[vtkusers] invert the color of pixels

Cory Quammen cquammen at cs.unc.edu
Tue Aug 28 06:49:38 EDT 2007


Shang,

vtkImageData::GetScalarPointer() returns a pointer to the scalar data
in your image so that you can access the data as you would a typical C
array. You'll have to cast the void pointer it returns to your data
type.

Cory

On 8/27/07, Shang Mu <smu.email at gmail.com> wrote:
> Thanks for the suggestion, Cory.
>
> But I really don't like that approach. Instead of just a single operation of
> getting the complement of an number, I have to use float point
> multiplication....
>
> Is there a canonical way to access the raw image data in vtk? I'd really
> like to know that if there is one.
>
> Shang
>
>
> ----- Original Message -----
> From: "Cory Quammen" <cquammen at cs.unc.edu>
> To: "Shang Mu" <smu.email at gmail.com>
> Cc: <vtkusers at vtk.org>
> Sent: Monday, August 27, 2007 7:07 PM
> Subject: Re: [vtkusers] invert the color of pixels
>
>
> > 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
>
>


-- 
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