[vtkusers] How get pixel data in VTK?

Mark Wyszomierski markww at gmail.com
Thu Apr 24 01:34:27 EDT 2008


I think the RGB pixel data is usually allocated like:

    RGBRGBRGB etc....

so you have numPixels * 3 actual elements in your image data array.

You get a pixel pointer as usual and cast it to (unsigned char*):

// Get a pointer to the actual pixel data.
unsigned char *pVtkPix = (unsigned char *)pImgData->GetScalarPointer();

// These are the r,g and b values for the first pixel:
int rr  = pVtkPix[0];
int gg = pVtkPix[1];
int bb = pVtkPix[2];

// For the second pixel:
rr  = pVtkPix[3];
gg = pVtkPix[4];
bb = pVtkPix[5];

and so on. Make sure you don't have RGBA data, if you do, then you just have
an extra index per pixel which is the alpha component. Let me know if that
helps,

Mark


On Wed, Apr 23, 2008 at 7:08 PM, <yenanqu at scs.fsu.edu> wrote:

> Hi, Mark, I did have the data that is three component. Your example only
> shows how to get pixel data that is one component which I never got in my
> code before. Do you have any idea how to retrieve this three component data?
> I have try bunch of methods, but none of them is working. any help will be
> greatly appreciated.
>
> Yenan
>
> Quoting Mark Wyszomierski <markww at gmail.com>:
>
>  Hi,
> >
> > It's definitely possible to get the scalar value from a vtkImageData
> > object. You need to know the type of data your object is stored in
> > though, for example you'll have difficulty getting the scalar value if
> > your data is three component RGB and you're trying to get a single
> > pixel scalar pixel value.
> >
> > I have an example of getting the pixel value that the mouse moves over
> > in an image here:
> >
> >
> > http://devsample.org/index.php?option=com_content&task=view&id=48&Itemid=27
> >
> > which may help.
> >
> > Mark
> >
> >
> > On Thu, Mar 27, 2008 at 1:37 PM,  <yenanqu at scs.fsu.edu> wrote:
> >
> > > Hi, all,
> > > I found bunch of the VTK methods to retrieve pixel data from vtk
> > > object, such as
> > > GetPixelData, GetRGBACharPixelData, etc, but none of them is working,
> > > Does anyone know how to get pixel data from VTK object? Thanks in
> > > advance.
> > >
> > > Yenan
> > >
> > > ----------------------------------------------------------------
> > > This message was sent using IMP, the Internet Messaging Program.
> > >
> > >
> > > --
> > > This message has been scanned for viruses and
> > > dangerous content by MailScanner, and is
> > > believed to be clean.
> > >
> > > _______________________________________________
> > > 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
> > >
> > >
> > --
> > This message has been scanned for viruses and
> > dangerous content by MailScanner, and is
> > believed to be clean.
> >
> >
> >
>
>
> ----------------------------------------------------------------
> This message was sent using IMP, the Internet Messaging Program.
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is
> believed to be clean.
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20080424/8cd65a6b/attachment.htm>


More information about the vtkusers mailing list