[Insight-users] ExtractImageFilter - newbie needs help!

Ramzy Darwish ramzy_d at hotmail.com
Mon Jun 28 23:09:39 EDT 2004


Hello,
I am VERY new to ITK.

I have used VTK for about 8 months now and am getting the hang of it and I 
would like to get the hang of ITK as well.

I am trying to modify examples to get my results but it is not working 
correctly.

Using Examples\IO\ImageReadExtractWrite.cxx as a starting point, I am trying 
to crop a JPEG image by user specified dimensions through a FLTK UI.

Now I can get the desired dimensions and stuff, but then when I apply the 
filter, it comes back incorrectly. It seems as though different regions of 
the image are superimposed upon each other. Also, the image seems like there 
are missing pixels or something. I had this problem with VTK in reading 
different endian-ed images (big -> little), but I don't think this is my 
problem.

I really don't know where to begin. I don't think that using JPEGs is the 
problem either, but as I said I am very new.

I am enclosing the code I am trying to use.

Please help me!

Thank you,
Ramzy Darwish

/*******************************************************************
int ITKWrapper::CropImage(char *fname, int x, int y, int w, int h)
{
  std::cout << "Cropping image: " << x << ", " << y << ", " << w << ", " << 
h << endl;

  typedef unsigned short        InputPixelType;
  typedef unsigned short        OutputPixelType;

  typedef itk::Image< InputPixelType,  2 >    InputImageType;
  typedef itk::Image< OutputPixelType, 2 >    OutputImageType;

  typedef itk::ImageFileReader< InputImageType  >  ReaderType;
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;

  const char * inputFilename  = "IM000018.jpg";
  const char * outputFilename = "tmp.jpg";

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

  reader->SetFileName( inputFilename  );
  writer->SetFileName( outputFilename );

  typedef itk::ExtractImageFilter< InputImageType, OutputImageType > 
FilterType;
  FilterType::Pointer filter = FilterType::New();

  reader->Update();
  InputImageType::RegionType inputRegion =
           reader->GetOutput()->GetLargestPossibleRegion();
  InputImageType::SizeType size = inputRegion.GetSize();
  size[0] = 100;
  size[1] = 100;
  size[2] = 0;

  InputImageType::IndexType start = inputRegion.GetIndex();
  //const unsigned int sliceNumber = atoi( argv[3] );
  start[0] = 100;
  start[1] = 100;
  //start[2] = sliceNumber;
  InputImageType::RegionType desiredRegion;
  desiredRegion.SetSize(  size  );
  desiredRegion.SetIndex( start );
  filter->SetExtractionRegion( desiredRegion );
  filter->SetInput( reader->GetOutput() );
  filter->Update();
  writer->SetInput( filter->GetOutput() );

  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cout << "ExceptionObject caught !" << std::endl;
    std::cout << err.what() << std::endl;
    return -1;
    }

  return 0;
}
*******************************************************/

_________________________________________________________________
MSN 9 Dial-up Internet Access fights spam and pop-ups – now 3 months FREE! 
http://join.msn.click-url.com/go/onm00200361ave/direct/01/



More information about the Insight-users mailing list