Hi,
after some problems converting 16bit quickbird images from rgb to ihs and vice versa (see user list), i took a look at the source code and discovered that pixel values are normalised by dividing by 255.
Naturally this leads to wrong values when using data with more than 8bit.
rgb2his.c
37 for (sample = 0; sample < columns; sample++) {
38 scaler = (double)rowbuffer[0][sample];
39 scaler /= 255.0;
40 scaleg = (double)rowbuffer[1][sample];
41 scaleg /= 255.0;
42 scaleb = (double)rowbuffer[2][sample];
43 scaleb /= 255.0;
this could be corrected by replacing the constant 255 with a variable according to the encoding of the image.
i'm not quite shure how to do this (only did some scripting so far) - can somebody help?
bests,
Georg
Georg Kaspar wrote:
this could be corrected by replacing the constant 255 with a variable according to the encoding of the image.
i'm not quite shure how to do this (only did some scripting so far) - can somebody help?
to be more precise: how can i read-out the encoding of a raster file (or the maximum value) in c? I already took a look at the programmer's manual but didn't find what i'm looking for (i'm accustomed to javadoc...).
Georg Kaspar wrote:
> this could be corrected by replacing the constant 255 with a variable
> according to the encoding of the image.
> i'm not quite shure how to do this (only did some scripting so far) -
> can somebody help?
to be more precise: how can i read-out the encoding of a raster file (or
the maximum value) in c? I already took a look at the programmer's
manual but didn't find what i'm looking for (i'm accustomed to javadoc...).
You can read the minimum and maximum values using G_read_range() or
G_read_fp_range() (these have been renamed from G_* to Rast_* in 7.0).
However, that tells you the minimum and maximum values which actually
occur, not the nominal 0 and 1 values which should be used for
colour-space conversion.
A more suitable approach is to use the colour tables, e.g. using
G_get_raster_row_colors() rather than G_get_raster_row(). This is the
mechanism used by r.composite.
Then, the user can apply grey-scale colour tables which match the
nominal range of the data (e.g. the predefined "grey255" colour table
maps 0 to black and 255 to white, while "grey1.0" maps 0 to black and
1.0 to white).
--
Glynn Clements <glynn@gclements.plus.com>