[Insight-users] Problem with itkAddImageFilter
Luis Ibanez
luis . ibanez at kitware . com
Thu, 30 Oct 2003 10:01:32 -0500
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
> -------------------------------------------------------------------------------
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
> ...............................................................................
>
> Anders Almås Min hjemmeside:
>
> 7230 Trondheim http://stud . ntnu . no/~andersal/
>
> ...............................................................................
>
>
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk . org
> http://www . itk . org/mailman/listinfo/insight-users
>