Angus McMorland | 5 Sep 22:39

[mv2] Just display image with its LUT

Hi mv devs / vtk gurus,

I'm trying to add an image to an mv2 scene, including its colourmap. A while back, Prabhu sent me this script to do that _and_ warp the image on to some arbitrary bump map, but I can't work out which bits of this are needed to just display a flat image, with its colours. Can someone point me in the correct direction please.

def render_img():
    r = tvtk.JPEGReader(file_name=img.jpg')
    r.update()
    img = r.output
    depth = np.asarray(Image.open('other_img.png'))
    scalar = np.ravel(depth)
    # print scalar.shape
    da = tvtk.DoubleArray()
    da.name = 'bump'
    da.from_array(scalar)
    img.point_data.add_array(da)
    pd = convert_to_poly_data(img)
    ws = tvtk.WarpScalar()
    ws.input = pd
    ws.set_input_array_to_process(0, 0, 0, 0, 'bump')
    ws.scale_factor = 0.2
    ws.update()
    o = ws.output
    d = VTKDataSource(data=o)
    s0 = Surface()
    d.add_child(s0)
    fig = mlab.figure()
    fig.add_child(d)

An alternative solution would be if I could do mlab.imshow on a 2D array and then assign it an LUT in the module manager, but that doesn't seem to be working. Is that expected?

Many thanks, as always,

Angus.
--
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh
_______________________________________________
Enthought-dev mailing list
Enthought-dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev

Re: [mv2] Just display image with its LUT

Angus McMorland wrote:
> Hi mv devs / vtk gurus,
> 
> I'm trying to add an image to an mv2 scene, including its colourmap. A 
> while back, Prabhu sent me this script to do that _and_ warp the image 
> on to some arbitrary bump map, but I can't work out which bits of this 
> are needed to just display a flat image, with its colours. Can someone 
> point me in the correct direction please.
> 
>     ws.scale_factor = 0.2

If you set that to 0 you'll get a flat image at the expense of one more 
filter in the pipeline.  However, what you want to do is really not 
clear to me.  If you have only one flat image to show then why do you 
need the second array at all??  Can't you just view the other_img.png??

> An alternative solution would be if I could do mlab.imshow on a 2D array 
> and then assign it an LUT in the module manager, but that doesn't seem 
> to be working. Is that expected?

Yes, that will not work.  The LUT just generates colors from scalars.

cheers,
prabhu
Angus McMorland | 8 Sep 17:09

Re: [mv2] Just display image with its LUT



2008/9/6 Prabhu Ramachandran <prabhu-F7jaCKusRBxE2icvEvkEJw@public.gmane.org>
Angus McMorland wrote:
> Hi mv devs / vtk gurus,
>
> I'm trying to add an image to an mv2 scene, including its colourmap. A
> while back, Prabhu sent me this script to do that _and_ warp the image
> on to some arbitrary bump map, but I can't work out which bits of this
> are needed to just display a flat image, with its colours. Can someone
> point me in the correct direction please.
>
>     ws.scale_factor = 0.2

Doh - yes, of course. I can see easily, now you point it out, that that should work.
 
If you have only one flat image to show then why do you
need the second array at all??  Can't you just view the other_img.png??

Sorry for not being clear: I only have one image - it's just that I don't know how to view an image with its colour information (in RGB channels) in mv2. I don't just want to use any old image viewer, as I'm trying to generate a 'stack' of colour images, like in the attached example, which would look better in colour..

> An alternative solution would be if I could do mlab.imshow on a 2D array
> and then assign it an LUT in the module manager, but that doesn't seem
> to be working. Is that expected?

Yes, that will not work.  The LUT just generates colors from scalars.

Is not an image just a 2D array of scalars that I could use to assign colours? I understand that this way I would get different colours to the ones in the original image, but that would be okay, since you've got such a good range of LUTs available. I've just bought one of the VTK books, so I should gradually become more independent on these things, but in the meantime a further explanation would be helpful. In the end today, I hacked it by switching on filled contours, using 256 of them with the range from 0 to 255, and then picking the LUT, in the module manager, that I wanted. It seems this should be easier.


cheers,
prabhu

_______________________________________________
Enthought-dev mailing list
Enthought-dev-oRDGkvazHdacsI7C1d+pp9BPR1lH4CV8@public.gmane.org
https://mail.enthought.com/mailman/listinfo/enthought-dev




--
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh
_______________________________________________
Enthought-dev mailing list
Enthought-dev@...
https://mail.enthought.com/mailman/listinfo/enthought-dev
Prabhu Ramachandran | 17 Sep 08:29

Re: [mv2] Just display image with its LUT

Angus McMorland wrote:
>     If you have only one flat image to show then why do you
>     need the second array at all??  Can't you just view the other_img.png??
> 
> Sorry for not being clear: I only have one image - it's just that I 

And sorry for being slow in my response.  I got sucked into the 
scripting feature I just added and it consumed most of my time.

> don't know how to view an image with its colour information (in RGB 
> channels) in mv2. I don't just want to use any old image viewer, as I'm 
> trying to generate a 'stack' of colour images, like in the attached 
> example, which would look better in colour..

If the scalar data type of your scalar array is unsigned char then it is 
treated as a color.  If you want it to be treated as a scalar you can 
do, for example with the surface module:

  surface.actor.mapper.color_mode = 'map_scalars'

Then it will use the lut you pick to map the scalars.

> Is not an image just a 2D array of scalars that I could use to assign 
> colours? I understand that this way I would get different colours to the 

True but with the exception above.

> ones in the original image, but that would be okay, since you've got 
> such a good range of LUTs available. I've just bought one of the VTK 
> books, so I should gradually become more independent on these things, 
> but in the meantime a further explanation would be helpful. In the end 
> today, I hacked it by switching on filled contours, using 256 of them 
> with the range from 0 to 255, and then picking the LUT, in the module 
> manager, that I wanted. It seems this should be easier.

That will work but will cost you the contouring etc.  The above should 
also work fine.  Use what works best for you.

cheers,
prabhu

Gmane