4
$\begingroup$

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. enter image description here

The codes are as follows

Pruning@Thinning@Closing[#, 5] &@DeleteSmallComponents[#, 500] &@
     LocalAdaptiveBinarize[#, 2] &@GaussianFilter[#, 10] &@img

enter image description here

ridges = ImageAdjust[RidgeFilter[imge, 7]]

enter image description here

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

enter image description here

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

enter image description here

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

enter image description here

$\endgroup$
1

1 Answer 1

5
$\begingroup$

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

enter image description here

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]

enter image description here

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

del = DeleteSmallComponents[bestBin, 100]

enter image description here

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

enter image description here enter image description here

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

enter image description here

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 = 
 LocalAdaptiveBinarize[(RidgeFilter[totImg, 3] // ImageAdjust), 
  5, {1, 1.5, -.07}]
mc = MorphologicalComponents[bestBin] // Colorize;
SelectComponents[mc, #Count > 100 &]

enter image description here

enter image description here

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.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.