[vtkusers] How get pixel data in VTK?
yenanqu at scs.fsu.edu
yenanqu at scs.fsu.edu
Thu Apr 24 13:44:13 EDT 2008
I can be sure the image data is 3 component, but I don't know how to
get the type those component. the pngwriter doesn't need to be worried
about, this is my old method which I could get the image data from
png writer, and it did works very well. but now I want to directly get
the pixel data, so that I don't have to pass the data through pngwriter.
PS: the image on the render window is what I expect to see, even I
store it into a png file. it is not all black.
my render window is 560X560, and the ms in "nsigned long ms =
id->GetActualMemorySize();" is 1041.
Yenan
Quoting Mark Wyszomierski <markww at gmail.com>:
> You have to remember to reply to the vtk users board as well, don't direct
> the emails to just me.
>
> How big is your render window, you're only sampling the first 1041 / 3
> pixels there, and I wouldn't be surprised if they were all black. You should
> also verify that the image data is 3 component unsigned char. I would also
> make sure that your png actually contains something by just writing it to
> disk.
>
> Mark
>
>
> On Thu, Apr 24, 2008 at 1:15 PM, <yenanqu at scs.fsu.edu> wrote:
>
>>
>> Here is my code:
>> ======================================
>> renWin->Render();
>> vtkWindowToImageFilter * w2i = vtkWindowToImageFilter::New();
>> vtkPNGWriter * writer = vtkPNGWriter::New();
>> w2i->SetInput( renWin );
>> writer->SetInput( w2i->GetOutput() );
>> w2i->Update();
>> vtkImageData * id = w2i->GetOutput();
>> id->Update();
>> //int* siz = id->GetDimensions();
>> //unsigned long ms = id->GetActualMemorySize();
>> //int ms1 = id->GetScalarSize();
>> unsigned char* pPix;
>> pPix = (unsigned char*)id->GetScalarPointer();
>>
>> for(int ee=0;ee<1041;ee++){
>> int pp = pPix[ee];
>> cout<<" "<<pp;
>> }
>> ===============================================
>> The thing I can be sure is there is no problem with id (vtkImageData)
>>
>>
>> Yenan
>>
>>
>>
>> Quoting Mark Wyszomierski <markww at gmail.com>:
>>
>> Are you sure you actually set any of the RGB components in the first
>>> place?
>>> You could just be allocating the image array, all elements are set to
>>> zero,
>>> and you'll just get a zero for every element you access.
>>>
>>> Mark
>>>
>>> On Thu, Apr 24, 2008 at 12:49 PM, <yenanqu at scs.fsu.edu> wrote:
>>>
>>> when I do
>>>> "unsigned char *pVtkPix = (unsigned char *)pImgData->GetScalarPointer();"
>>>> it doesn't seem to get the scarlar pointer, I have already do all the
>>>> update thing before this, and I also could get dimensions from pImgData.
>>>> but
>>>> when I output all the RGB value with your method, they are all 0.
>>>> this stuff really kills me~~~
>>>>
>>>>
>>>> Yenan
>>>>
>>>>
>>>> Quoting Mark Wyszomierski <markww at gmail.com>:
>>>>
>>>> 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.
>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>> 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.
>>>>
>>>>
>>>>
>>> --
>>> 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.
>>
>>
>
> --
> 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.
More information about the vtkusers
mailing list