next up previous contents
Next: Other tips and tricks Up: Colour images Previous: Colour images   Contents

Hugh's examples

I HAVEN'T UPDATED HUGH'S PART OF THIS - I HAVE NEVER OPERATED ON COLOUR IMAGES LIKE THIS MYSELF - I HAVE LEFT IT IN FOR REFERENCE THOUGH.

A colour image is really three images, a red one, a green one and a blue one. If you want to do image processing things to a colour image, smoothing for example, then you have to apply your algorithm to the three colours separately. As we have seen, images are stored on computers in various file formats. Just like computer screens, some image formats (tiff, jpeg, ppm, some .png) are 24 bit true colour and store a red, a green and a blue image. Others (.gif, some .png) store an 8-bit image and a colour table to say which value in the image should be what colour.

Here is how to read in and display a pseudocolour png image

IDL> pg=read_png('/home/hcp/wrk/idlcourse/colourpeng.png',r,g,b)
%%IDL> pg=rotate(pg,7) ; wont be needed after upgrade
IDL> tvlct,r,g,b
IDL> showimage,pg,win=2

Remember that on 24-bit displays, you will need to do:

IDL> device,true_color=24,decomposed=0,retain=2
for this to work.

The ppm file format stores 24 bit images. Here is how to read in a ppm file, we use the help command to see what the resulting array is like:

 
IDL> read_ppm,'/home/hcp/wrk/idlcourse/ferry.ppm',ferry
IDL> help,ferry
FERRY           BYTE      = Array[3, 593, 413]
This is an 593 X 413 pixel image containing three 'layers', red, green and blue.

We can do this to see the individual layers:

IDL> loadct,0
IDL> showimage,reform(ferry[2,*,*]),win=2
IDL> showimage,reform(ferry[1,*,*]),win=1
IDL> showimage,reform(ferry[0,*,*]),win=0

Note that the boat in the centre foreground looks dark in the red and green images but light in the blue image. To display this as a colour image on a 24-bit terminal, you just need to use the /true keyword with tv:

IDL> tv,ferry,/true


next up previous contents
Next: Other tips and tricks Up: Colour images Previous: Colour images   Contents
lecjm 2008-11-06