ukoethe / vigra

a generic C++ library for image analysis
http://ukoethe.github.io/vigra/
Other
411 stars 192 forks source link

slicSuperpixels() always returns '0'. #281

Closed RishabhMalviya closed 8 years ago

RishabhMalviya commented 8 years ago

I used the library (1.10.0 release) as part of a project recently, and I think I may have discovered a bug with the slicSuperpixels() function. It states the following in the documentation on the website:

"The function returns the number of superpixels, which equals the largest label because labeling starts at 1."

But when using the function, it always returned '0'. I found a way around this by calculating the maximum value in the labels MultiArray that is filled up by the function (please look at how the variable superpixelCount is assigned in the extractSLICSuperpixels function at line number 59 in this source file). Furthermore, when going through these super-pixels, I discovered that many of them had zero pixels in them.

I think this may be because internally some superpixels get merged with others. I do not know exactly what files to work on or how to proceed to fix his issue, but I felt that I should bring this to light so that it can be worked upon.

ukoethe commented 8 years ago

Thanks for reporting this. Can you please try if the problem persists when you use the current master from github?

Furthermore, when going through these super-pixels, I discovered that many of them had zero pixels in them. I think this may be because internally some superpixels get merged with others.

According to the original authors of the SLIC method, merging of some superpixels is desired. However, function slicSuperpixels() is supposed to call function Slic::postProcessing() which should restore consecutive superpixel labels and return the maximum. Is this function called in your installation?

RishabhMalviya commented 8 years ago

I just ran some test with the latest snapshot from GitHub. There aren't any problems with the slicSuperpixels() function any more!

I ran the function on the _lennacolor.gif image, and I got 61 superpixels, which the function returned faithfully. I also verified that none of the superpixels had zero pixels in them by calculating the average RGB values for each through an ArrayOfRegionStatistics object (when I did this previously, I was getting 'nan' values for the zero-pixel superpixels). I've attached a screenshot of my results:

screenshot from 2015-12-22 13 14 36

I also checked the slic.hxx file and verified that the Slic::postProcessing() function is being called.

ukoethe commented 8 years ago

Great to hear that!

BTW, as you are interested in region statistics, you might want to take a look at the accumulator framework, see http://ukoethe.github.io/vigra/doc/vigra/group__FeatureAccumulators.html

RishabhMalviya commented 8 years ago

Yes, I had a look at the Feature Accumulator framework before, but I just ended up using the Region Statistics methods somehow.

I'll be sure to look into it in future projects. On 22-Dec-2015 5:34 pm, "Ullrich Koethe" notifications@github.com wrote:

Great to hear that!

BTW, as you are interested in region statistics, you might want to take a look at the accumulator framework, see http://ukoethe.github.io/vigra/doc/vigra/group__FeatureAccumulators.html

— Reply to this email directly or view it on GitHub https://github.com/ukoethe/vigra/issues/281#issuecomment-166596473.