<P>Hello all:</P>
<P> </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 wrote </P>
<P>writer->SetFileName( "c:\\tmp.bmp" );</P>
<P>writer->Update(); to save the rescaled image.</P>
<P>In another implemention - ImageHistogram2(), I wrote </P>
<P>reader->SetFileName( "c:\\tmp.bmp" );</P>
<P>reader->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> </P>
<P>The methods are as below:</P>
<P> </P>
<P>void CItkMFCDoc::RescaleImage()<BR>{<BR> typedef float InputPixelType;<BR> typedef unsigned char OutputPixelType;</P>
<P> typedef itk::Image< InputPixelType, 2 > InputImageType;<BR> typedef itk::Image< OutputPixelType, 2 > OutputImageType;</P>
<P> typedef itk::ImageFileReader< InputImageType > ReaderType;<BR> typedef itk::ImageFileWriter< OutputImageType > WriterType;</P>
<P> typedef itk::RescaleIntensityImageFilter< <BR> InputImageType, <BR> OutputImageType > FilterType;<BR> <BR> FilterType::Pointer filter = FilterType::New();<BR> filter->SetOutputMinimum( 0 );<BR> filter->SetOutputMaximum( 255 );</P>
<P> ReaderType::Pointer reader = ReaderType::New();<BR> WriterType::Pointer writer = WriterType::New();</P>
<P> filter->SetInput( reader->GetOutput() );<BR> writer->SetInput( filter->GetOutput() );<BR> <BR> reader->SetFileName( m_FilePathName );<BR> writer->SetFileName( "c:\\tmp.bmp" );</P>
<P> try<BR> {<BR> writer->Update();<BR> }<BR> catch( itk::ExceptionObject & excp )<BR> {<BR> CString fmt;<BR> fmt.Format("Write image failed:\n%s",excp.GetDescription() );<BR> ::AfxMessageBox(fmt);<BR> }</P>
<P> <BR>}<BR></P>
<P>void CItkMFCDoc::ImageHistogram2()<BR>{<BR> typedef unsigned char PixelType;<BR> typedef itk::Image<PixelType, 2 > ImageType;<BR> typedef itk::ImageFileReader< ImageType > ReaderType;</P>
<P> ReaderType::Pointer reader = ReaderType::New();<BR> reader->SetFileName( "c:\\tmp.bmp" );</P>
<P> try<BR> {<BR> reader->Update();<BR> }<BR> catch( itk::ExceptionObject & excp )<BR> {<BR> CString str ;<BR> str.Format(_T("Problem reading image file : %s"),m_FilePathName);<BR> <BR> ::AfxMessageBox((LPCSTR)str); <BR> }<BR> typedef itk::Statistics::ScalarImageToHistogramGenerator< <BR> ImageType > HistogramGeneratorType;</P>
<P> HistogramGeneratorType::Pointer histogramGenerator =<BR> HistogramGeneratorType::New();<BR> histogramGenerator->SetInput( reader->GetOutput() );<BR> histogramGenerator->SetNumberOfBins( 255 );<BR> histogramGenerator->SetMarginalScale( 10.0 );<BR> histogramGenerator->Compute();<BR> <BR> typedef HistogramGeneratorType::HistogramType HistogramType;<BR> const HistogramType * histogram = histogramGenerator->GetOutput();<BR> const unsigned int histogramSize = histogram->Size();</P>
<P> HistogramType::ConstIterator itr = histogram->Begin();<BR> HistogramType::ConstIterator end = histogram->End();<BR> <BR> unsigned int binNumber = 0;<BR> while( itr != end )<BR> {<BR> std::cout << "bin = " << binNumber << " frequency = ";<BR> std::cout << itr.GetFrequency() << std::endl; <BR> ++itr;<BR> ++binNumber;<BR> }<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>