# How can I increase boundaries accuracy in satellite images?

I use the following codes for this work on Mathematica, but they have low accuracy. I would be grateful if you could help me improve accuracy.

The codes are as follows

Pruning@Thinning@Closing[#, 5] &@DeleteSmallComponents[#, 500] &@


ridges = ImageAdjust[RidgeFilter[imge, 7]]


bin = MorphologicalBinarize[ridges, {.1, .2}]


dist = DistanceTransform[ColorNegate@bin];
maxMarkers = MaxDetect[dist, 10];
HighlightImage[bin, maxMarkers]


watersheds = WatershedComponents[ridges, maxMarkers];
Colorize[watersheds]


As a "quick and dirty” method WaterShedComponents works somewhat well with Method -> {"MinimumSaliency", 0.5} if we look at the total (rescaled) intensity of each pixel:

totImg = ImageApply[Total, img] // ImageAdjust;
WatershedComponents[totImg, Method -> {"MinimumSaliency", 0.5}] // Colorize


Now let's try to do better (this is hard!):

I am again going to use the total pixel intensity image totImg, and I will immediately apply the RidgeFilter first and Binarize it. The scale parameter for RidgeFilter and the threshold for binarize I just determined by eye by looking at different values with Manipulate[ Binarize[RidgeFilter[totImg, r] // ImageAdjust, b], {r, 0, 5}, {b, 0, .3}]

bestBin = Binarize[RidgeFilter[totImg, 3.5] // ImageAdjust, 0.15]


There is a lot of small noisy components in bestBin so I attempt to remove some of them with DeleteSmallComponents:

del = DeleteSmallComponents[bestBin, 100]


And now I use your same exact method (with the same parameter for MaxDetect) to get the markers for WatershedComponents:

dist = DistanceTransform[ColorNegate@del];
maxMarkers = MaxDetect[dist, 10];
HighlightImage[bestRidge, maxMarkers]
watersheds = WatershedComponents[del, maxMarkers];
Colorize@watersheds


This still only seems to be a mild improvement, and there's a lot of places the watersheds don't really line up with fields. Another function you may want to explore is ImageForestingComponents:

ImageForestingComponents[del] // Colorize


Update: There is a lot of potential for improvement in my result. After playing with the parameters of LocalAdaptiveBinarize for some time I managed to get a good binarized ridge separation:

lab =

Some squiggly lines still remain on the interior of fields in the final image, so I'm trying to think of an appropriate ComponentMeasurement I could use to remove these with using SelectComponents.