In its current form, plimage automatically scales the plotted colors
to take advantage of as much dynamic range in the color scale 1 as
possible - the minimum value in the given image corresponds to a color
of 0.0 and the maximum value in the image corresponds to a color of
1.0.
The attached patch adds two extra parameters to plimage to allow a
user to set this range on their own. Image values of valuemin or less
will now map to color 0.0 and image values of valuemax or greater will
map to color 1.0. Values between valuemin and valuemax will similarly
map to colors between 0.0 and 1.0, in the same way plimage currently
handles this.
The reason for this change is to allow multiple plots to be made with
varying data sets, while maintaining directly comparable color scales
between plots. The current implementation does not allow this for
data sets with different value ranges without manually setting at
least one pixel to a fixed minimum value and another to a fixed
maximum value in each image.
This patch affects include/plplot.h and src/plimage.c and should apply
cleanly against the current PLplot Subversion head. I have not made
any adjustments to any of the included language bindings as I want to
find out if this is an acceptable API change, if I should make this in
to a new function instead. I think it is a worthwhile adjustment to
plimage, particularly given that it is an undocumented function,
except for the code and an example.
Please let me know your thoughts and/or questions about this.
Thanks,
Hez
--
Hezekiah M. Carty
Graduate Research Assistant
University of Maryland
Department of Atmospheric and Oceanic Science
diff --git a/include/plplot.h b/include/plplot.h
index c6390d2..0edd1fa 100644
--- a/include/plplot.h
+++ b/include/plplot.h
@@ -1450,9 +1450,10 @@ c_plstripd(PLINT id);
/* plots a 2d image (or a matrix too large for plshade() ) */
PLDLLIMPEXP void
-plimage( PLFLT **data, PLINT nx, PLINT ny,
- PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
- PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax);
+plimage(PLFLT **idata, PLINT nx, PLINT ny,
+ PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
+ PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax,
+ PLFLT valuemin, PLFLT valuemax);
/* Set up a new line style */
diff --git a/src/plimage.c b/src/plimage.c
index 7bbd8ca..f51099f 100644
--- a/src/plimage.c
+++ b/src/plimage.c
@@ -157,18 +157,36 @@ grimage(short *x, short *y, unsigned short *z, PLINT nx, PLINT ny)
* plots only the window of points whose(x,y)'s fall
* inside the [Dxmin->Dxmax]X[Dymin->Dymax] window
*
+ * valuemin, valuemax:
+ * The minimum and maximum values to use for value -> color
+ * mappings. A value in idata of valuemin or less will have
+ * color 0.0 and a value in idata of valuemax or greater will
+ * have color 1.0. Values between valuemin and valuemax will
+ * map linearly to to the colors between 0.0 and 1.0.
+ * If you do not want to display values outside of the
+ * (valuemin -> valuemax) range, then set zmin = valuemin and
+ * zmax = valuemax.
+ * This allows for multiple plots to use the same color scale
+ * with a consistent value -> color mapping, regardless of the
+ * image content.
+ *
\*-------------------------------------------------------------------------*/
void
plimage(PLFLT **idata, PLINT nx, PLINT ny,
- PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
- PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax)
+ PLFLT xmin, PLFLT xmax, PLFLT ymin, PLFLT ymax, PLFLT zmin, PLFLT zmax,
+ PLFLT Dxmin, PLFLT Dxmax, PLFLT Dymin, PLFLT Dymax,
+ PLFLT valuemin, PLFLT valuemax)
{
PLINT nnx, nny, ix, iy, ixx, iyy, xm, ym;
PLFLT dx, dy;
+ // Zf holds transformed image pixel values
+ // szmin and szmax are zmin and zmax scaled to unsigned short values
unsigned short *Zf, szmin, szmax;
short *Xf, *Yf;
- PLFLT lzmin, lzmax, tz;
+ // This is used when looping through the image array, checking to
+ // make sure the values are within an acceptable range.
+ PLFLT datum;
if (plsc->level < 3) {
plabort("plimage: window must be set up first");
@@ -181,7 +199,7 @@ plimage(PLFLT **idata, PLINT nx, PLINT ny,
}
if (Dxmin < xmin || Dxmax > xmax || Dymin < ymin || Dymax > ymax){
- plabort("plimage: Dxmin or Dxmax or Dymin or Dymax not compatible with xminor xmax or ymin or ymax.");
+ plabort("plimage: Dxmin or Dxmax or Dymin or Dymax not compatible with xmin or xmax or ymin or ymax.");
return;
}
@@ -196,38 +214,41 @@ plimage(PLFLT **idata, PLINT nx, PLINT ny,
}
xm = floor((Dxmin-xmin)/dx); ym = floor((Dymin-ymin)/dy);
- lzmin = lzmax = idata[xm][ym];
-
- for (ix=xm; ix<xm+nnx; ix++) {
- for (iy=ym; iy<ym+nny; iy++) {
- tz = idata[ix][iy];
- if (lzmax < tz)
- lzmax = tz;
- if (lzmin > tz)
- lzmin = tz;
- }
- }
+ // Go through the image values and scale them to fit in an
+ // unsigned short range.
+ // Any values greater than valuemax are set to valuemax,
+ // and values less than valuemin are set to valuemin.
ixx=-1;
for (ix=xm; ix<xm+nnx; ix++) {
ixx++; iyy=0;
- for (iy=ym; iy<ym+nny; iy++)
- Zf[ixx*nny+iyy++] = (idata[ix][iy] - lzmin)/(lzmax-lzmin)*USHRT_MAX;
+ for (iy=ym; iy<ym+nny; iy++) {
+ datum = idata[ix][iy];
+ if (datum < valuemin) {
+ datum = valuemin;
+ }
+ else if (datum > valuemax) {
+ datum = valuemax;
+ }
+ Zf[ixx*nny+iyy++] =
+ (datum - valuemin) / (valuemax - valuemin) * USHRT_MAX;
+ }
}
if (zmin == zmax) {
- zmin = lzmin;
- zmax = lzmax;
- } else {
- if (zmin < lzmin)
- zmin = lzmin;
-
- if (zmax > lzmax)
- zmax = lzmax;
+ zmin = valuemin;
+ zmax = valuemax;
+ }
+ else {
+ if (zmin < valuemin)
+ zmin = valuemin;
+ if (zmax > valuemax)
+ zmax = valuemax;
}
- szmin = (zmin - lzmin)/(lzmax-lzmin)*USHRT_MAX;
- szmax = (zmax - lzmin)/(lzmax-lzmin)*USHRT_MAX;
+ // The value range to plot, scaled to unsigned short values
+ szmin = (zmin - valuemin) / (valuemax - valuemin) * USHRT_MAX;
+ szmax = (zmax - valuemin) / (valuemax - valuemin) * USHRT_MAX;
xmin = Dxmin; xmax = Dxmax;
ymin = Dymin; ymax = Dymax;
-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Plplot-devel mailing list
Plplot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/plplot-devel