[vtkusers] How to normalize gray level images by intensity?

David Doria daviddoria at gmail.com
Tue May 8 12:48:14 EDT 2012


On Tue, May 8, 2012 at 12:38 PM, Wenlong <scc.wwl at gmail.com> wrote:
> Dear all,
>
> I have a set of gray level human face images. I'd like to normalize them to
> 0-255 by intensity.
>
> Here is what I do.
>
> vtkBMPReader* imageReader = vtkImageReader::New();
> vtkBMPWriter* imageWriter = vtkImageWriter::New();
> vtkImageCast* imageCast = vtkImageCast::New();
> vtkImageShiftScale* imageScale = vtkImageScale::New();
> vtkImageNormalize* imageNormalize = vtkImageNormalize::New();
>
> imageReader->SetFileName("C:\\Users\\Wenlong\\Desktop\\image.bmp");
> imageReader->Update();
>
> imageNormalize->SetInput(imageReader->GetOutput());
> imageNormalize->Update();
>
> imageScale->SetInput(imageNormalize->GetOutput());
> imageScale->SetScale(255);
> imageScale->Update();
>
> imageCast->SetInput(imageScale->GetOutput());
> imageCast->SetOutputScalarTypeToUnsignedChar();
> imageCast->Update();
>
> imageWriter->SetFileName("C:\\Users\\Wenlong\\Desktop\\NormalizedImage.bmp");
> imageWriter->SetInput(imageCast->GetOutput());
> imageWriter->Update();
> imageWriter->Write();
> /////////////////////////////////////////////////////////////////
>
> However, the result image has the same black background as the input image.
> And it has a grey face that has the same shape as the face in the input
> image. But I cannot tell the eyes, nose and mouth etc.
>
> Is this because I set the scale wrong? Please help if you have any idea.
>
> Many thanks in advance. I look forward to hearing from you.
>
> Best wishes
> Wenlong

You have to first shift the range to that the bottom of the input
range is aligned with zero. Then you have to scale by the appropriate
scaling factor to stretch the range. Both are demonstrated here:
http://www.vtk.org/Wiki/VTK/Examples/Cxx/ImageProcessing/RescaleAnImage

David



More information about the vtkusers mailing list