Segmentation does not produce output

34 views
Skip to first unread message

Ricardo Martínez Prentice

unread,
Dec 2, 2020, 5:54:13 AM12/2/20
to SegOptim user group
Dear João Gonçalves:

I am using the TerraLib segmentation for small areas of a larger image (at the moment, using images of 892,144 pixels) without any problem. In order to optimise the segmentation process for large areas, I have converted my original  floating point .tif bands to int data type using ArcMap (output are .tif rasters). Now, the segmentation_Terralib_Baatz() function does not output a segmentation.

 I think that the problem is this one: this .tif format is not readable by R (whereas for ArcMap is). Is this possible? Or perhaps the function does not work with integer rasters?

Here is my code. As you can see, nothing is "unusual".  


ImgSegment <- segmentation_Terralib_Baatz(
c(0.1, 5, 0.9, 100),
"D:/.../Stacked_.tif",
"D:/.../Segmented.tif",
CompactnessWeight = NULL,
SpectralWeight = NULL,
Threshold = NULL,
MinSize = NULL, # Minimum size of 8 because oour training samples have 8 pixels (Pol -> Ras) 
verbose = TRUE, # I want to see messages
TerraLib.path = "C:/terralib-5.2.1-TISA-win_x64/terralib-5.2.1-TISA/lib" #route to TerraLib

# Check the result
rstSegm <- raster(ImgSegment$segm) 
(...)

Of course, all the data is in the same extent and projection (4 spectral bands and a DEM).

Thank you.

João Gonçalves

unread,
Dec 2, 2020, 7:34:18 AM12/2/20
to SegOptim user group
Hi Ricardo,

Thanks for your feedback.

 The GeoTIFF (.tif) format exported by the TISA tool is fully readable in R through the raster package. The TISA package is also compatible with integer data.
So, I am not completely sure what is causing this issue but probably you have to adjust the segmentation parameters (especially the compactness and spectral weights and also the threshold) now that your input data has changed to an integer type. Checking your image data after this conversion is also critical to ensure if it is valid.. Is the numerical range correct? Did any truncation occur? (but I guess you have checked this by now).
 
Also, for segmentation, I am not sure if mixing spectral and elevation features will provide the best results. Usually, elevation and other DEM-related features (e.g., slope, curvature) are more often used in classification stages as features included in learning algorithms. For addressing this you can try to segment your image with and without the DEM band and check which one provides better results.


Hope this helps.
Best regards,
João

Ricardo Martínez Prentice

unread,
Dec 3, 2020, 8:29:57 AM12/3/20
to SegOptim user group
Thank you  João Gonçalves , 
You are right, I am using only the spectral bands. The DEM is for the following classification.

After doing some tests, I found out that I am having problems with rasters generated by R using the following code (does not matter if they are the original or converted to integer):

allBands <- list.files(file.path(Path_to_bands),pattern = "tif$",full.names = TRUE)

##Stack the bands
stackBands <- stack(allBands)

#save the stackedbands
writeRaster(stackBands, "D:/.../Stacked_.tif" ,overwrite = TRUE )

Then I use the same path to " Stacked_.tif" saved in the previous line as input for the segmentation.

ImgSegment <- segmentation_Terralib_Baatz(
c(0.1, 1, 0.9, 10),
"D:/.../Stacked_.tif",
"D:/.../Segmented.tif",
CompactnessWeight = NULL,
SpectralWeight = NULL,
Threshold = NULL,
MinSize = NULL, # Minimum size of 8 because oour training samples have 8 pixels (Pol -> Ras) 
verbose = TRUE, # I want to see messages
TerraLib.path = "C:/terralib-5.2.1-TISA-win_x64/terralib-5.2.1-TISA/lib" #route to TerraLib

This does not work (takes a lot of time and the segmentation is only 3 sections of the whole extension. 
Otherwise, when I use stacked bands produced by ArcMap, it works.

I know this is a problem not related with SegOptim, but if you have faced this problem before, please let me know. Perhaps I am not using the right function to stack the rasters. 

Regards,

Ricardo Martínez Prentice

unread,
Dec 8, 2020, 9:03:20 AM12/8/20
to SegOptim user group
I solved this problem. I was using rasters extracted with an irregular shape of mask (in the following image, red) so I used a squared mask (blue) to clip the rasters and it worked fine.




Thank you.

João Gonçalves

unread,
Dec 8, 2020, 11:14:20 AM12/8/20
to SegOptim user group
Great! Thanks for posting the solution. I was not aware of this kind of issue when running the Baatz segmenter.

Cheers
Reply all
Reply to author
Forward
0 new messages