# LargeScaleMeanShift not working as I expect

**URL:** <https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919>\
**Category:** OTB Usage\
**Created:** [January 21, 2021, 12:15pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919 "2021-01-21T12:15:36Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![wkcmark](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/w/c68b51/32.png) [@wkcmark](https://forum.orfeo-toolbox.org/u/wkcmark)\
**Post date:** [January 21, 2021, 12:15pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/1 "2021-01-21T12:15:36Z")

</div>

I’m trying to use the LargeScaleMeanShift tool as this first step to carry out some benthic habitat mapping using WorldView 2 data.

This has worked successfully for me with previous analysis so I’m not sure what is happening now.

For some reason I’m getting a large polygon forming over the area of water so sub-surface features aren’t detected.

This is the image that I’m trying to classifiy

 ![LSMS 1a](https://forum.orfeo-toolbox.org/uploads/default/original/1X/515378cea7a0972167aeab2300256c0ab17b6faf.jpeg)

This is the result of the segmentation. You see the large polygon over the water area.

 ![LSMS 1](https://forum.orfeo-toolbox.org/uploads/default/original/1X/ffc0500c6941c13c4ea29c8d179100ad5ca68d23.jpeg)

The data is fine. This is the result using a segmentation algorithm from GRASS.

 ![LSMS 2](https://forum.orfeo-toolbox.org/uploads/default/original/1X/dd34f3c5ca187457071927a399f6fa92f64282ff.jpeg)

I’m not sure why it’s not producing similar results with OTB.

As well as the LargeScaleMeanShift algorithm I’ve also tried with the LSMS workflow using MeanShiftSmoothing then LSMSSegmentation Then LSMSVectorization. This has given me the same results.

Here is a close up from Spatial Filtered Displacement.tif created using MeanShiftSmoothing. I should be able to detect the dredged channels that are clearly present here.

 ![LSMS 3](https://forum.orfeo-toolbox.org/uploads/default/original/1X/e9057e8ffc65192e6168ad2bcf68258a8dc0776e.jpeg)

---

<div class="post-metadata">

**Author:** ![julienosman](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@julienosman](https://forum.orfeo-toolbox.org/u/julienosman)\
**Post date:** [January 21, 2021, 1:34pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/2 "2021-01-21T13:34:23Z")

</div>

Dear @wkcmark,

Did you try to play with the parameters ?  
It might be interesting to try with a smaller value for the range radius (`-ranger`), so the algorithm will try to differentiate pixels with close radiometry.

Sincerely.  
Julien.

---

<div class="post-metadata">

**Author:** ![wkcmark](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/w/c68b51/32.png) [@wkcmark](https://forum.orfeo-toolbox.org/u/wkcmark)\
**Post date:** [January 21, 2021, 1:39pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/3 "2021-01-21T13:39:03Z")

</div>

Thanks for responding.

Yes I’ve tried the following

Spatial Radius: 5  
Range Radius: 15

and

Spatial Radius: 2  
Range Radius: 5

What values would you try?

---

<div class="post-metadata">

**Author:** ![julienosman](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@julienosman](https://forum.orfeo-toolbox.org/u/julienosman)\
**Post date:** [January 21, 2021, 1:45pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/4 "2021-01-21T13:45:10Z")

</div>

Well, I would have tried 5 and 5. I am surprised you don’t get better results with 2 ad 5…  
You may also want to reduce the Minimum Segment Size (`-minsize`), but I doubt it will help you in your case…

---

<div class="post-metadata">

**Author:** ![wkcmark](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/w/c68b51/32.png) [@wkcmark](https://forum.orfeo-toolbox.org/u/wkcmark)\
**Post date:** [January 21, 2021, 1:53pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/5 "2021-01-21T13:53:26Z")

</div>

Yes this is what I can’t understand.

It has worked fine doing similar work in the past.

---

<div class="post-metadata">

**Author:** ![julienosman](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/j/9f8e36/32.png) [@julienosman](https://forum.orfeo-toolbox.org/u/julienosman)\
**Post date:** [January 21, 2021, 2:09pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/6 "2021-01-21T14:09:13Z")

</div>

I am very surprised by your results. On one hand, you have a huge polygon for the underwater area. But on the other hand, the land seems to be over-segmented. I think the low Range Radius was not a good idea.

Maybe you should use different parameters for both areas. You could use a higher value for Range Radius to segment the land. Then use the [ExtractROI](https://www.orfeo-toolbox.org/CookBook/Applications/app_ExtractROI.html) application to generate a new image containing only the underwater area (use the huge polygon you obtained previously as input with the parameter `-mode.fit.vect`) and try smaller parameters on that new image.

---

<div class="post-metadata">

**Author:** ![wkcmark](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/w/c68b51/32.png) [@wkcmark](https://forum.orfeo-toolbox.org/u/wkcmark)\
**Post date:** [January 21, 2021, 2:11pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/7 "2021-01-21T14:11:42Z")

</div>

Thanks for your suggestions I will give that a go.

I think I will also extract a small area of water first and see how it works just segmenting that.

---

<div class="post-metadata">

**Author:** ![wkcmark](https://forum.orfeo-toolbox.org/letter_avatar_proxy/v4/letter/w/c68b51/32.png) [@wkcmark](https://forum.orfeo-toolbox.org/u/wkcmark)\
**Post date:** [January 21, 2021, 2:37pm UTC](https://forum.orfeo-toolbox.org/t/largescalemeanshift-not-working-as-i-expect/919/8 "2021-01-21T14:37:05Z")

</div>

Thanks actually I gave your 5 and 5 a go and have got better results now. I’ll play around some more and see where i get.

 ![LSMS 4](https://forum.orfeo-toolbox.org/uploads/default/original/1X/1bc85fc87f219153e69b067b45baec21aea5a473.jpeg)
