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

Tobias Gass gass at vision.ee.ethz.ch
Sun Apr 27 06:21:12 EDT 2014


Hi,

I didn't follow everything in detail, but it looks as if you're trying to
pass an image with PixelType unsigned short to a writer which expects an
image with PixelType unsigned char, which wont work. Please also be aware
of the value ranges of the PixelTypes you declare. Multiplying two short
ints can easily lead to overflow when casting to unsigned char. I'd even be
careful casting them to short unless I am very certain about the expected
intensity range in the images.

HTH
Tobias


2014-04-27 12:20 GMT+02:00 Tobias Gass <tobiasgass at gmail.com>:

> Hi,
>
> I didn't follow everything in detail, but it looks as if you're trying to
> pass an image with PixelType unsigned short to a writer which expects an
> image with PixelType unsigned char, which wont work. Please also be aware
> of the value ranges of the PixelTypes you declare. Multiplying two short
> ints can easily lead to overflow when casting to unsigned char. I'd even be
> careful casting them to short unless I am very certain about the expected
> intensity range in the images.
>
> HTH
> Tobias
>
>
> 2014-04-27 11:15 GMT+02:00 Pansam Changmi <pansam5green at gmail.com>:
>
> Thanks Christopher,
>>
>> I removed the VTK viewer part and instead of creating two images I edited
>> the code to read tow ".hdr" files and write one ".hdr" output file. But I
>> am getting the following errors. I couldn't figure out the problem. Given
>> below is multiplyFilter.cxx 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 << " fixedImageFile  movingImageFile ";
>>     std::cerr << "outputImagefile " << std::endl;
>>     return EXIT_FAILURE;
>>     }
>>
>>   typedef  unsigned short  PixelType;
>>   const   unsigned int        Dimension = 3;
>>   typedef itk::Image< PixelType, Dimension >  FixedImageType;
>>   typedef itk::Image< PixelType, Dimension >  MovingImageType;
>>
>>   typedef itk::ImageFileReader< FixedImageType  > FixedImageReaderType;
>>   typedef itk::ImageFileReader< MovingImageType > MovingImageReaderType;
>>
>>   FixedImageReaderType::Pointer  fixedImageReader  =
>> FixedImageReaderType::New();
>>   MovingImageReaderType::Pointer movingImageReader =
>> MovingImageReaderType::New();
>>
>>   fixedImageReader->SetFileName( argv[1] );
>>   movingImageReader->SetFileName( argv[2] );
>>
>>   typedef itk::MultiplyImageFilter <FixedImageReaderType,
>> MovingImageReaderType >
>>       MultiplyImageFilterType;
>>
>>   MultiplyImageFilterType::Pointer multiplyFilter
>>     = MultiplyImageFilterType::New ();
>>   multiplyFilter->SetInput1(fixedImageReader);
>>   multiplyFilter->SetInput2(movingImageReader);
>>
>>   typedef  unsigned char  OutputPixelType;
>>
>>   typedef itk::Image< OutputPixelType, 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 11:14 AM, Christopher Mullins <
>> christopher.mullins at kitware.com> wrote:
>>
>>> This example might help. You can delete the VTK-viewer bit if you want,
>>> should only need ITK.
>>>
>>> http://www.itk.org/Wiki/ITK/Examples/ImageProcessing/MultiplyImageFilter
>>> On Apr 27, 2014 1:40 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
>>>>
>>>>
>>
>> _____________________________________
>> 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://www.itk.org/pipermail/insight-users/attachments/20140427/13ff6cdc/attachment.html>


More information about the Insight-users mailing list