[Insight-users] how can I convert the image type
Zachary Pincus
zpincus at stanford.edu
Thu Jul 1 03:52:27 EDT 2004
Hello,
Displaying 16-bit (i.e. "unsigned short") greyscale files causes some
viewers trouble -- especially PNG files (which are more rarely seen in
the 16-bit variety.)
First, try adjusting the brightness/contrast in your viewer. It might
be that the useful values of your image are all in the 8-bit range, and
the viewer did not automatically scale the image properly. (Looking at
an image with pixels in the range 0-255 when the viewer is trying to
show some scaled version of all the values from 0-65535 generally
produces screen output that looks "black.")
Alternately, it might be that your PNG viewer just breaks totally on
16-bit files... this happens with some viewers. You could try saving
the output as a TIFF and using a program that's good at reading 16-bit
TIFFs (The Adobe Photoshop family is works, if you have access to it.
The ImageMagick "display" tool, if you've got a UNIX-ish system, is
also good.)
Finally, just try reading and writing the images as 8-bit for your
test. All viewers deal with 8-bit images fine. This would involve
changing the following:
> typedef unsigned short PixelType;
to
> typedef unsigned char PixelType;
Also, note that in general you do not have to explicitly set the
writer's IO type (e.g. the "pngIO") -- it is usually automatically
detected from the file name you set.
Zach Pincus
Department of Biochemistry and Program in Biomedical Informatics
Stanford University School of Medicine
On Jul 1, 2004, at 12:03 AM, Guorong Wu wrote:
> hello:
> I want to convert one type of image to another type, for example,
> I will convert RatLungSlice1.mha to RatLungSlice.png. I write a simple
> program as follows but it doesn't work. The output is all black. I
> guess it is wrong to simply link the imagefilereader and
> imagefilewriter without doing anything. Can you tell me what work I
> should do or which section I shuold refer to the document of
> ITKSoftwareGuide? Thanks.
>
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkImage.h"
> #include "itkPNGImageIO.h"
> main(int argc, char **argv)
> {
> typedef unsigned short PixelType;
> const unsigned int Dimension=2;
> typedef itk::Image<PixelType, Dimension> ImageType;
> typedef itk::ImageFileReader<ImageType> ReaderType;
> typedef itk::ImageFileWriter<ImageType> WriterType;
> typedef itk::PNGImageIO ImageIOType;
> ReaderType::Pointer reader=ReaderType::New();
> WriterType::Pointer writer=WriterType::New();
> ImageIOType::Pointer pngIO=ImageIOType::New();
> //const char *InputFilename=argv[1];
> //const char *OutputFilename=argv[2];
> reader->SetFileName("RatLungSlice1.mha);
> writer->SetFileName("RatLungSlice1.png");
> writer->SetInput(reader->GetOutput());
> writer->SetImageIO(pngIO);
> writer->Update();
> return 0;
>
> }
>
>
> Guorong Wu
> grwu at sjtu.edu.cn
> 2004-07-01
>
> =============================================================
> Guorong Wu
> The Department of Computer Science and Technology
> Shanghai Jiao Tong University
> 1954 Huashan RD
> Shanghai China
> 200030
> Tel: +86 21 3226 1236 , 6293 2089
> =============================================================
> <fox.gif>_______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
More information about the Insight-users
mailing list