bugGNU Octave - Bugs: bug #41240, image class is not preserved in...

 
 

bug #41240: image class is not preserved in cdata field of graphics handle

Submitter:  CarnĂ« Draug <carandraug>
Submitted:  Wed 15 Jan 2014 05:43:22 PM UTC
   
 
Category:  Plotting Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Other
Status:  Fixed Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * 3.8.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 01 May 2014 08:28:17 PM UTC, comment #5: 

I added support for images to use the logical data type (http://hg.savannah.gnu.org/hgweb/octave/rev/d57a83f2d73e).  I then overhauled the imshow routine to get rid of the conversion to double.  I also did a lot of other cleanup on imshow.  It's not perfect, but is way better than before (http://hg.savannah.gnu.org/hgweb/octave/rev/0585787aa8ae).

Rik <rik5>
Group administrator
Sun 27 Apr 2014 08:49:19 AM UTC, comment #4: 

Here is a test in Matlab:


% Integer, scaled
img = uint8 (meshgrid (0:250));
h = imshow (img);
class (get (h, 'cdata')) %% uint8

% Integer, true color
img = repmat (uint8 (meshgrid (0:250)), [1 1 3]);
h = imshow (img);
class (get (h, 'cdata')) %% uint8

% Integer, indexed
img = uint8 (meshgrid (1:256));
h = imshow (img, colormap ('jet'));
class (get (h, 'cdata')) %% uint8

% Logical
img = meshgrid (0:250) > 125;
h = imshow (img);
class (get (h, 'cdata')) %% logical


The image class is always preserved for the case of logical and uint8 integer images. Tell me if more exhaustive tests are needed.

Pantxo Diribarne <pantxo>
Group Member
Sat 26 Apr 2014 11:46:16 PM UTC, comment #3: 

I added support in C++ for integer formats with this changeset (http://hg.savannah.gnu.org/hgweb/octave/rev/44f0d1a53ead).  Octave can will now store cdata in the same datatype (uint8, single, etc.) as the original input format to image().

At this point, this bug should be easy to fix.  In imshow.m there is this line:
 

  ## This is for compatibility.
  if (! (indexed || (true_color && isinteger (im))) || islogical (im))
    im = double (im);
  endif


This line was coded a long time ago and is probably no longer accurate.  Someone with access to Matlab should verify how imshow behaves and possibly this line can be deleted.  Actually, the whole of imshow looks like it could be cleaned up to just call image or imagesc for the backend.

Rik <rik5>
Group administrator
Wed 29 Jan 2014 06:26:31 AM UTC, comment #2: 

This has been a known issue for a while.  See image.m and the following lines


  ## FIXME: Hack for integer formats which use zero-based indexing
  ##        Hack favors correctness of display over size of image in memory.
  ##        True fix must be done in C++ code for renderer.
  if (ndims (img) == 2 && (isinteger (img) || islogical (img)))
    img = single (img) + 1;
  endif


which I added.  There is currently no support for integer formats (zero-based indexing in the C++ renderer.

Rik <rik5>
Group administrator
Sun 19 Jan 2014 06:53:15 PM UTC, comment #1: 

Confirmed in default version as well.

Mike Miller <mtmiller>
Group Member
Wed 15 Jan 2014 05:43:22 PM UTC, original submission:  

The data of an image being plotted is kept in the field cdata, but the class has changed. This is important because the class of an image changes how the data is interpreted.

For example:


## image is uint8
img = repmat (uint8 (0:250), [200 1]);
h = imshow (img);
## image comes back as double
nimg = get (h, 'cdata');
class (nimg)
## note how changing class has a drastic effect on its representation
figure ();
imshow (nimg);


Note how the the same function, imshow, displays the image so differently. As uint8, it's a gradient, as double, it's all white (since images of class double should be on range [0 1]).

The effect this has on other functions is that it's not possible to retrieve the image from a figure (required for things such as impixel and imcrop which return parts from the current or a specified figure).

I looked at the other fields available from get() but didn't notice anything that would point to the original class.

Also, this works in MatLab so it stacks as a matlab compatibility bug.

Carnë Draug <carandraug>
Group Member

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by carandraug (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2014-05-01 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2014-01-19 mtmiller CategoryNone Plotting
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-758e.
    Corresponding source code