Discussion:
[ITK-users] OtsuMultipleThresholdsImageFilter creates asymmetric classes for symmetric a distribution
hellman
2017-10-17 14:35:27 UTC
Permalink
Hi all,

I am planning to use OtsuMultipleThresholdsImageFilter to segment an image
into a number of classes. I started by testing it for a small image with
only a single threshold to see that I understand how it works. The results
surprise me though.

I create a 1D-image with four pixels: 1000, 2000, 3000 and 4000. Computing a
threshold to split this distribution into two classes of maximum
between-class variance should give a threshold between 2000 and 3000.
However, OtsuMultipleThresholdsImageFilter gives me a value 1996.17, which
puts 1000 in one class and 2000, 3000, 4000 in the other class. This does
not give the smallest between-class variance.

The code that I tried can be found below. Do I misunderstand how this filter
should work or is there a bug in its implementation?

Running the following code with ITK 4.12.0 and ITK 4.12.2 prints 1996.17:

#include <itkOtsuMultipleThresholdsImageFilter.h>

typedef itk::Image<float, 1> ImageType;
typedef itk::Image<int, 1> LabelImageType;

int main(int argc, char *argv[])
{
typename ImageType::Pointer input = ImageType::New();

ImageType::RegionType region;
region.GetModifiableSize()[0] = 4;
input->SetRegions(region);
input->Allocate();

ImageType::IndexType index;
index[0] = 0;
input->SetPixel(index, 1000);
index[0] = 1;
input->SetPixel(index, 2000);
index[0] = 2;
input->SetPixel(index, 3000);
index[0] = 3;
input->SetPixel(index, 4000);

auto otsuFilter = itk::OtsuMultipleThresholdsImageFilter<ImageType,
LabelImageType>::New();
otsuFilter->SetInput(input);
otsuFilter->SetNumberOfHistogramBins(128);
otsuFilter->SetNumberOfThresholds(1);
otsuFilter->Update();

std::cout << otsuFilter->GetThresholds()[0] << std::endl;

return 0;
}

Best wishes,
Fredrik Hellman



--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
Dženan Zukić
2017-10-17 15:15:10 UTC
Permalink
Hi Frederik,

what happens if you set number of histogram bins to 129 or 127?

Regards,
DÅŸenan
Post by hellman
Hi all,
I am planning to use OtsuMultipleThresholdsImageFilter to segment an image
into a number of classes. I started by testing it for a small image with
only a single threshold to see that I understand how it works. The results
surprise me though.
I create a 1D-image with four pixels: 1000, 2000, 3000 and 4000. Computing a
threshold to split this distribution into two classes of maximum
between-class variance should give a threshold between 2000 and 3000.
However, OtsuMultipleThresholdsImageFilter gives me a value 1996.17, which
puts 1000 in one class and 2000, 3000, 4000 in the other class. This does
not give the smallest between-class variance.
The code that I tried can be found below. Do I misunderstand how this filter
should work or is there a bug in its implementation?
#include <itkOtsuMultipleThresholdsImageFilter.h>
typedef itk::Image<float, 1> ImageType;
typedef itk::Image<int, 1> LabelImageType;
int main(int argc, char *argv[])
{
typename ImageType::Pointer input = ImageType::New();
ImageType::RegionType region;
region.GetModifiableSize()[0] = 4;
input->SetRegions(region);
input->Allocate();
ImageType::IndexType index;
index[0] = 0;
input->SetPixel(index, 1000);
index[0] = 1;
input->SetPixel(index, 2000);
index[0] = 2;
input->SetPixel(index, 3000);
index[0] = 3;
input->SetPixel(index, 4000);
auto otsuFilter = itk::OtsuMultipleThresholdsImageFilter<ImageType,
LabelImageType>::New();
otsuFilter->SetInput(input);
otsuFilter->SetNumberOfHistogramBins(128);
otsuFilter->SetNumberOfThresholds(1);
otsuFilter->Update();
std::cout << otsuFilter->GetThresholds()[0] << std::endl;
return 0;
}
Best wishes,
Fredrik Hellman
--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to
discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
hellman
2017-10-18 07:03:12 UTC
Permalink
Hi Dženan,

With 127 bins I get: 2004.02

With 129 bins I get: 1988.45

Best wishes,
Fredrik



--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/l
Dženan Zukić
2017-10-18 14:47:47 UTC
Permalink
Hi Frederik,

I agree that the threshold should be larger than 2000, and should not
depend on whether the number of histogram bins is 127, 128 or 129 - with
this many bins it really shouldn't matter.

This example is simple enough that it would be worthwhile to step through
the code
<https://github.com/InsightSoftwareConsortium/ITK/blob/master/Modules/Filtering/Thresholding/include/itkOtsuMultipleThresholdsCalculator.hxx>
of OtsuMultipleThresholdsCalculator
<https://itk.org/Doxygen/html/classitk_1_1OtsuMultipleThresholdsCalculator.html>
to
see why it doesn't produce the result we expect. This might lead to a bug
fix.

Will you do it Frederik? Or wait for Francois or me to get around to it? If
you do, please report the findings on discourse <https://discourse.itk.org/>,
or submit a patch <https://itk.org/Wiki/ITK/Git/Develop> to Gerrit.

Regards,
DÅŸenan
Hi DÅŸenan,
With 127 bins I get: 2004.02
With 129 bins I get: 1988.45
Best wishes,
Fredrik
--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to
discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
Matt McCormick
2017-10-18 15:01:55 UTC
Permalink
Hi Frederik,

Since this is a statistical method, it should be tested with more than
four samples. Please try creating a distribution of values with
hundreds of samples for each mode.

Hope this helps,
Matt
Post by Dženan Zukić
Hi Frederik,
I agree that the threshold should be larger than 2000, and should not depend
on whether the number of histogram bins is 127, 128 or 129 - with this many
bins it really shouldn't matter.
This example is simple enough that it would be worthwhile to step through
the code of OtsuMultipleThresholdsCalculator to see why it doesn't produce
the result we expect. This might lead to a bug fix.
Will you do it Frederik? Or wait for Francois or me to get around to it? If
you do, please report the findings on discourse, or submit a patch to
Gerrit.
Regards,
Dženan
Post by hellman
Hi Dženan,
With 127 bins I get: 2004.02
With 129 bins I get: 1988.45
Best wishes,
Fredrik
--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to
discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
The ITK community is transitioning from this mailing list to
discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.kitware.com/products/protraining.php
http://www.itk.org/Wiki/ITK_FAQ
http://public.kitware.com/mailman/listinfo/insight-users
The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-us
Fredrik Hellman
2017-10-18 15:04:23 UTC
Permalink
I can start taking a look and report in discourse (or submit a patch in
gerrit if I find out how to do it).



--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users
Lowekamp, Bradley (NIH/NLM/LHC) [C]
2017-10-20 17:28:27 UTC
Permalink
A large number of the automatic thresholding filters came from an Insight Journal contribution. The couple filters I check have a link to this paper for more information:
http://www.insight-journal.org/browse/publication/811

I agree that it would be nice if each filter described the method used to compute the threshold.

HTH,
Brad

From: "insight-***@itk.org" <insight-***@itk.org>
Reply-To: Mihail Isakov <***@googlemail.com>
Date: Friday, October 20, 2017 at 11:33 AM
To: "insight-***@itk.org" <insight-***@itk.org>
Subject: Re: [ITK-users] OtsuMultipleThresholdsImageFilter creates asymmetric classes for symmetric a distribution

Hi,
BTW, there are many interesting histogram-based threshold filters in ITK, but unfortunately there is no documentation in
The ITK Software Guide Book (or didn't find it).
PDF file from
http://www.insight-journal.org/browse/publication/811
can shed some light. Filters are already in ITK.
And most or all histogram-based threshold filters depend on Otsu filter, so changing it might require a extended testing.

Regards,

Mihail
Fredrik Hellman
2017-10-25 14:25:05 UTC
Permalink
I believe I have found what causes this problem, see:

https://discourse.itk.org/t/otsumultiplethresholdsimagefilter-creates-asymmetric-classes-for-a-symmetric-distribution/354



--
Sent from: http://itk-users.7.n7.nabble.com/
The ITK community is transitioning from this mailing list to discourse.itk.org. Please join us there!
________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/insight-users

Loading...