[Insight-users] Can "update" not be used in different implementions?

zhouyi_hust zhouyi_hust at 163.com
Tue Feb 7 13:40:29 EST 2006


Hello all:
 
I used c++ language and compiled my programme in visual c++.
I want to rescale image intensity in the implemention - RescaleImage() .
In this method, I wrote 
writer->SetFileName( "c:\\tmp.bmp" );
writer->Update(); to save the rescaled image.
In another implemention - ImageHistogram2(), I wrote 
reader->SetFileName( "c:\\tmp.bmp" );
reader->Update(); to read the saved image --"c:\\tmp.bmp" .
When I execute the *.exe, it seems that reading "c:\\tmp.bmp" in ImageHistogram2() has some errors.
I do not know why it happens and how to avoid this kind of error.
 
The methods are as below:
 
void CItkMFCDoc::RescaleImage()
{
 typedef float InputPixelType;
 typedef unsigned char OutputPixelType;
 typedef itk::Image< InputPixelType,  2 >   InputImageType;
 typedef itk::Image< OutputPixelType, 2 >   OutputImageType;
 typedef itk::ImageFileReader< InputImageType >  ReaderType;
 typedef itk::ImageFileWriter< OutputImageType >  WriterType;
 typedef itk::RescaleIntensityImageFilter< 
                                  InputImageType, 
                                  OutputImageType >    FilterType;
 
 FilterType::Pointer filter = FilterType::New();
 filter->SetOutputMinimum(   0 );
 filter->SetOutputMaximum( 255 );
 ReaderType::Pointer reader = ReaderType::New();
 WriterType::Pointer writer = WriterType::New();
 filter->SetInput( reader->GetOutput() );
 writer->SetInput( filter->GetOutput() );
 
 reader->SetFileName( m_FilePathName );
 writer->SetFileName( "c:\\tmp.bmp" );
  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & excp )
    {
    CString fmt;
    fmt.Format("Write image failed:\n%s",excp.GetDescription() );
    ::AfxMessageBox(fmt);
    }
 
}

void CItkMFCDoc::ImageHistogram2()
{
 typedef unsigned char       PixelType;
 typedef itk::Image<PixelType, 2 > ImageType;
 typedef itk::ImageFileReader< ImageType > ReaderType;
 ReaderType::Pointer reader = ReaderType::New();
 reader->SetFileName( "c:\\tmp.bmp" );
 try
 {
  reader->Update();
 }
 catch( itk::ExceptionObject & excp )
 {
  CString str ;
  str.Format(_T("Problem reading image file : %s"),m_FilePathName);
  
  ::AfxMessageBox((LPCSTR)str); 
 }
 typedef itk::Statistics::ScalarImageToHistogramGenerator< 
                                 ImageType >   HistogramGeneratorType;
 HistogramGeneratorType::Pointer histogramGenerator =
                                        HistogramGeneratorType::New();
 histogramGenerator->SetInput(  reader->GetOutput() );
 histogramGenerator->SetNumberOfBins( 255 );
 histogramGenerator->SetMarginalScale( 10.0 );
 histogramGenerator->Compute();
 
 typedef HistogramGeneratorType::HistogramType  HistogramType;
 const HistogramType * histogram = histogramGenerator->GetOutput();
 const unsigned int histogramSize = histogram->Size();
 HistogramType::ConstIterator itr = histogram->Begin();
 HistogramType::ConstIterator end = histogram->End();
 
 unsigned int binNumber = 0;
 while( itr != end )
    {
  std::cout << "bin = " << binNumber << " frequency = ";
  std::cout << itr.GetFrequency() << std::endl;     
  ++itr;
  ++binNumber;
   }
}

Looking forward to your answers.
Thank you very much.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20060208/2df273d5/attachment.htm


More information about the Insight-users mailing list