[Insight-users] Problem with itkAddImageFilter

Luis Ibanez luis . ibanez at kitware . com
Thu, 30 Oct 2003 10:21:53 -0500


Hi Anders,

Thanks for posting your typedefs.

Your use of (unsigned short) look fine.
The addition process should be working ok
and probably the only problem is on the
viewing side.

That is, your resulting image should have
values from 0 to 512 (255 x 2) immersed
in a dynamic range from 0 to 65535.
Please use a viewer that allows you to
normalize intensities.

For example, the "display" tool from
ImageMagick  will offer you this option
(it will not normalize by default).

The ImageViewer tool distributed with
InsightApplication is probably the
best (for the price :-) ) viewer that
you can use for medical images.


Regards,


    Luis



----------------------
Anders Almås wrote:
> Hi again!
> 
> Here follows my type definitions:
> 
> const unsigned int Dimension = 2;
> typedef unsigned short PixelType;
> typedef itk::Image<PixelType,Dimension> ImageType;
> 
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::ImageFileWriter<ImageType> WriterType;
> typedef itk::AddImageFilter<ImageType,ImageType,ImageType> addFilterType;
> 
> This is all my typedefs.. the files  which I use are png's with only 0 and
> 255 as pixel values...
> 
> Anders
> 
> 
> -------------------------------------------------------------------------------
> Navn:   Anders Almås
> E-post: andersal at stud . ntnu . no
> Tlf:    90550374
> -------------------------------------------------------------------------------
> 

> 
> On Thu, 30 Oct 2003, Luis Ibanez wrote:
> 
> 
>>Hi Anders,
>>
>>
>>Please post the type definitions that you used for adding
>>these two images as well as the types you used for saving
>>the image into a file.
>>
>>
>>---
>>
>>
>>You should be doing something like
>>
>>typedef itk::Image< unsigned char,  3 >   InputImageType;
>>typedef itk::Image< unsigned short, 3 >   OutputImageType;
>>
>>// Note that the output image type requires a larger
>>// dynamic range (unsigned short) in order to hold
>>// the values resulting from the addition.
>>
>>typedef itk::AddImageFilter<
>>                      InputImageType,
>>                      InputImageType,
>>                      OutputImageType   > AdderType;
>>
>>typedef itk::Image< unsigned char, 3 >   WriteImageType;
>>
>>typedef itk::RescaleIntensityImageFilter<
>>                                   OutputImageType,
>>                                   WriteImageType
>>                                          >   RescalerType;
>>
>>typedef itk::ImageFileWriter< WriteImageType > WriterType;
>>
>>// Note that the writer type is declared using 8 bits
>>// and the rescaler filter will renormalize the
>>// intensity levels of the sum in order to fit in 8 bits again.
>>// (after the addition the data was potentially in 9 bits.)
>>
>>AdderType::Pointer adder = AdderType::New();
>>
>>RescalerType::Pointer rescaler = RescalerType::New();
>>
>>WriterType::Pointer writer = WriterType::New();
>>
>>adder->SetInput1( image1 );
>>adder->SetInput2( image2 );
>>
>>rescaler->SetInput( adder->GetOutput() );
>>rescaler->SetOutputMinimum(   0 );
>>rescaler->SetOutputMaximum( 255 );
>>
>>writer->SetInput( rescaler->GetOutput() );
>>
>>writer->SetFileName("sum.png");
>>
>>writer->Update();
>>
>>
>>----------
>>
>>
>>Note that it is a common mistake to save images with
>>intesities in the 8bit range as images of 16bits.
>>This usually happens when using PNG as file format.
>>The resulting image looks black when seen with a
>>viewer that doens't normalize the intensity levels.
>>
>>The ImageViewer application available in InsightApplications
>>performs a normalization of intensity levels. (you may want
>>to use this viewer...)
>>
>>
>>
>>Regards,
>>
>>
>>   Luis
>>
>>
>>
>>-----------------------
>>Anders Almås wrote:
>>
>>>Hi!
>>>I am new to ITK. I have a question about itkAddImageFilter
>>>
>>>I  try to add two binary images together but my result is a  black image.
>>>I have managed to subtract two images.. I thought mybe I got out of range
>>>when two pixles with intensity of 255 was added, but I  implemented also a
>>>rescale intensity image filter but the same result occured..
>>>
>>>Fo anyone have some suggestions?
>>>
>>>Regards
>>>
>>>Anders
>>>
>>>-------------------------------------------------------------------------------
>>>Navn:   Anders Almås
>>>E-post: andersal at stud . ntnu . no
>>>Tlf:    90550374
>>>-------------------------------------------------------------------------------
>>>