bugGNU Octave - Bugs: bug #41673, imwrite creates bad jpeg grayscale...

 
 

bug #41673: imwrite creates bad jpeg grayscale images

Submitter:  Ian Journeaux <ijourneaux>
Submitted:  Sat 22 Feb 2014 11:03:14 PM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  None
Originator Name:  Ian Journeaux Open/Closed:  * Closed
Release:  * 3.8.0 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Wed 11 Feb 2015 05:52:41 PM UTC, comment #8: 
Carnë Draug <carandraug>
Group Member
Wed 11 Feb 2015 05:48:37 PM UTC, comment #7: 

Correct: the bug is not fixed in the current default system:

line 1107:
           for (octave_idx_type col = 0; col < nCols; col++)
              {
                for (octave_idx_type row = 0; row < nRows; row++)
                  {
                    Magick::Color c;
                    c.redQuantum (double (*img_fvec) / divisor);
                    pix[GM_idx] = c;
                    img_fvec++;
                    GM_idx += nCols;
                  }
                GM_idx -= nCols * nRows - 1;
              }

Michael Godfrey <godfrey>
Group Member
Wed 11 Feb 2015 05:42:23 PM UTC, comment #6: 

I just gave it a go on the default branch and despite comment #2, this is indeed not fixed.

Answering comment #4

yes it is a wonder because this works fine for other formats. I can't find it on the documentation at the moment but if I remember correctly (it has been almost 2 years), you should be able to create grayscale images by setting the red channel.  And that is why 10 lines above the snippet you show, the image is created with type Magick::GrayscaleType

What is happening then? Is the mean of the 3 channels being used on the new image? Why does this not happen for the other coders/formats?

Carnë Draug <carandraug>
Group Member
Wed 11 Feb 2015 05:20:52 PM UTC, comment #5: 

What are you commenting on? Is this bug not fixed yet?

Carnë Draug <carandraug>
Group Member
Wed 11 Feb 2015 06:13:14 AM UTC, comment #4: 


at "libinterp/dldfcn/__magick_read__.cc"

No wonder that image is red:

                for (octave_idx_type row = 0; row < nRows; row++)
                  {
                    Magick::Color c;
                    c.redQuantum (double (*img_fvec) / divisor);
                    pix[GM_idx] = c;

Fix:

                for (octave_idx_type row = 0; row < nRows; row++)
                  {
                    double grey = double (*img_fvec) / divisor;
                    Magick::Color c (grey, grey, grey);
                    pix[GM_idx] = c;

Ilya Kurdyukov <ikurdyukov>
Tue 11 Mar 2014 07:16:51 PM UTC, comment #3: 

For future reference, what fixed this will most likely be e0cc67d5a462 (although it was a side effect of fixing a different bug).

Alternatively, it may have been fixed by e0cc67d5a462.

Carnë Draug <carandraug>
Group Member
Tue 11 Mar 2014 04:11:15 PM UTC, comment #2: 

With the latest version of MXE Octave for Windows 3.8.1 from http://mxeoctave.osuv.de/, this bug seem to corrected. Selecting .bmp or .jpg seems to produces the correct result.

a = repmat (uint8 (0:255), 100, 1);
imshow (a)
imwrite (a, "test.bmp");
b = imread ("test.bmp");
figure;
imshow (b)

Ian Journeaux <ijourneaux>
Sun 23 Feb 2014 05:11:25 PM UTC, comment #1: 

I can replicate this problem with the more simple case:


a = repmat (uint8 (0:255), 100, 1);
imshow (a)
imwrite (a, "test.jpg");
b = imread ("test.jpg");
figure;
imshow (b)


The example above shows that the problem happens during imwrite since the jpg file created is already wrong.

We can also see that the problem happens only with grayscale images since writing an RGB image creates the image file correctly:


a = repmat (uint8 (0:255), 100, 1, 3);
imwrite (a, "test.jpg");


But I'm unsure if this is a problem in Octave. The reason to believe this is that Octave does not have format specific code, the code is all the same, independent of the format chosen. However, if we write the image to a tif or bmp file, everything is correct. By the way, using imread() to read the RGB image where all 3 channels are the same, will read a grayscale image. This is again, because GraphicsMagick will recognize it as such and report a grayscale image to save memory.

Still, I'm marking this as a regression because apparently (according to the OP on the mailing list)) Octave was saving the file correctly in 3.2.4 and 3.6.0.

Carnë Draug <carandraug>
Group Member
Sat 22 Feb 2014 11:03:14 PM UTC, original submission:  

if you write out an array using imwrite in bmp and jpg format, the output is not correct. If you use tif format the ouput looks ok.


I have attahed a smalll sample. test.bmp and test.jpg are corrupt compared to the input.jpg. The background should be off white. test.bmp has a red background and test.jpg is dark gray. test.tif appears to be correct.

The problem exists in 3.8.1rc

Ian Journeaux <ijourneaux>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #30646:  testimwrite.m added by ijourneaux (111B - application/octet-stream)

 

Carbon-Copy List
  • -email is unavailable- added by godfrey (Posted a comment)
  • -email is unavailable- added by ikurdyukov (Posted a comment)
  • -email is unavailable- added by ijourneaux (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 13 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2015-02-11 carandraug StatusPatch Submitted Fixed
        Open/ClosedOpen Closed
    2015-02-11 carandraug StatusFixed Patch Submitted
        Open/ClosedClosed Open
    2015-02-11 carandraug Dependencies- bugs #44118 is dependent
    2015-02-11 carandraug Dependencies- bugs #42474 is dependent
    2014-03-11 carandraug StatusNone Fixed
        Open/ClosedOpen Closed
    2014-02-23 carandraug Summaryimwrite creates bad grayscale images imwrite creates bad jpeg grayscale images
    2014-02-23 carandraug Item GroupIncorrect Result Regression
        Operating SystemMicrosoft Windows Any
        Summaryimwrite problems with jpg and bmp imwrite creates bad grayscale images
    2014-02-22 ijourneaux Attached File- Added testimwrite.m, #30646

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code