[Insight-users] Write data in PNG Format

Luis Ibanez luis . ibanez at kitware . com
Mon, 08 Jul 2002 01:47:56 -0400


Hi Samuel,

I'm assuming that you succeded to write the images but they don't
look right:  is this what you observe ?

If that's the case, one possible cause is that the PNG writers require
images to be of PixelType "unsigned short". Your images are probably
of PixelType "float", so you may want to rescale the scale of gray levels=
,
in particular for the gradient image since it should have positive and
negative values that cannot be represented by "unsigned short".

You can use the filter :

http://public.kitware.com/Insight/Doxygen/html/classitk_1_1RescaleIntensi=
tyImageFilter.html

in order to map: =20

{min,max } of the float image to { 0, 65535 } (unsigned short) prior to=20
saving the image.

and use the Calculator:

http://public.kitware.com/Insight/Doxygen/html/classitk_1_1MinimumMaximum=
ImageCalculator.html

to get the min and max of the gray levels in the float image



   Luis


=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D

Samuel Rodr=EDguez Bescos wrote:

> Hello every body,
>
> =20
>
> I'm developing and watershed segmentation example that can read PNG=20
> Images and write the results in PNG format. I have a problems with=20
> writing the smoothed image, the gradinet magnitude Image and the final =

> Segmented image. I want to write them to disk in PNG format.
>
> =20
>
> I'm using the next code for witing:
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
>           (...)
>
>           typedef   float                             PixelType;
>
>           (...)
>
>     typedef   itk::Image< PixelType, 2 >      ImageType;
>
>     typedef   itk::PNGImageIO         IoType;
>
>     =20
>
>     (...)
>
>     =20
>
>     typedef itk::ImageFileWriter<ImageType>      ImageWriterType;
>
>     IoType::Pointer             m_Io;
>
>     CurvatureAnisotropicDiffusionImageFilterType::Pointer    m_Smoothed=
;
>
>     ImageWriterType::Pointer           m_SmoothedWriter;
>
>     =20
>
>     (........Executing the algorithm....)
>
>     =20
>
>        m_SmoothedWriter->SetInput(m_Smoothed->GetOutput());
>        m_SmoothedWriter->SetFileName( filename );
>        m_SmoothedWriter->SetImageIO(m_Io);
>        m_SmoothedWriter->Write();
>
> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
>
> =20
>
> Can anyboby tell me how can I do it or what is the problem.
>
> =20
>
> Thanks,
>
> =20
>
> Samuel
>