octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #49130] uint8 images are not shown correctly b


From: Rik
Subject: [Octave-bug-tracker] [bug #49130] uint8 images are not shown correctly by imshow with gnuplot
Date: Fri, 30 Sep 2016 16:00:39 +0000 (UTC)
User-agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:43.0) Gecko/20100101 Firefox/43.0

Follow-up Comment #15, bug #49130 (project octave):

I pushed your cset here
(http://hg.savannah.gnu.org/hgweb/octave/rev/202c6871f07d).

I followed it with some changes to make it more Matlab compatible.


changeset:   22564:3fd1b248bb27
branch:      stable
tag:         tip
user:        Rik <address@hidden>
date:        Fri Sep 30 08:51:18 2016 -0700
files:       scripts/plot/util/private/__gnuplot_draw_axes__.m
description:
Better Matlab compatibility for images created with gnuplot (bug #49130).

* __gnuplot_draw_axes__.m (mapcdata): Don't do conversion to
double->uint8->double to achieve clamping of RGB values.  Keep cdata as
double
and use indexing to find and clamp values outside range [0, 255].
For scaled data, use scaling factor of colormap_size rather than
colormap_size-1 for compatibility.
For "direct" integer data, convert range from zero-based indices to
ones-based.
For "direct" float data, truncate using "fix" rather than "round" for
compatibility.


diff -r b828361c8949 -r 3fd1b248bb27
scripts/plot/util/private/__gnuplot_draw_axes__.m
--- a/scripts/plot/util/private/__gnuplot_draw_axes__.m Wed Sep 28 15:57:05
2016 -0500
+++ b/scripts/plot/util/private/__gnuplot_draw_axes__.m Fri Sep 30 08:51:18
2016 -0700
@@ -2849,21 +2849,27 @@ endfunction
 
 function retval = mapcdata (cdata, mode, clim, cmap_sz)
   if (ndims (cdata) == 3)
-    # True color, clamp data to 8-bit
+    ## True Color, clamp data to 8-bit
     cdata = double (cdata);
-    cdata = uint8 (255*(cdata-clim(1))/(clim(2)-clim(1)));
-    # Scale using inverse of gnuplot's cbrange mapping
-    retval = 1 + double (cdata)*(cmap_sz-1)/255;
+    cdata = 255 * (cdata - clim(1)) / (clim(2)-clim(1));
+    cdata(cdata < 0) = 0;  cdata(cdata > 255) = 255;
+    ## Scale using inverse of gnuplot's cbrange mapping
+    retval = 1 + cdata * (cmap_sz-1)/255;
   else
     if (islogical (cdata))
       cdata += 1;
     elseif (strcmp (mode, "scaled"))
       cdata = double (cdata);
       clim = double (clim);
-      cdata = 1 + fix ((cmap_sz-1)*(cdata-clim(1))/(clim(2)-clim(1)));
+      cdata = 1 + fix (cmap_sz * (cdata - clim(1)) / (clim(2) - clim(1)));
     else
-      cdata = round (cdata);
+      if (isinteger (cdata))
+        cdata += 1;
+      else
+        cdata = fix (cdata);
+      endif
     endif
     retval = max (1, min (cdata, cmap_sz));
   endif
 endfunction
+




    _______________________________________________________

Reply to this item at:

  <http://savannah.gnu.org/bugs/?49130>

_______________________________________________
  Message sent via/by Savannah
  http://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]