[vtkusers] invert the color of pixels

Cory Quammen cquammen at cs.unc.edu
Mon Aug 27 19:07:49 EDT 2007


Shang,

Try a vtkImageShiftScale object to apply the transformation

255 - px = (px - 255.0) * -1.0

to each pixel where px is the initial pixel value. It will probably go
something like:

vtkImageShiftScale inverter = vtkImageShiftScale::New();
inverter->SetInput(myImage);
inverter->SetOutputScalarTypeToUnsignedChar();
inverter->SetShift(-255.0);
inverter->SetScale(-1.0);
...

This will subtract 255 from all your values and then "mirror" them
around 0. You may want to set the shift value to something like -255.1
just to make sure the "mirrored" numbers will clamp down to the
appropriate unsigned char.

Cory

On 8/27/07, Shang Mu <smu.email at gmail.com> wrote:
> I'm trying to invert the color of an image of type unsigned char, i.e.
> black to white and white to black. To my suprise i could not find a
> vtk filter that does this job. Does vtk have such a filter somewhere?
>
> I've went through the vtk filters several times and could not find
> such a filter. The "invert" in vtkImageMathematics returns the
> reciprocal of each pixel, not in the sense of image color.
>
> Thanks!
>
> Shang
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>


-- 
Cory Quammen
Department of Computer Science
University of North Carolina at Chapel Hill
http://www.cs.unc.edu/~cquammen



More information about the vtkusers mailing list