<P>Hello all:</P>
<P>&nbsp;</P>
<P>I used c++ language and compiled my programme in visual c++.</P>
<P>I want to rescale image intensity in the implemention - RescaleImage() .</P>
<P>In this method, I&nbsp;wrote </P>
<P>writer-&gt;SetFileName( "c:\\tmp.bmp" );</P>
<P>writer-&gt;Update(); to save the rescaled image.</P>
<P>In another implemention - ImageHistogram2(), I wrote </P>
<P>reader-&gt;SetFileName( "c:\\tmp.bmp" );</P>
<P>reader-&gt;Update(); to read the saved image --"c:\\tmp.bmp" .</P>
<P>When I execute the *.exe, it seems that reading "c:\\tmp.bmp" in ImageHistogram2() has some errors.</P>
<P>I do not know why it happens and how to avoid this kind of error.</P>
<P>&nbsp;</P>
<P>The methods are as below:</P>
<P>&nbsp;</P>
<P>void CItkMFCDoc::RescaleImage()<BR>{<BR>&nbsp;typedef float InputPixelType;<BR>&nbsp;typedef unsigned char OutputPixelType;</P>
<P>&nbsp;typedef itk::Image&lt; InputPixelType,&nbsp; 2 &gt;&nbsp;&nbsp; InputImageType;<BR>&nbsp;typedef itk::Image&lt; OutputPixelType, 2 &gt;&nbsp;&nbsp; OutputImageType;</P>
<P>&nbsp;typedef itk::ImageFileReader&lt; InputImageType &gt;&nbsp; ReaderType;<BR>&nbsp;typedef itk::ImageFileWriter&lt; OutputImageType &gt;&nbsp; WriterType;</P>
<P>&nbsp;typedef itk::RescaleIntensityImageFilter&lt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; InputImageType, <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; OutputImageType &gt;&nbsp;&nbsp;&nbsp; FilterType;<BR>&nbsp;<BR>&nbsp;FilterType::Pointer filter = FilterType::New();<BR>&nbsp;filter-&gt;SetOutputMinimum(&nbsp;&nbsp; 0 );<BR>&nbsp;filter-&gt;SetOutputMaximum( 255 );</P>
<P>&nbsp;ReaderType::Pointer reader = ReaderType::New();<BR>&nbsp;WriterType::Pointer writer = WriterType::New();</P>
<P>&nbsp;filter-&gt;SetInput( reader-&gt;GetOutput() );<BR>&nbsp;writer-&gt;SetInput( filter-&gt;GetOutput() );<BR>&nbsp;<BR>&nbsp;reader-&gt;SetFileName( m_FilePathName );<BR>&nbsp;writer-&gt;SetFileName( "c:\\tmp.bmp" );</P>
<P>&nbsp; try<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; writer-&gt;Update();<BR>&nbsp;&nbsp;&nbsp; }<BR>&nbsp; catch( itk::ExceptionObject &amp; excp )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;&nbsp; CString fmt;<BR>&nbsp;&nbsp;&nbsp; fmt.Format("Write image failed:\n%s",excp.GetDescription() );<BR>&nbsp;&nbsp;&nbsp; ::AfxMessageBox(fmt);<BR>&nbsp;&nbsp;&nbsp; }</P>
<P>&nbsp;<BR>}<BR></P>
<P>void CItkMFCDoc::ImageHistogram2()<BR>{<BR>&nbsp;typedef unsigned char&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; PixelType;<BR>&nbsp;typedef itk::Image&lt;PixelType, 2 &gt; ImageType;<BR>&nbsp;typedef itk::ImageFileReader&lt; ImageType &gt; ReaderType;</P>
<P>&nbsp;ReaderType::Pointer reader = ReaderType::New();<BR>&nbsp;reader-&gt;SetFileName( "c:\\tmp.bmp" );</P>
<P>&nbsp;try<BR>&nbsp;{<BR>&nbsp;&nbsp;reader-&gt;Update();<BR>&nbsp;}<BR>&nbsp;catch( itk::ExceptionObject &amp; excp )<BR>&nbsp;{<BR>&nbsp;&nbsp;CString str ;<BR>&nbsp;&nbsp;str.Format(_T("Problem reading image file : %s"),m_FilePathName);<BR>&nbsp;&nbsp;<BR>&nbsp;&nbsp;::AfxMessageBox((LPCSTR)str); <BR>&nbsp;}<BR>&nbsp;typedef itk::Statistics::ScalarImageToHistogramGenerator&lt; <BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ImageType &gt;&nbsp;&nbsp; HistogramGeneratorType;</P>
<P>&nbsp;HistogramGeneratorType::Pointer histogramGenerator =<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; HistogramGeneratorType::New();<BR>&nbsp;histogramGenerator-&gt;SetInput(&nbsp; reader-&gt;GetOutput() );<BR>&nbsp;histogramGenerator-&gt;SetNumberOfBins( 255 );<BR>&nbsp;histogramGenerator-&gt;SetMarginalScale( 10.0 );<BR>&nbsp;histogramGenerator-&gt;Compute();<BR>&nbsp;<BR>&nbsp;typedef HistogramGeneratorType::HistogramType&nbsp; HistogramType;<BR>&nbsp;const HistogramType * histogram = histogramGenerator-&gt;GetOutput();<BR>&nbsp;const unsigned int histogramSize = histogram-&gt;Size();</P>
<P>&nbsp;HistogramType::ConstIterator itr = histogram-&gt;Begin();<BR>&nbsp;HistogramType::ConstIterator end = histogram-&gt;End();<BR>&nbsp;<BR>&nbsp;unsigned int binNumber = 0;<BR>&nbsp;while( itr != end )<BR>&nbsp;&nbsp;&nbsp; {<BR>&nbsp;&nbsp;std::cout &lt;&lt; "bin = " &lt;&lt; binNumber &lt;&lt; " frequency = ";<BR>&nbsp;&nbsp;std::cout &lt;&lt; itr.GetFrequency() &lt;&lt; std::endl;&nbsp;&nbsp;&nbsp;&nbsp; <BR>&nbsp;&nbsp;++itr;<BR>&nbsp;&nbsp;++binNumber;<BR>&nbsp;&nbsp; }<BR>}<BR><BR>Looking forward to your answers.</P>
<P>Thank you very much.<BR><BR></P><SPAN ></SPAN><br><!-- footer --><br><br><br><br><br><div style="border-bottom:1px solid #999"></div><br>

        <font color="black" style="font-size:14.8px">你 知 道 2006 年 最 火 爆 的 电 子 邮 箱 吗 ? </font>
        <br>
        <a href="http://www.126.com/help/126fab.htm" target="_blank" style="font-size:13px;line-height:160%;color:blue">多 达 1.1 亿 中 国 人 选 择 网 易 2000 兆 免 费 邮 箱 , 抢 注 再 得 280 兆 超 大 网 盘
</a>