[ITK] [ITK-users] Multiply two .img or .hdr images in ITK

Pansam Changmi pansam5green at gmail.com
Sun Apr 27 10:48:14 EDT 2014


Thanks guys. My requirement is kind of just using ITK. It is an assignment
actually.
Can you guys help me out what am I doing wrong here. I have busted my head
over this for the whole day. I am getting like 30 errors :'(

The code:

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkMultiplyImageFilter.h"

int main( int argc, char * argv[] )
{
  if( argc < 4 )
    {
    std::cerr << "Usage: " << argv[0];
    std::cerr << " image1  image2 ";
    std::cerr << "outputImagefile " << std::endl;
    return EXIT_FAILURE;
    }

  typedef  unsigned char  PixelType;
  const   unsigned int        Dimension = 3;
  typedef itk::Image< PixelType, Dimension >  Image1Type;
  typedef itk::Image< PixelType, Dimension >  Image2Type;

  typedef itk::ImageFileReader< Image1Type > Image1ReaderType;
  typedef itk::ImageFileReader< Image2Type > Image2ReaderType;


  Image1ReaderType::Pointer Image1Reader = Image1ReaderType::New();
  Image2ReaderType::Pointer Image2Reader = Image2ReaderType::New();

  Image1Reader->SetFileName( argv[1] );
  Image2Reader->SetFileName( argv[2] );

  typedef itk::MultiplyImageFilter <Image1ReaderType, Image2ReaderType >
      MultiplyImageFilterType;

  MultiplyImageFilterType::Pointer multiplyFilter =
MultiplyImageFilterType::New ();
  multiplyFilter->SetInput1(Image1Reader);
  multiplyFilter->SetInput2(Image2Reader);

  typedef itk::Image< PixelType, Dimension > OutputImageType;
  typedef itk::ImageFileWriter< OutputImageType >  WriterType;
  WriterType::Pointer      writer =  WriterType::New();
  writer->SetFileName( argv[3] );
  writer->SetInput( multiplyFilter->GetOutput() );
  writer->Update();

  return EXIT_SUCCESS;
}




On Sun, Apr 27, 2014 at 7:00 PM, Bradley Lowekamp <blowekamp at mail.nih.gov>wrote:

> Hello,
>
> You may be interested in the SimpleITK bindings for ITK. SimpleITK
> provides an easy to use interface on top of ITK which excels facilitation
> quick image manipulation with ITK, and enables interactive manipulations
> with tools such as IPython[1]
>
> SimpleITK for python is readily available as a binary download[2].  What
> you are looking for can be done in SimpleITK like this:
>
> import SimpleITK as sitk
> img1 = sitk.ReadImage("head.img")
> img2 = sitk.ReadImage("BrainMask.img")
> out = img1*img2
> sitk.WriteImage("out.img")
>
> This assumes that the two images occupy the same physical space and are
> the same pixel type. The binary operators in SimpleITK require that the
> pixel types are the same, so a cast may be needed.
>
> However, if you are multiplying a mask by the grayscale you may be
> interested in the MaskImageFilter[3]. This filter will support most
> combinations and can be used:
>
> sitk.Mask(img1, img2).
>
> Enjoy,
> Brad
>
> [1] http://simpleitk.github.io/SimpleITK-Notebooks/
> [2]
> http://www.itk.org/Wiki/SimpleITK/GettingStarted#Downloading_the_binaries
> [3]
> http://www.itk.org/SimpleITKDoxygen/html/classitk_1_1simple_1_1MaskImageFilter.html
>
>
>
>
>
>
> On Apr 27, 2014, at 1:39 AM, Pansam Changmi <pansam5green at gmail.com>
> wrote:
>
> > Hi,
> >
> > Can anyone tell me how to multiply two .img or .hdr images (for example
> head.img and BrainMask.img) in ITK? Do I need VTK? ITK-Snap? C3d tool?
> >
> > Regards,
> > Pansam
> > _____________________________________
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at
> > http://www.kitware.com/opensource/opensource.html
> >
> > Kitware offers ITK Training Courses, for more information visit:
> > http://www.kitware.com/products/protraining.php
> >
> > Please keep messages on-topic and check the ITK FAQ at:
> > http://www.itk.org/Wiki/ITK_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.itk.org/mailman/listinfo/insight-users
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/community/attachments/20140427/29cfa783/attachment-0002.html>
-------------- next part --------------
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.php

Please keep messages on-topic and check the ITK FAQ at:
http://www.itk.org/Wiki/ITK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.itk.org/mailman/listinfo/insight-users


More information about the Community mailing list