comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Re: gamma correction
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: gamma correction [message #31245 is a reply to message #31244] Wed, 26 June 2002 15:20 Go to previous messageGo to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
Dick Jackson (dick@d-jackson.com) writes:

> Usually, colortables are used with 2D (nx, ny) images where the byte values are
> looked up in the RGB colortables, while 3D images (3, nx, ny) have their byte
> values used exactly as given.
>
> Less common, but equally valid, is to display a 3D image where each plane's byte
> values are looked up in the colortables. Gamma_CT changes the colortables so
> that an image that uses them appears to have had its 'gamma' changed.
>
> Quick examples:
>
> =====
>
> COMMON Colors ; allow access to color tables
> Device, Decomposed=0 ; set to use color tables for lookup
>
> file = FilePath('rose.jpg', SubDir=['examples', 'data'])
> Read_JPEG, file, image
>
> TV,/True,image ; show original image
>
> Gamma_CT,0.5 ; set gamma 0.5
> Plot,[r_curr,g_curr,b_curr] ; show the colortables (crudely!)
> TV,/True,image ; show image
>
> Gamma_CT,2.0 ; set gamma 2.0
> Plot,[r_curr,g_curr,b_curr] ; show the colortables
> TV,/True,image ; show image
>
> END
>
> =====
>
> No need to recompute the image array, it just passes through the transforming
> colortables on its way to the display. Hope this helps!

Well, it does on PCs and Macs. I'm not sure it
does on UNIX machines, at least not in all versions
of IDL. :-)

But here is an alternative point of view. Normally, we
think of gamma as affecting the "brightness" of an
image. Dick's example has the effect of actually
changing the colors in the image, which may lead
us away from the gamma idea.

What if we convert the RGB image to HSV color space and
only apply the gamma to the brightness (value) part of the
image?

Here is a program that demonstrates what I mean. How do these
ideas square with the "right" way in Infarct (or whatever
the hell it was called) Ben?

Cheers,

David

;*********************************************************** ***
PRO Example, gamma

IF N_Elements(gamma) EQ 0 THEN gamma = 2.0

; Get 24-bit JPEG image.

file = FilePath('rose.jpg', SubDir=['examples', 'data'])
Read_JPEG, file, image

; Show original image.

DEVICE, Decomposed=1
Window, XSize=227*2, YSize=149, /Free, $
Title='Gamma of ' + StrTrim(gamma, 2)
TV, image, True=1

; Convert from RGB to HSV color space.

r = Reform(image[0,*,*])
g = Reform(image[1,*,*])
b = Reform(image[2,*,*])
Color_Convert, r, g, b, h, s, v, /RGB_HSV

; Perform gamma correction on the "brightness".

correction = long(256*((findgen(256)/256)^gamma))
new_v = correction[BytScl(v)] / 255.0

; Convert back to RGB space.

Color_Convert, h, s, new_v, rr, gg, bb, /HSV_RGB

; Create the gamma corrected image and display it.

g_image = image
g_image[0,*,*] = rr
g_image[1,*,*] = gg
g_image[2,*,*] = bb
TV, g_image, True=1, 227, 0

END
;*********************************************************** ***

--
David W. Fanning, Ph.D.
Fanning Software Consulting, Inc.
Phone: 970-221-0438, E-mail: david@dfanning.com
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Toll-Free IDL Book Orders: 1-888-461-0155
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: Delvar?
Next Topic: Delvar?

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Sun Oct 12 02:14:53 PDT 2025

Total time taken to generate the page: 1.92614 seconds