Georg wrote:
> 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?
see also 'gdalinfo -stats' on raw data and 'r.info -r' on grass
maps.
where is rgb2his.c, I don't see it in grass 6.5
if that is a C module, ideally the 256 should be made a
module option which defaults to 256.
see attached patch x6.5, I'm not quite sure if the approach is
right though so haven't applied it.
Also, for a long time I have wanted to replace the quick
sexidecimal method with propper cone geometry math, but not
found the time. It doesn't seem too hard, and computers are
much faster these days. :)
> 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...).
from d.legend:
struct Range range;
struct FPRange fprange;
...
if (!fp) {
if (G_read_range(map_name, mapset, &range) == -1)
G_fatal_error(_("Range information for <%s> not available (run r.support)"),
map_name);
G_get_range_min_max(&range, &min_ind, &max_ind);
if (G_is_c_null_value(&min_ind))
G_fatal_error(_("Input map contains no data"));
.
.
.
else { /* is fp */
if (G_read_fp_range(map_name, mapset, &fprange) == -1)
G_fatal_error(_("Range information for <%s> not available"),
map_name);
G_get_fp_range_min_max(&fprange, &dmin, &dmax);
but the max value should be the channel's max, not the observed
max, so I think the module option is better.
as for dull greys, the grey255 color map is there to force min=0
max=255. If you want grey66535 just copy the 255 file and edit
to suit.
Hamish
[i_rgb_his_depth.diff]
Index: imagery/i.rgb.his/r2hmain.c
===================================================================
--- imagery/i.rgb.his/r2hmain.c (revision 39354)
+++ imagery/i.rgb.his/r2hmain.c (working copy)
@@ -33,9 +33,11 @@
struct Option *opt_hue, *opt_red;
struct Option *opt_inten, *opt_green;
struct Option *opt_sat, *opt_blue;
+ struct Option *opt_nlevels;
struct GModule *module;
int fd_input[3];
int fd_output[3];
+ int nlevels;
/* Initialize GIS engine */
G_gisinit(argv[0]);
@@ -72,9 +74,21 @@
opt_sat->key = "saturation_output";
opt_sat->description = _("Name for output raster map (saturation)");
+ opt_nlevels = G_define_option();
+ opt_nlevels->key = "n_levels";
+ opt_nlevels->type = TYPE_INTEGER;
+ opt_nlevels->required = NO;
+ opt_nlevels->answer = "255";
+ opt_nlevels->description = _("Number of possible levels in base data");
+
if (G_parser(argc, argv))
exit(EXIT_FAILURE);
+
+ nlevels = atoi(opt_nlevels->answer);
+ if (nlevels <= 0)
+ G_fatal_error(_("Invalid number of levels"));
+
/* get dimension of the image */
rows = G_window_rows();
cols = G_window_cols();
@@ -89,16 +103,16 @@
for (band = 0; band < 3; band++)
if (G_get_map_row(fd_input[band], rowbuffer[band], i) < 0)
- G_fatal_error(_("Unable to read raster map row %d"), i);
+ G_fatal_error(_("Unable to read raster map row %ld"), i);
/* process this row of the map */
- rgb2his(rowbuffer, cols);
+ rgb2his(rowbuffer, cols, nlevels);
/* write out the new row for each cell map */
for (band = 0; band < 3; band++)
if (G_put_raster_row(fd_output[band], rowbuffer[band], CELL_TYPE)
< 0)
- G_fatal_error(_("Failed writing raster map row %d"), i);
+ G_fatal_error(_("Failed writing raster map row %ld"), i);
}
closefiles(opt_hue->answer, opt_inten->answer, opt_sat->answer,
Index: imagery/i.rgb.his/rgb2his.c
===================================================================
--- imagery/i.rgb.his/rgb2his.c (revision 39354)
+++ imagery/i.rgb.his/rgb2his.c (working copy)
@@ -17,9 +17,10 @@
each band is processed and written out. CWU GIS Lab: DBS 8/90 */
#include <grass/gis.h>
+#include <grass/glocale.h>
#include "globals.h"
-void rgb2his(CELL * rowbuffer[3], int columns)
+void rgb2his(CELL * rowbuffer[3], int columns, int nlevels)
{
int sample; /* sample indicator */
double red; /* the red band output */
@@ -33,14 +34,17 @@
double intens; /* intensity */
double sat; /* saturation */
double hue = 0.0L; /* hue */
+ double nlevels_fp; /* expanded bitdepth (eg 255) */
+ nlevels_fp = nlevels * 1.0;
+
for (sample = 0; sample < columns; sample++) {
scaler = (double)rowbuffer[0][sample];
- scaler /= 255.0;
+ scaler /= nlevels_fp;
scaleg = (double)rowbuffer[1][sample];
- scaleg /= 255.0;
+ scaleg /= nlevels_fp;
scaleb = (double)rowbuffer[2][sample];
- scaleb /= 255.0;
+ scaleb /= nlevels_fp;
high = scaler;
if (scaleg > high)
@@ -64,8 +68,8 @@
/* hue = -1.0; */
hue = 0.0;
rowbuffer[0][sample] = (unsigned char)hue;
- rowbuffer[1][sample] = (unsigned char)(intens * 255.);
- rowbuffer[2][sample] = (unsigned char)(sat * 255.);
+ rowbuffer[1][sample] = (unsigned char)(intens * nlevels_fp);
+ rowbuffer[2][sample] = (unsigned char)(sat * nlevels_fp);
}
/*
else chromatic case
@@ -78,6 +82,7 @@
sat = (high-low)/(2 - (high-low));
*/
sat = (high - low) / (2 - high - low);
+
red = (high - scaler) / (high - low);
green = (high - scaleg) / (high - low);
blue = (high - scaleb) / (high - low);
@@ -108,9 +113,9 @@
/*
set the HIS output values
*/
- rowbuffer[0][sample] = (unsigned char)(255.0 * hue / 360.0 + 0.5);
- rowbuffer[1][sample] = (unsigned char)(intens * 255. + 0.5);
- rowbuffer[2][sample] = (unsigned char)(sat * 255. + 0.5);
+ rowbuffer[0][sample] = (unsigned char)(nlevels_fp * hue / 360.0 + 0.5);
+ rowbuffer[1][sample] = (unsigned char)(intens * nlevels_fp + 0.5);
+ rowbuffer[2][sample] = (unsigned char)(sat * nlevels_fp + 0.5);
}
}
}
Index: imagery/i.rgb.his/description.html
===================================================================
--- imagery/i.rgb.his/description.html (revision 39354)
+++ imagery/i.rgb.his/description.html (working copy)
@@ -24,4 +24,5 @@
with acknowledgements to Ali Vali, Space Research
Center, for the core routine.
-<p><i>Last changed: $Date$</i>
+<p>
+<i>Last changed: $Date$</i>
Index: imagery/i.rgb.his/globals.h
===================================================================
--- imagery/i.rgb.his/globals.h (revision 39354)
+++ imagery/i.rgb.his/globals.h (working copy)
@@ -8,6 +8,6 @@
void openfiles(char *, char *, char *, char *, char *, char *,
int[3], int[3], CELL *[3]);
/* rgb2his.c */
-void rgb2his(CELL *[3], int);
+void rgb2his(CELL *[3], int, int);
#endif /* __GLOBALS_H__ */
_______________________________________________
grass-dev mailing list
[hidden email]
http://lists.osgeo.org/mailman/listinfo/grass-dev