[Insight-users] output of filter, image filled with zeros
Luis Ibanez
luis.ibanez@kitware.com
Fri, 29 Nov 2002 13:20:13 -0500
Hi Ghassan,
Your code looks fine.
The problem maybe on the image type itself.
The dynamic range may not be representing the
gradient correctly.
I would suggest you to define the
GradientMagnitudeImageFilter as having input
image of type <unsigned short> and output image
of type <float>. Then use an RescaleIntensity
image filter to scale the levels of the image
The RescaleIntensity filter can be defined with
input image <float> and output image <unsigned short>
http://www.itk.org/Insight/Doxygen/html/classitk_1_1RescaleIntensityImageFilter.html
Finally pass the output of the IntensityRescale
filter to the reader.
Note that you have to provide the RescaleIntesity
filter with the min and max values that you want
on the gray levels of the output image.
Use : SetOuputMinimun() and SetOutputMaximum()
Please let us know if you find any problems,
Thanks
Luis
=============================================
Ghassan Hamarneh wrote:
> Hello,
>
> I am trying to read a 3d image, perform simple filtering, and write the output
> to file. I able to read the image (mhd+raw) and write it directly to a new file
> without problems (writer->SetInput(reader->GetOutput()); //bypass filter).
> However, if I include the filter "itkGradientMagnitudeImageFilter" into the
> pipeline the saved image of the correct size and type but is all zeros . Can
> you spot the problem in my code? My appologies if this turns out to be very
> trivial, I am an ITK beginner.
>
> /Thank you.
> Ghassan
>
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkGradientMagnitudeImageFilter.h"
> #include "itkRawImageWriter.h"
>
> int main( int argc, char **argv){
> typedef itk::Image <unsigned short, 3> ImageType;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::RawImageWriter<ImageType> WriterType;
> typedef itk::GradientMagnitudeImageFilter<ImageType,ImageType> FilterType;
>
> ReaderType::Pointer reader = ReaderType::New();
> FilterType::Pointer filter = FilterType::New();
> WriterType::Pointer writer = WriterType::New();
>
> reader->SetFileName(argv[1]);
>
> filter->SetInput(reader->GetOutput());
> filter->Update();
> writer->SetInput(filter->GetOutput());
>
> //writer->SetInput(reader->GetOutput()); //bypass filter
>
> writer->SetFileName(argv[2]);
> writer->SetFileTypeToBinary();
> writer->Write();
> return 0;
> }
>
>
>
>
>
> ______________________________________________________________________
> Post your free ad now! http://personals.yahoo.ca
> _______________________________________________
> Insight-users mailing list
> Insight-users@public.kitware.com
> http://public.kitware.com/mailman/listinfo/insight-users
>
>