Karthik,<br><br>I think the ScalarImageToHistogramGenerator should set the min/max bounds<br>to be k-0.5, k+0.5 as Luis indicated. This is how I build my histograms for <br>integral types.<br><br>I think the code<br><br> h_upper[i] = ((THistogramMeasurement) upper[i]) +
<br> NumericTraits< THistogramMeasurement >::One ;<br> if(h_upper[i] <= upper[i])<br> {<br> // an overflow has occurred therefore set upper to upper<br> h_upper[i] = upper[i];
<br> // Histogram measurement type would force the clipping the max<br>value.<br> // Therefore we must call the following to include the max value:<br> m_Histogram->SetClipBinsAtEnds<div style="direction: ltr;">
(false);<br> }<br></div><br>should be scrapped for integral types and specify the bins with as k-0.5,k+0.5.<br>Then the ClipBinsAtEnds does not need to be used.<br><br>On a side note, we may want to come up with a synonym/antonym for ClipBinsAtEnds.
<br>What this mode is doing is deciding whether to include all the mass in the <br>distribution that is outside the histogram domain in the first/last bin verses<br>just ignoring that mass. I just don't know a better name right now..
<br><br>AutoExpandHistogramDomain()<br>IgnoreDataOutsideHistogramDomain(), IngoreMeasurementsOutsideHistogramDomain()<br>IncludeDataOutsideHistogramDomain(), IncludeMeasurementsOutsideHistogramDomain()<br><br>These modes bring up an interesting question. If the ClipBinsAtEnds is off, then the first/last
<br>bin runs to -+ infinity respectively. If you then ask for the bin bounds, should the first/last bin<br>report that their bounds are -+ infinity respectively? Probably should.<br><br>Jim<br><br><br><div><span class="gmail_quote">
On 6/8/06, <b class="gmail_sendername">Karthik Krishnan</b> <<a href="mailto:Karthik.Krishnan@kitware.com">Karthik.Krishnan@kitware.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Gaetan, Uwe, Luis:<br><br>My point was that despite all that the histogram would be computed the<br>right way, without any user intervention, *even if you don't set the<br>bounds* (if you are using ScalarImageToHistogramGenerator. Otsu uses
<br>that)...<br><br>See<br><a href="http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.txx?annotate=1.14&root=Insight">http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.txx?annotate=1.14&root=Insight
</a><br><br>The min and max are automatically computed for you in line 63 and that<br>will be 255 in your case<br>Line 90 : The upper bound of the histogram is set to 255 + 1 = 256. So<br>the histogram should be fine too.
<br><br>I just checked the code snippets with a debugger to see if there were<br>overflows due to datatype etc.. and its fine..<br><br>So what is the bug here ? Could I please have a minimal code where it<br>doesn't work.
<br><br>[ You can run Examples/Statistics/ImageHistogram2.cxx after commenting<br>out the SetHistogramMin/Max part on a binary image, such as<br>Insight/Examples/Data/Circle.png - UCHAR image with pixels 0/255 and<br>your histogram will still be fine].
<br><br>Am I mistaken here ?<br><br>Thanks<br>-karthik<br><br><br><br>Gaetan Lehmann wrote:<br><br>><br>> Hi Luis,<br>><br>> So it explain the observed behavior :-)<br>> However, a naive user (let say me) would think the following code
<br>> (stollen from itkOtsuMultipleThresholdsImageFilter.txx to implement<br>> my own filter) will return an histogram with all the values:<br>><br>> // Create a histogram of the image intensities<br>> typename HistogramGeneratorType::Pointer histogramGenerator =
<br>> HistogramGeneratorType::New();<br>> histogramGenerator->SetInput( this->GetInput() );<br>> histogramGenerator->SetNumberOfBins( m_NumberOfHistogramBins );<br>> histogramGenerator->Compute();
<br>><br>> By the way, does it mean that OtsuMultipleThresholdsImageFilter code<br>> is broken ?<br>> Perhaps the class ScalarImageToHistogramGenerator should be modified<br>> to set the min and max values to include all the values ?
<br>><br>> Gaetan<br>><br>><br>> On Thu, 08 Jun 2006 14:00:25 +0200, Luis Ibanez<br>> <<a href="mailto:luis.ibanez@kitware.com">luis.ibanez@kitware.com</a>> wrote:<br>><br>>><br>>> For mor details, you may want to look at the Examples:
<br>>><br>>><br>>> Insight/<br>>> Examples/<br>>> Statistics/<br>>> ImageHistogram1.cxx<br>>> ImageHistogram2.cxx
<br>>><br>>> in particular to the call for the methods:<br>>><br>>> SetHistogramMin()<br>>> SetHistogramMax()<br>>><br>>><br>>> Note again that the min and max values of the histogram
<br>>> refer here to the values of the bin bounds, not the the<br>>> values to be accepted in the bins.<br>>><br>>> For an image of integer pixel type, the bounds of the<br>>> bins must be of the type
K-0.5,K+0.5, so that the bin<br>>> accepts the value K (where K is an integer).<br>>><br>>><br>>> Luis<br>>><br>>><br>>> ---------------------<br>>> Luis Ibanez wrote:<br>
>><br>>>> This is a known behavior of the Histogram.<br>>>> The correct way to use the histogram class for an image of 8-bits<br>>>> is to set the minimum and maximum to values such as -
0.5 and 255.5<br>>>> Note that the types for setting min and max are not the image pixel<br>>>> type but its RealType.<br>>>> The reason is that the min and max that we pass to the histogram<br>
>>> class are the values for the min of the first bin and the max of<br>>>> the last bin.<br>>>> If you want to include all the samples, the min value of the bin<br>>>> bounds must be lower that the actual minimum value expected in the
<br>>>> population, and the max value of the bin bounds must be larger<br>>>> than the minimum value expected in the population. This is standard<br>>>> for computing histogram.<br>>>> The unfortunate fact is that there are too many bad habits acquired
<br>>>> for people that got used to work only with 8-bit images, and expect<br>>>> the min and max of the histogram to be 0 and 255. Those are actually<br>>>> the mid-values of the bins, not the bounds of the bins.
<br>>>> It may be convenient to have a helper initializer class to set the<br>>>> min and max values for images of (char) and (unsigned char) so that<br>>>> user's do not have to think about these details.
<br>>>> Luis<br>>>> =========================<br>>>> Karthik Krishnan wrote:<br>>>><br>>>>> The histogram class is a widely used class. Please file a bug<br>>>>> report and assign it to me with a high priority.
<br>>>>><br>>>>> -----<br>>>>><br>>>>> That said, I am surprised, it does not handle pixels with<br>>>>> intensity 255. See lines 90-102 of<br>>>>>
<a href="http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.txx?annotate=1.14&root=Insight">http://www.itk.org/cgi-bin/viewcvs.cgi/Code/Numerics/Statistics/itkListSampleToHistogramGenerator.txx?annotate=1.14&root=Insight
</a><br>>>>> h_upper[i] = ((THistogramMeasurement) upper[i]) +<br>>>>> NumericTraits< THistogramMeasurement >::One ;<br>>>>> if(h_upper[i] <= upper[i])<br>
>>>> {<br>>>>> // an overflow has occurred therefore set upper to upper<br>>>>> h_upper[i] = upper[i];<br>>>>> // Histogram measurement type would force the clipping
<br>>>>> the max value.<br>>>>> // Therefore we must call the following to include the<br>>>>> max value:<br>>>>> m_Histogram->SetClipBinsAtEnds(false);
<br>>>>> }<br>>>>><br>>>>> If pixel type is UCHAR, it should go into that if block and do the<br>>>>> SetClipBinsAtEnds(false) thing. That would mean that the bins at
<br>>>>> the edges of the histogram extend to infinity, so really 255<br>>>>> should be considered. [ In the default case, the ends are<br>>>>> clipped, See constructor of itk::Histogram with sets
<br>>>>> ClipBinsAtEnds to true (so 255 won't be considered), but that's<br>>>>> not the case with you since you are using the<br>>>>> ScalarImageToHistogramGenerator. ]<br>>>>>
<br>>>>><br>>>>> Thanks for reporting this.<br>>>>> -karthik<br>>>>><br>>>>><br>>>>> Gaetan Lehmann wrote:<br>>>>><br>>>>>>
<br>>>>>> Hi,<br>>>>>><br>>>>>> I am the only one to have this problem ?<br>>>>>> Should I file a bug report ?<br>>>>>><br>>>>>> Gaetan
<br>>>>>><br>>>>>><br>>>>>> On Fri, 02 Jun 2006 17:11:45 +0200, Gaetan Lehmann<br>>>>>> <<a href="mailto:gaetan.lehmann@jouy.inra.fr">gaetan.lehmann@jouy.inra.fr
</a>> wrote:<br>>>>>><br>>>>>>><br>>>>>>> I forgot to say I'm using ITK 2.6.0 with gcc 4.0<br>>>>>>><br>>>>>>> On Fri, 02 Jun 2006 16:23:25 +0200, Gaetan Lehmann
<br>>>>>>> <<a href="mailto:gaetan.lehmann@jouy.inra.fr">gaetan.lehmann@jouy.inra.fr</a>> wrote:<br>>>>>>><br>>>>>>>><br>>>>>>>> Hi,<br>>>>>>>>
<br>>>>>>>> I'm trying to manipulate histograms, with itk::Histogram. I'm<br>>>>>>>> generating<br>>>>>>>> the histogram from an image with the<br>>>>>>>> ScalarImageToHistogramGenerator
<br>>>>>>>> class. The pixel type of the input image is unsigned char.<br>>>>>>>> Everything seems to work, as long as there is no pixel value =<br>>>>>>>> 255 in the
<br>>>>>>>> image.<br>>>>>>>> All the pixels with an intensity of 255 are not counted in the<br>>>>>>>> histogram.<br>>>>>>>> For example, the attached image (a 10x10 black image with 4
<br>>>>>>>> white (255)<br>>>>>>>> pixels) produce an histogram with 96 pixels according to the<br>>>>>>>> GetTotalFrequency() result.<br>>>>>>>>
<br>>>>>>>> Is it a bug ?<br>>>>>>>> Or I have missed something ?<br>>>>>>>><br>>>>>>>> Regards,<br>>>>>>>><br>>>>>>>> Gaetan
<br>>>>>>>><br>>>>>>><br>>>>>>><br>>>>>>><br>>>>>><br>>>>>><br>>>>>><br>>>>> _______________________________________________
<br>>>>> Insight-users mailing list<br>>>>> <a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>>>>> <a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users
</a><br>>>>><br>>>>><br>>>> _______________________________________________<br>>>> Insight-developers mailing list<br>>>> <a href="mailto:Insight-developers@itk.org">Insight-developers@itk.org
</a><br>>>> <a href="http://www.itk.org/mailman/listinfo/insight-developers">http://www.itk.org/mailman/listinfo/insight-developers</a><br>>>><br>>><br>>><br>>> _______________________________________________
<br>>> Insight-users mailing list<br>>> <a href="mailto:Insight-users@itk.org">Insight-users@itk.org</a><br>>> <a href="http://www.itk.org/mailman/listinfo/insight-users">http://www.itk.org/mailman/listinfo/insight-users
</a><br>><br>><br>><br>><br>_______________________________________________<br>Insight-developers mailing list<br><a href="mailto:Insight-developers@itk.org">Insight-developers@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-developers">
http://www.itk.org/mailman/listinfo/insight-developers</a><br></blockquote></div><br>