View on GitHub

IRAF Community Distribution

IRAF maintained by the community

Home | Installation | Packages | X11IRAF | PyRAF | Forum

XImtool display transformations

Mike Fitzpatrick wrote on Sep 09, 1998

>I'm using saotng to try to find out what are the optimal minimum and 
>maximum intensities for image display. From the scale panel I can see what
>the current limits are, but I would like to know the new values that would
>give the same results that I get when I move the mouse to adjust contrast
>and bias. In other words:  looking at the control panel I can see how the
>contrast and the bias change as I move the mouse and once I get the the
>right display I would like to know which values for z1 and z2 would give
>the same result straight away. Is there any way of finding the new pair z1
>and z2 knowing the original z1 and z2 and the values of the contrast and
>bias?
>    What I want is to give the right setting to IGI, but the only com-
>mands I know are "zrange" and "saocmap". The last one should do but I 
>don't know how to write the text file with the colormap using the 
>brightness/contrast values from ximtool or saotng.

	As I understand the question, given an image displayed with a
certain z1/z2 and scaled in the server, what is the equivalent image that
displays the same way using the default contrast/brightness scaling values
in the server...right?  The short answer is that this can't be done, at
least not easily.
	The reason is that when rendering an image there are two
transformations that occur:  The display client first computes an optimal
z1/z2 value and maps this to the 200 or so display values to be used,
image pixels outside the z1/z2 range map to either extreme.  These 200
values are the indices into the colormap used to render the image and are
what get shipped to the display server.
	The second transformation occurs in the display server where the
initial colormap cells are mapped to a new colormap based on the contrast
and bias settings.   The thing to remember is that when doing the
brightness stretching you're not remapping the image pixels to the display
pixels, you're mapping the default colormap to some new colormap that gets
updated on the screen.  By default the z1 value maps to the first colormap
value, the z2 value maps to the last colormap value, and the rest scale
linearly in between.  When you move the mouse and adjust the
brightness/contrast values you rescale the colormap (let's call it 'cmap')
so that the 200 or so cells map to a new colormap in which e.g. cells 1-50
are cmap[0], cells 150-200 are cmap[200] and cells 51-149 are a linear
scaling of all 200 elements to the 100 cells in the new colormap.  It is
this new colormap that is loaded and the result is a higher contrast image
on the screen.  By rescaling the colormap (at most 256 values) rather than
the image mapping (possibly many Mb pixels, and the server doesn't have
access to the pixels anyway) the display can be updated in real time.  You
could possibly compute the z1/z2 that corresponds to a given server
contrast/bias setting, but when redisplaying those values with the default
200 colormap cells you would need a different set of contrast/bias and in
most cases it couldn't be done without a specialized colormap.
	I'll append a small script task that computes an SAOimage colormap
for a given brightness/contrast setting which you should be able to feed
into an saocmap igi call.

Cheers,
-Mike

--------------------------------------------------------------------------
    #{ MKMAP - Make an SAOimage greyscale colormap from a given
    #          brightness/contrast setting.

    procedure mkmap ()
    real brightness = 0.5          	{ prompt = "Brightness: " }
    real contrast   = 1.0          	{ prompt = "Contrast: " }
    begin
        int     index
        real    brt, con, nc

        brt = bright
        con = contrast
        nc = 199                	# default for saoimage

        printf ("PSEUDOCOLOR\n")
        for (j=0; j < 3; j=j+1) {
            if (j == 0) print ("RED:")
            else if (j == 1) print ("GREEN:")
            else if (j == 2) print ("BLUE:")
            for (i=1; i <= nc; i=i+1) {
                y = (( (real(i) / nc) - brt) * con + 0.5 ) * nc
                index = min(max(y,0),nc)
                printf ("(%6.3f,%6.3f)\n", real(i)/nc, real(index)/nc)
            }
        }
    end

Last post on Sep 09, 1998