[Insight-users] Re: extraction of a portion of an images?
Luis Ibanez
luis . ibanez at kitware . com
Fri, 23 Aug 2002 09:57:20 -0400
This is a multi-part message in MIME format.
--------------080800040004070204050706
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit
Hi Zein,
An Example on image Extraction was just added last night to
Insight/Examples/ExtractImageFilter
It is here attached too.
This example takes parameters from the command line.
Reads an image, extract a portion from the image and
writes the extracted piece into another file.
The command should look like:
"ExtractImageRegion input.mha output.mha 12 20 25 100 200 100"
This will extracts a region starting at pixel (12,20,25) and
with size (100,200,100).
Please let us know if you encounter any problem using
this filter.
Thanks
Luis
================================================
Zein Salah wrote:
> Hi Luis,
>
>
>
> I want to extract a portion of a volume image (a cubic region). I have
> looked at the testing example of extractimagefilter in
> insight/testing/...... The example is too complicated. The docmumentation in
>
> http://www.itk.org/Insight/Doxygen/html/classitk_1_1ExtractImageFilter.html
> is also somehow not helpfull.
>
> Can you please provide with simplest code to do the job??
>
> Many thanks in advanced...
>
> Zein
>
> ->8<------------->8<------------->8<------------->8<------------->8<------------->8<-
> Zein I. Salah
> Universität Tübingen, WSI-GRIS
> Sand 14
> 72076 Tübingen
> Email: salah@gris.uni-tuebingen.de <mailto:salah@gris.uni-tuebingen.de>
> / zeinsalah@hotmail.com <mailto:zeinsalah@hotmail.com>
> Tel.: (07071) 29 75465 (GRIS) , (07071) 96 44 39 (privat)
>
==============================================
--------------080800040004070204050706
Content-Type: text/plain;
name="ExtractImageRegion.cxx"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="ExtractImageRegion.cxx"
/*=========================================================================
Program: Insight Segmentation & Registration Toolkit
Module: $RCSfile: ExtractImageRegion.cxx,v $
Language: C++
Date: $Date: 2002/08/23 00:56:53 $
Version: $Revision: 1.1 $
Copyright (c) 2002 Insight Consortium. All rights reserved.
See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#include <iostream>
#include <itkImage.h>
#include <itkImageFileWriter.h>
#include <itkImageFileReader.h>
#include <itkMetaImageIO.h>
#include <itkExtractImageFilter.h>
int main(int argc, char **argv)
{
if( argc < 9 )
{
std::cerr << "Usage: ExtractImageRegion inputImageFile outputImageFile ";
std::cerr << "xStart yStart zStart xSize ySize zSize " << std::endl;
return 1;
}
// Declare the image
typedef itk::Image<unsigned short, 3> ImageType;
// Declare a Reader
typedef itk::ImageFileReader< ImageType > VolumeReaderType;
VolumeReaderType::Pointer reader = VolumeReaderType::New();
// Set the filename
reader->SetFileName( argv[1] );
// Declare the Extract filter
typedef itk::ExtractImageFilter< ImageType, ImageType > ExtractFilterType;
ExtractFilterType::Pointer extractor = ExtractFilterType::New();
extractor->SetInput( reader->GetOutput() );
ImageType::SizeType size;
ImageType::IndexType index;
index[0] = atoi( argv[3] );
index[1] = atoi( argv[4] );
index[2] = atoi( argv[5] );
size[0] = atoi( argv[6] );
size[1] = atoi( argv[7] );
size[2] = atoi( argv[8] );
ImageType::RegionType region;
region.SetIndex( index );
region.SetSize( size );
extractor->SetExtractionRegion( region );
// Declare a Writer
typedef itk::ImageFileWriter< ImageType > VolumeWriterType;
VolumeWriterType::Pointer writer = VolumeWriterType::New();
// Add the MetaImage format to the writer
writer->SetImageIO( itk::MetaImageIO::New() );
// Set the filename
writer->SetFileName( argv[2] );
// Set the image to write
writer->SetInput( extractor->GetOutput() );
// Write the image
writer->Update();
}
--------------080800040004070204050706--