[Insight-users] Help

Luis Ibanez luis . ibanez at kitware . com
Sat, 01 Jun 2002 11:04:32 -0400


Hi cspl,

you can give the filename to the ImageFileReader
by calling :

               SetFileName();

See the man page for details:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1ImageFileReader.html

For example:

typedef itk::Image<char,3>  ImageType;
typedef itk::ImageFileReader< ImageType >  ReaderType;
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName("/home/cspl/data/myImage.raw");

// this line registers a Factory of readers
// capable of reading RAW image files
itk::RawImageIOFactory::RegisterOneFactory();

// Here: actually read the file
reader->Update();



NOTE that the raw readers requires you to provide the
image size and spacing since they cannot figure it out
from the file.

See the following man page for details:
http://www.itk.org/Insight/Doxygen/html/classitk_1_1RawImageIO.html


After that you can connect the reader's output as
input to any number of filters, for example:


typedef itk::LaplacianImageFilter<ImageType,
	                          ImageType>   LaplacianFilterType;

LaplacianFilterType::Pointer  filterA = LaplacianFilterType::New();

filterA->SetInput( reader->GetOutput() );


NOTE: in the code in you email, you are using Iterators to pass
the output of the reader to an input image. You *don't* need to do
that.  The ITK pipeline mechanisms will do all that for you !

Just plug the output of the reader as input of the filter.



----




If you get an Exception during execution,
Please post the exception message to the mailing-list,
that could be useful to figure out the problem.



Please let us know if you find any problems



   Luis



================================

cspl wrote:
> Dear Mr.Luis,
> 
> Now I can able to run the application.Actually I want to give the input to
> the Laplician filter and get the output.How to give the filename to
> ImageFilereader.I have written code as follows.It is giving memory
> exception.Please tell me that how to give the input's and get output's.
> 
> 
> 
> int main()
> {
> 
> UnsignedImageType::RegionType requestedRegion;
>   UnsignedImageType::SizeType  size;
>   UnsignedImageType::IndexType index;
> 
> 
>  size of the image region
>   //If you want to try a 2D image, you need to change the dimension.
>   size[0] = 256;
>   size[1] = 128;
>   size[2] = 10;
> 
>   index[0] = 0;
>   index[1] = 0;
>   index[2] = 0;
> 
>   requestedRegion.SetSize(size);
>   requestedRegion.SetIndex(index);
> 
> 
>   itk22::ImageFileReader<ImageType>::Pointer  reader;
> 
>   reader->SetFileName("c:\\dicomfiles\\download\\xyz\\1.raw");
> 
> ///commented
> ing *pfname=new std::string;
>   strcpy(pfname,"1.raw");
>   reader->SetFileName(fname);*/
> 
> //  reader->SetPixelSize(4);
> //  reader->SetRegion(requestedRegion);
>   //cout<<"coming here"<<endl;
>   reader->Update();
> //  reader->GenerateData();
> 
> 
>  // UnsignedImageType::Pointer inPtr =  reader->GetOutput();
>   ImageType::Pointer input = ImageType::New();
>   input->SetLargestPossibleRegion(requestedRegion);
>   input->SetRequestedRegion(requestedRegion);
>   input->SetBufferedRegion(requestedRegion);
>   input->Allocate();
> 
>   ImageType::Pointer output = ImageType::New();
>   ///commented
> 
> geRegionIterator<UnsignedImageType>  uit(inPtr,
> inPtr->GetRequestedRegion());
>   itk::ImageRegionIterator<ImageType>  it(input,
> input->GetRequestedRegion());
> 
>   uit.GoToBegin();
>   it.GoToBegin();
> 
>   while(!uit.IsAtEnd())
>     {
>       it.Value() = (float)uit.Value();
>       ++uit;
>       ++it;
>     }
> 
> 
>   ImageType::Pointer output;
> 
>   //itk::ImageFileReader<ImageType>::Pointer  reader;
>   //reader =  itk::ImageFileReader<ImageType>::New();
>   //reader->SetFileName(in);
>   //reader->Update();
>   //ImageType::Pointer input = reader->GetOutput();
> 
>   float value[3];
>   value[0] = 2.0f;
>   value[1] = 2.0f;
>   value[2] = 2.0f;*/
> 
> 
>   cout<<"Laplacian filter test"<<endl;
>   itk12::DiscreteGaussianImageFilter<ImageType, ImageType>::Pointer
>     gaussianFilter = itk12::DiscreteGaussianImageFilter<ImageType,
> ImageType>::New();
> 
>   gaussianFilter->SetInput(input);
> //  gaussianFilter->SetVariance(value);
> 
> 
>   itk::LaplacianImageFilter<ImageType, ImageType>::Pointer
>     lapFilter = itk::LaplacianImageFilter<ImageType, ImageType>::New();
> 
> 
>   lapFilter->SetInput(gaussianFilter->GetOutput());
> 
> 
>   lapFilter->Update();
> 
>   output = lapFilter->GetOutput();
>   cout<<output->GetLargestPossibleRegion();
> 
> return 0;
> }
> 
> I am passing raw file as input.I want it's o/p.Please in which way I have to
> follow.I have copied required name spaces to my cpp file to run this
> application.But it is giving memory exception when it is at runtime.Please
> tell me  how to approach the correct flow of syntax.
> 
> 
> Thanking you,
> Regards,
> Ramakrishna
> 
> 
>