[Insight-users] Reg 64X64 images
Luis Ibanez
luis.ibanez@kitware.com
Sat, 19 Apr 2003 18:29:48 -0400
Hi Prasad,
You don't need to explicitly set a MetaImageIO reader.
If you already created the MetaImage header file, you
can load it simply by declaring an ImageFileReader
like:
#include "itkImageFileReader.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkImage.h"
typedef itk::Image< float, 2 > InputImageType;
typedef itk::Image< unsigned char ,2 > InternalImageType;
typedef itk::ImageFileReader< InputImageType > ReaderType;
typedef itk::RescaleIntensityImageFilter<
InputImageType, InternalImageType > FilterType;
ReaderType::Pointer reader = ReaderType::New();
FilterType::Pointer filter = FilterType::New();
reader->SetFileName("image.mhd");
filter->SetInput( reader->GetOutput() );
filter->Update();
The ITK file IO factory mechanism will select the
appropriate reader for you. Just make sure the the
filename has extension ".mha" or ".mhd".
There are multiple examples of this mechanism
in the directories:
Insight/Examples/IO
Insight/Examples/Filtering
Luis
-------------------
Prasad Sarma wrote:
> hi Luis,
> I have tried to do as you said, I wrote the code to
> use RescaleIntensity Image filter for my program
> to convert from float to unsigned char and I
> confronted a problem.
> The rescaler Image intensity imae filer required the
> input to be output of a "file reader" which must be
> set to someImageIO, as I have raw Images I have used
> metaImageIO
> and I am stuck at this point.Here's part of my code,
> could you pl tell me whether I am going in the right
> direction? I just highlighted my doubt.
>
>
> ------------------------------
>
> //define input, output image types
>
> typedef itk::Image<unsigned char, 3> OutputImageType;
> typedef itk::Image<float,3> InputImageType;
>
> // define the rescale type and instantiate it
>
> typedef
> itk::RescaleIntensityImageFilter<InputImageType,OutputImageType>
> RescaleType;
>
> RescaleType::Pointer
> rescaler=RescaleFilterType::New();
>
>
> float a[3];
> a[0]=a[1]=a[2]=1.0;
>
> // Create the IO object to read Meta images
>
>
> itk::MetaImageIO::poinetr io1;
> io1= itk::MetaImageIO::New();
>
>
> io1->setSpacing(a);
> io1->SupportsDimension(3.0);
> io1->setFileType("Binary");
>
> *******************************************
>
> how to set the dimensions of the image as 19*64*64 for
> the 3 dimensions
>
> in meta Image IO ?
>
> *******************************************
>
>
> // Create the IO object to write PNG images
>
> itk::PNGImageIO::Pointer io;
> io = itk::PNGImageIO::New();
>
> // Instantiate the reader
> itk::ImageFileReader<InputImageType>::Pointer reader;
> reader = itk::ImageFileReader<InputImageType>::New();
>
>
> // Set the parameters of the reader
> reader->SetFileName("19178_1.raw");
> reader->SetImageIO(io1);
> // Read the image
>
> rescaler->SetInput(reader->GetOutput());
>
>
> rescaler->SetOutputMinimum(0);
> rescaler->SetOutputMaximum(255);
>
> rescaler->Update();
>
> // Instantiate the writer
> itk::ImageFileWriter<OutputImageType>::Pointer writer;
> writer = itk::ImageFileWriter<OutputImageType>::New();
>
> // Set the parameters of the writer
> writer->SetInput(rescaler->GetOutput());
> writer->SetFileName("myoutputimage.png");
> writer->SetImageIO(io);
>
> // Write the output
> writer->Write();
>
> --------------
>
> Thanks
> Prasad
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> --- Luis Ibanez <luis.ibanez@kitware.com> wrote:
>
>>Hi Prasad,
>>
>>It is not surprising that your image lost most
>>information after the conversion.
>>
>>If you converted floats to unsigned char just
>>by using C-style casting it is very likely that
>>you truncated the original float values.
>>
>>Did you verified if the float values were in the
>>range [0,255] before casting them to unsigned chars
>>?
>>
>>
>>You should rather use a normalization filter,
>>like for example the
>>
>> itk::RescaleIntensityImageFilter
>>
>
> http://www.itk.org/Insight/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html
>
>>
>>Examples on the use of this filter are available
>>on the SoftwareGuide:
>>http://www.itk.org/ItkSoftwareGuide.pdf
>>In the "Casting" section : 5.2, pdf-page 96.
>>
>>
>>
>>In any case, there is not much that you can see
>>in a 64x64 image :-)
>>
>>
>>
>>I would suggest you to create a couple of synthetic
>>images of this resolution in order to test your
>>procedures, before you move into processing real
>>medical data. A typical example could be something
>>like a circle of radius 25pixels centered in the
>>64x64 image.
>>
>>
>>
>>Regards,
>>
>>
>> Luis
>>
>>
>>--------------------------
>>Prasad Sarma wrote:
>>
>>>hi,
>>>
>>> I have 19 images downloaded from GE scanner
>>
>>which
>>
>>>are of 64X64 resoultion with datatype as
>>
>>"float".The
>>
>>>raw files are generated in unix. I converted them
>>
>>into
>>
>>>"unsigned char" in unix using just typecast
>>
>>operator
>>
>>>of c .
>>>when I copy this file to windows and run using
>>>ITK/VTK/FLTK,the image displayed is very bad just
>>
>>no
>>
>>>structure ..only dots appear. I used MetaImageIO
>>>function in ITK.
>>>
>>>
>>>
>>>When I use MetaImageIO for an "unsigned char"
>>
>>image of
>>
>>>180X217X180 as dimension(z,y,x resprectively) the
>>>image is good.
>>>
>>> does the resolution matter? did anyone get good
>>>images with 64 X 64 resolution?
>>>Pl let me know.
>>>Thanks
>>>
>>>Prasad
>>>
>>>__________________________________________________
>>>Do you Yahoo!?
>>>The New Yahoo! Search - Faster. Easier. Bingo
>>>http://search.yahoo.com
>>>_______________________________________________
>>>Insight-users mailing list
>>>Insight-users@public.kitware.com
>>>
>>
> http://public.kitware.com/mailman/listinfo/insight-users
>
>>
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users@public.kitware.com
>>
>
> http://public.kitware.com/mailman/listinfo/insight-users
>
>
> __________________________________________________
> Do you Yahoo!?
> The New Yahoo! Search - Faster. Easier. Bingo
> http://search.yahoo.com
>