[Insight-users] Read / Write File
Dan Mueller
d.mueller at qut.edu.au
Mon Jan 8 17:42:59 EST 2007
Hi Julio,
Welcome to ITK!
One of the best places for newbies to start is the ITK Software Guide:
http://www.itk.org/ItkSoftwareGuide.pdf.
You'll find that ITK supports many different types of files (mainly
image formats) including: jpg, png, mhd, bmp, analyze, dicom, gipl,
nrrd, tiff, vtk, and more! Check out
http://www.itk.org/Wiki/ITK_File_Formats for a quick list.
Reading and writing images using ITK can be done in the following manner
(for unsigned char pixel type, with two dimensions):
typedef unsigned char PixelType;
const unsigned int Dimension = 2;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
typedef itk::ImageFileWriter< ImageType > WriterType;
// Read an image
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFilename );
reader->Update();
ImageType::Pointer image = reader->GetOutput();
// Write an image
WriterType::Pointer writer = WriterType::New();
writer->SetFileName( outputFilename );
writer->SetInput( image );
writer->Update();
The above code might be a little more verbose than the VXL example you
gave, but with ITK you have the added benefit of SmartPointers to take
care of memory deallocation, etc. If you want concise, maybe consider
using the Python wrappers generated by WrapITK:
imagetype = itk.Image[itk.UC, 2]
reader = itk.ImageFileReader[imagetype].New( FileName=argv[1] )
image = reader.GetOutput()
Check out the Examples folder that came with the source files - it's
jammed packed with helpful examples. The above code is a snippet from
Examples/IO/ImageReadWrite.cxx. FYI: the ITK Software Guide was actually
generated directly from the folder of examples!
I hope you enjoy ITK!
Cheers
Dan
pastrana at bgt.uni-hannover.de wrote:
> Hello dear ITK users ...
>
> I have been looking a way to easy read an write files.
> Well, I am getting started with ITK and I dont think it is
> that easy ...
>
> I mean it is not as easy as in VXL:
>
> read>
> vil_image_view<vil_rgb<vxl_byte> > rgb_image;
> rgb_image = vil_load("/pathTOfile/file.bla");
> write>
> vil_save(image_buffer, "FILENAME", "jpeg");
>
>
> With VXL one can read read almost any file
>
> Is there anyway to do that with ITK??
>
> ... I am still trying to figure out the way to do that
> with ITK ... if you could point me in the right direction
> i would really apreciate it ( I know newie question!!!)
>
>
> Thanks ... ciaooo
> Julio
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20070109/f803b7cd/attachment-0001.html
More information about the Insight-users
mailing list