bugGNU Octave - Bugs: bug #49941, image package: rgb2gray of a...


bug #49941: image package: rgb2gray of a single image produces a double image

Submitter:  Avinoam Kalma <avinoam>
Submitted:  Tue 27 Dec 2016 08:45:36 PM UTC
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Fixed Assigned to:  carandraug
Originator Name:  Avinoam Open/Closed:  * Closed
Release:  * other Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup

Sun 29 Jan 2017 04:08:57 PM UTC, comment #3: 

Not a duplicate of bug #50152, only very similar (sorry, I was reading incorrectly because I was in a rush).  Fixed now with http://hg.code.sf.net/p/octave/image/rev/ec1a16084bfc

Carnë Draug <carandraug>
Group Member
Sun 29 Jan 2017 04:00:11 PM UTC, comment #2: 

I believe anonymous is right about the skipping the conversion to double completely on the case of images of class single.  I have fixed like that for the bug #50152 (a duplicate of this).

To Avinoam:

you don't need to

assert (isequal(class(rgb2gray(ones(3,3,3,'single'))),'single'))

because assert takes an observed and expected arguments.  Instead, use:

assert (class (rgb2gray (ones (3, 3, 3, 'single'))), 'single')

Carnë Draug <carandraug>
Group Member
Thu 26 Jan 2017 10:05:57 AM UTC, comment #1: 

Actually, it might be an idea to handle the line

gray = im2double (rgb)...

differently and convert to double only in the case of uint8/uint16. This way if the input is single, the calculation is also done at single precision (saves a lot for very large images).

Also see bug #50152

Tue 27 Dec 2016 08:45:36 PM UTC, original submission:  

rgb2gray of a single image produces a double image, while in
MATLAB the result is single.

The fix is very simple: instead of

    case {"single", "double"}
      ## do nothing. All is good

There should be:

    case "single"
      im = single(im);
    case "double"
      ## do nothing. All is good


assert (isequal(class(rgb2gray(ones(3,3,3,'single'))),'single'))

Avinoam Kalma <avinoam>
Group Member


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

Attach Files:

No files currently attached


   bug dependencies.

Items that depend on this one: None found


Carbon-Copy List
  • -email is unavailable- added by avinoam (Submitted the item)
  • -email is unavailable- added by avinoam

    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
    2017-01-29 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
    2017-01-29 carandraug Dependencies- Depends on bugs #50152
    2016-12-27 avinoam Carbon-Copy- Added -email is unavailable-

    Back to the top

    Powered by Savane 3.13-58d6.
    Corresponding source code