[vtkusers] How to change pixel color?

Mark Wyszomierski markww at gmail.com
Thu May 22 14:24:49 EDT 2008


Yeah that's tricky because converting your original greyscale data
into three component color data implies you're only going to be using
255 possible grey values, whereas your original grey data might be in
the 16 bit range etc. So, what are you going to do with a grey value
of say 3000? This problem occurs even when you're viewing a greyscale
image because you need to map the grey values into the range that the
monitor can display. I guess this is what window/leveling is for, so
you're determining some window/scale to remap all those really big
gray values for the user. Can anyone verify that?

This isn't a good recommendation, but it's something I hacked together
just to get a temporary visualization going. If your greyscale data is
being stored in unsigned shorts let's say, you can iterate over all
the pixel data and find the max value used. For the images I worked
with, this was rarely near the unsigned short max value, it was
usually 20,000 let's say. Then if I wanted to display green pixels in
the volume, I would use a lookup table and add points like 20001 =
(0,255,0), 20002 = (255,0,0) and so on. You're sure your greyscale
data never uses those values. Then you replace the voxels of interest
with those appropriate lookup table values. When you hand the volume +
LUT to VTK, you'll see the voxels in the colors you chose.

There are problems with doing that of course. One is that your LUT
will always have to be dynamically created which is kind of annoying.
You're also overwriting voxel values in the source volume, so you need
to keep a reference to a copy of the ones you overwrite if you want to
'remember' the original greyscale values. The list goes on. But it
works and maybe it can give you some ideas.

I'm sure other people have done this and they probably have better suggestions,

Mark


On 5/22/08, Romuald BERTRAND <beromuald at wanadoo.fr> wrote:
> Ok, pPix = (unsigned char*)id->GetScalarPointer(); works for me.
>
> But I have a problem : I display a grey image (1 component) and I want to
> change few pixels in green (for example), I don't know how can I do this.
> The grey image has 1 scalar component, and I need to transform its to 3
> components, and it takes a lot of time, and it's not very interactiv.
>
> Someone know can I do my task?
>
> Thanks a lot for answers,
>
> Romu
>
> PS : yenan, make sure you change just one component if you have a grey
> image, and change 3 components if you have a rgb image.
>
>
>
>
>> Message du 19/05/08 20:54
>> De : yenanqu at scs.fsu.edu
>> A : "Romuald BERTRAND"
>> Copie à : "Mark Wyszomierski" , vtkusers at vtk.org
>> Objet : Re: [vtkusers] How to change pixel color?
>>
>> No, I am still trying it. if you have other way to or could make it
>> work, please, please let me know.
>>
>> Yenan
>>
>> Quoting Romuald BERTRAND :
>>
>> > Hi,
>> >
>> > Thanks for your answers.
>> >
>> > I have tried but pPix = (unsigned char*)id->GetScalarPointer();
>> > doesn't work for me.
>> >
>> > when I change the components, nothing change, and after I have
>> > display the array and I have seen it is null.
>> > Know you why?
>> >
>> > Yenan: Have you arrived to manipulate it correctly?
>> >
>> > Thanks
>> >
>> >
>> >
>> >> Message du 16/05/08 21:35
>> >> De : "Mark Wyszomierski"
>> >> A : yenanqu at scs.fsu.edu
>> >> Copie à : "Romuald BERTRAND" , vtkusers at vtk.org
>> >> Objet : Re: [vtkusers] How to change pixel color?
>> >>
>> >> >>  pPix = (unsigned char*)id->GetScalarPointer();
>> >>
>> >> That should work, I've used it many times for instance in this project:
>> >>
>> >>
>> >> http://devsample.org/index.php?option=com_content&task=view&id=48&Itemid=27
>> >>
>> >> I show the value of the pixel that the mouse is over. Maybe there's
>> >> something else going on in your pipeline?
>> >>
>> >> Mark
>> >>
>> >>
>> >>
>> >> On 5/16/08, yenanqu at scs.fsu.edu  wrote:
>> >> >   How to get pointer from vtkImageData is the hardest thing,which I
>> >> > still can not make it.
>> >> >
>> >> > //id is vtkImageData
>> >> > int *uExtent = id->GetUpdateExtent();
>> >> > pPix = (unsigned char*)id->GetScalarPointer(uExtent[0], uExtent[2],
>> >> > uExtent[4]);
>> >> >
>> >> >   or
>> >> >
>> >> >   pPix = (unsigned char*)id->GetScalarPointer();
>> >> >
>> >> > the only method I could find out. It didn't work for me. try it to
>> >> > see
>> >> > if it works for you.
>> >> >
>> >> > Yenan
>> >> >
>> >> > Quoting Mark Wyszomierski :
>> >> >
>> >> >> Yeah once you get a pointer to the pixel data in vtkImageData you
>> >> >> can
>> >> >> manipulate it however you want. It's just an array of values.
>> >> >>
>> >> >> Mark
>> >> >>
>> >> >> On 5/16/08, yenanqu at scs.fsu.edu  wrote:
>> >> >>> Did you retrieve pixel data from vtkImageData seccessfully?
>> >> >>>
>> >> >>>
>> >> >>> Yenan
>> >> >>> Quoting Romuald BERTRAND :
>> >> >>>
>> >> >>>> Hi all,
>> >> >>>>
>> >> >>>> I have to display an image for my work. After, I have to change
>> >> >>>> the
>> >> >>>> color of several pixels, I don't know why. I have a vtkImageData,
>> >> >>>> and I have search some methods to set the scalars of the pixels
>> >> >>>> which are stored in, but I don't arrived.
>> >> >>>>
>> >> >>>> Someone could help me?
>> >> >>>>
>> >> >>>> Thanks for answers.
>> >> >>>>
>> >> >>>> Romuald
>> >> >>>>
>> >> >>>> --
>> >> >>>> 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 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.
>>
>>
>>
>



More information about the vtkusers mailing list