<div dir="ltr"><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">Hi Dobashi,</div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small"><br></div><div class="gmail_default" style="font-family:verdana,sans-serif;font-size:small">adding this line makes the behavior independent from pixel type:</div><div class="gmail_default"><font face="monospace, monospace">imageToHistogramFilter-><wbr>SetAutoMinimumMaximum(false);</font><br></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">And this is because <wbr>ImageToHistogramFilter's constructor has this:</font></div><div class="gmail_default"><div class="gmail_default"><font face="monospace, monospace">if( typeid(ValueType) == typeid(signed char) || typeid(ValueType) == typeid(unsigned char) )</font></div><div class="gmail_default"><font face="monospace, monospace"> {</font></div><div class="gmail_default"><font face="monospace, monospace"> autoMinMax->Set(false);</font></div><div class="gmail_default"><font face="monospace, monospace"> }</font></div><div class="gmail_default"><font face="monospace, monospace"> else</font></div><div class="gmail_default"><font face="monospace, monospace"> {</font></div><div class="gmail_default"><font face="monospace, monospace"> autoMinMax->Set(true);</font></div><div class="gmail_default"><font face="monospace, monospace"> }</font></div></div><div class="gmail_default"><font face="verdana, sans-serif"><br></font></div><div class="gmail_default"><font face="verdana, sans-serif">Regards,</font></div><div class="gmail_default"><font face="verdana, sans-serif">Dženan</font></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 26, 2017 at 10:51 AM, SDobashi <span dir="ltr"><<a href="mailto:dobashisuguru@gmail.com" target="_blank">dobashisuguru@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hello, everyone,<br>
<br>
I want to calculate a histogram for a double precision C-array (or<br>
std::vector<double>).<br>
<br>
As a simple example, I tried to calculate a histogram for the data<br>
<br>
double data[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};<br>
<br>
for the range from 5 to 10 in 10 bins, and I wrote the code listed in the<br>
last part of this post.<br>
<br>
This code worked well for "unsined char" but not for "double".<br>
<br>
Could anyone suggest me why this could happen?<br>
Please tell me a proper way to calculate a histogram of the double precision<br>
array.<br>
<br>
Thanks a lot in advance,.<br>
<br>
Kind regards,<br>
<br>
# Results for "unsigned char" data and this is what I expected:<br>
<br>
Frequency = [ 1,<br>
0,<br>
1,<br>
0,<br>
1,<br>
0,<br>
1,<br>
0,<br>
1,<br>
0 ]<br>
Frequency of 0 : (5 to 5.5) = 1<br>
Frequency of 1 : (5.5 to 6) = 0<br>
Frequency of 2 : (6 to 6.5) = 1<br>
Frequency of 3 : (6.5 to 7) = 0<br>
Frequency of 4 : (7 to 7.5) = 1<br>
Frequency of 5 : (7.5 to 8) = 0<br>
Frequency of 6 : (8 to 8.5) = 1<br>
Frequency of 7 : (8.5 to 9) = 0<br>
Frequency of 8 : (9 to 9.5) = 1<br>
Frequency of 9 : (9.5 to 10) = 0<br>
Total count 5<br>
<br>
# Results for "double" precision data:<br>
<br>
Frequency = [ 1,<br>
1,<br>
1,<br>
1,<br>
1,<br>
1,<br>
1,<br>
1,<br>
1,<br>
1 ]<br>
Frequency of 0 : (0 to 0.9009) = 1<br>
Frequency of 1 : (0.9009 to 1.8018) = 1<br>
Frequency of 2 : (1.8018 to 2.7027) = 1<br>
Frequency of 3 : (2.7027 to 3.6036) = 1<br>
Frequency of 4 : (3.6036 to 4.5045) = 1<br>
Frequency of 5 : (4.5045 to 5.4054) = 1<br>
Frequency of 6 : (5.4054 to 6.3063) = 1<br>
Frequency of 7 : (6.3063 to 7.2072) = 1<br>
Frequency of 8 : (7.2072 to 8.1081) = 1<br>
Frequency of 9 : (8.1081 to 9.009) = 1<br>
Total count 10<br>
<br>
<br>
# Code I wrote:<br>
<br>
#include "itkImage.h"<br>
#include "itkImportImageFilter.h"<br>
#include "itkImageToHistogramFilter.h"<br>
<br>
using namespace std;<br>
<br>
int main(int argc, char* argv[])<br>
{<br>
//typedef unsigned char PixelType;<br>
typedef double PixelType;<br>
const int Dimension = 1;<br>
<br>
const int numElems = 10;<br>
PixelType data[numElems] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};<br>
<br>
typedef itk::Image<PixelType, Dimension> ImageType;<br>
typedef itk::ImportImageFilter<PixelTy<wbr>pe, Dimension> ImportFilterType;<br>
<br>
ImportFilterType::Pointer importFilter = ImportFilterType::New();<br>
<br>
ImportFilterType::SizeType size;<br>
size[0] = numElems;<br>
<br>
ImportFilterType::IndexType start;<br>
start[0] = 0;<br>
<br>
ImportFilterType::RegionType region;<br>
region.SetIndex(start);<br>
region.SetSize(size);<br>
<br>
importFilter->SetRegion(region<wbr>);<br>
<br>
importFilter->SetImportPointer<wbr>(data, numElems, false);<br>
<br>
importFilter->Update();<br>
<br>
ImageType::Pointer img = importFilter->GetOutput();<br>
<br>
const unsigned int binsPerDimension = numElems;<br>
<br>
const unsigned int MeasurementVectorSize = 1;<br>
<br>
typedef itk::Statistics::ImageToHistog<wbr>ramFilter<ImageType><br>
ImageToHistogramFilterType;<br>
<br>
ImageToHistogramFilterType::Hi<wbr>stogramType::MeasurementVector<wbr>Type<br>
lowerBound(binsPerDimension);<br>
lowerBound.Fill(5);<br>
<br>
ImageToHistogramFilterType::Hi<wbr>stogramType::MeasurementVector<wbr>Type<br>
upperBound(binsPerDimension);<br>
upperBound.Fill(10);<br>
<br>
ImageToHistogramFilterType::Hi<wbr>stogramType::SizeType<br>
histSize(MeasurementVectorSize<wbr>);<br>
histSize.Fill(binsPerDimension<wbr>);<br>
<br>
ImageToHistogramFilterType::Po<wbr>inter imageToHistogramFilter =<br>
ImageToHistogramFilterType::Ne<wbr>w();<br>
imageToHistogramFilter->SetInp<wbr>ut(img);<br>
imageToHistogramFilter->SetHis<wbr>togramBinMinimum(lowerBound);<br>
imageToHistogramFilter->SetHis<wbr>togramBinMaximum(upperBound);<br>
imageToHistogramFilter->SetHis<wbr>togramSize(histSize);<br>
<br>
try {<br>
imageToHistogramFilter->Update<wbr>();<br>
}<br>
catch (itk::ExceptionObject& error) {<br>
std::cerr << "Error: " << error << std::endl;<br>
return EXIT_FAILURE;<br>
}<br>
<br>
ImageToHistogramFilterType::Hi<wbr>stogramType* histogram =<br>
imageToHistogramFilter->GetOut<wbr>put();<br>
<br>
std::cout << "Frequency = [ ";<br>
for (unsigned int i = 0; i < histogram->GetSize()[0]; ++i) {<br>
std::cout << histogram->GetFrequency(i);<br>
<br>
if (i != histogram->GetSize()[0] - 1) {<br>
std::cout << "," << std::endl;<br>
}<br>
}<br>
std::cout << " ]" << std::endl;<br>
<br>
for (unsigned int i = 0; i < histogram->GetSize()[0]; i++) {<br>
std::cout << "Frequency of " << i << " : ("<br>
<< histogram->GetBinMin(0, i) << " to " << histogram->GetBinMax(0,<br>
i)<br>
<< ") = " << histogram->GetFrequency(i) << std::endl;<br>
}<br>
<br>
std::cout << "Total count " << histogram->GetTotalFrequency() <<<br>
std::endl;<br>
}<br>
<br>
<br>
<br>
<br>
--<br>
View this message in context: <a href="http://itk-insight-users.2283740.n2.nabble.com/Histogram-for-a-double-precision-array-tp7589566.html" rel="noreferrer" target="_blank">http://itk-insight-users.22837<wbr>40.n2.nabble.com/Histogram-<wbr>for-a-double-precision-array-<wbr>tp7589566.html</a><br>
Sent from the ITK Insight Users mailing list archive at Nabble.com.<br>
______________________________<wbr>_______<br>
Powered by <a href="http://www.kitware.com" rel="noreferrer" target="_blank">www.kitware.com</a><br>
<br>
Visit other Kitware open-source projects at<br>
<a href="http://www.kitware.com/opensource/opensource.html" rel="noreferrer" target="_blank">http://www.kitware.com/opensou<wbr>rce/opensource.html</a><br>
<br>
Kitware offers ITK Training Courses, for more information visit:<br>
<a href="http://www.kitware.com/products/protraining.php" rel="noreferrer" target="_blank">http://www.kitware.com/product<wbr>s/protraining.php</a><br>
<br>
Please keep messages on-topic and check the ITK FAQ at:<br>
<a href="http://www.itk.org/Wiki/ITK_FAQ" rel="noreferrer" target="_blank">http://www.itk.org/Wiki/ITK_FA<wbr>Q</a><br>
<br>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://public.kitware.com/mailman/listinfo/insight-users" rel="noreferrer" target="_blank">http://public.kitware.com/mail<wbr>man/listinfo/insight-users</a><br>
</blockquote></div><br></div></div>