Another thought along these lines is to refer to the defacto standard in these<br>issues, namely MATLAB. MATLAB will autocalculate bins for you or you<br>can specify bin centers (off the top of my head, I think it does centers not bounds
<br>but I could be wrong). What does matlab do with the data far outside a specified <br>first/last bin?<br><br>Jim<br><br><div><span class="gmail_quote">On 6/10/06, <b class="gmail_sendername">Jim Miller</b> <<a href="mailto:millerjv@gmail.com">
millerjv@gmail.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;"><div>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</div><div><span class="q"><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></span></div><div>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></div><div><span class="sg"><br>Jim</span>
</div><div><span class="e" id="q_10bbdf1674b3ed40_4"><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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a><br>>>>>
<a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Insight-developers@itk.org
</a><br>>>> <a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">Insight-users@itk.org</a><br>>> <a href="http://www.itk.org/mailman/listinfo/insight-users" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
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" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
Insight-developers@itk.org</a><br><a href="http://www.itk.org/mailman/listinfo/insight-developers" target="_blank" onclick="return top.js.OpenExtLink(window,event,this)">
http://www.itk.org/mailman/listinfo/insight-developers</a><br></blockquote></div><br>
</span></div></blockquote></div><br>