bugGNU Octave - Bugs: bug #63060, imread returns logical data for...

 
 

bug #63060: imread returns logical data for 8-bit TrueColor PNG image

Submitter:  Yu Hongbo <yuhongbo>
Submitted:  Thu 15 Sep 2022 03:13:02 AM UTC
   
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  * Open
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Thu 06 Oct 2022 03:22:32 PM UTC, comment #8: 

Actually, this is not a duplicate of bug #51264.  In that bug, the potential fix would be in the read_images() function.  In this case, a fix would need to occur in the get_depth() routine before read_images is called.

There are numerous bug reports about imread getting confused by data that looks like it is either binary (0/1) or graylevel.  Alas, this is all about the Imagemagick libraries which sometimes seem to mis-identify files, but don't give programmers enough visibility to countermand those decisions.

Either we just live with this situation or we have to create a lot of point exceptions for certain file types with certain configurations of bit depth, color profile, etc.  None of it is very good.

There may be some correlation between when a file is DirectClass or PseudoClass (indexed) and whether it is truly 1-bit data.  I will post a patch for that here.  But it would need a fair bit of testing on multiple platforms with different versions of Magick libraries.

Rik <rik5>
Group administrator
Thu 06 Oct 2022 07:37:59 AM UTC, comment #7: 

IIUC, the patch in bug #51264 only affects reading JPEG files. Would it also work for the PNG file here?

Markus Mützel <mmuetzel>
Group administrator
Wed 05 Oct 2022 07:36:40 PM UTC, comment #6: 

This seems to be a duplicate of bug #51264.  Perhaps the patch there should just be applied because this issue has been reported multiple times.

Rik <rik5>
Group administrator
Wed 05 Oct 2022 07:25:12 PM UTC, comment #5: 

Interestingly, imfinfo identifies the file as a greyscale file with bit depth of 1.


imfinfo white_background_3.png
ans =

  scalar structure containing the fields:

    Filename = /home/rik/wip/Projects_Mine/octave-dev/white_background_3.png
    FileModDate =  5-Oct-2022 12:18:19
    FileSize = 4891
    Format = PNG
    FormatVersion =
    Width = 65
    Height = 65
    BitDepth = 1
    ColorType = grayscale


It is sufficient to change even one pixel to a value which is not black or white for the detection algorithm to correctly identify the PNG file as 8-bit TrueColor.

Rik <rik5>
Group administrator
Wed 05 Oct 2022 07:14:12 PM UTC, comment #4: 

FYI, Matlab also doesn't allow logical values for TrueColor data.  This code works:


img = rand (65,65) > 0.5;
imshow (img)


But this code does not


img = rand (65,65,3) > 0.5;
imshow (img)


The error message says that logical data must be 2-D.

Hence, the problem seems to be that imread is returning logical data, when it should be returning TrueColor data.  Re-titling bug report.

Rik <rik5>
Group administrator
Thu 29 Sep 2022 04:35:50 PM UTC, comment #3: 

I can reproduce with a build from the development branch (hg id 4c2b83516eb7).

IIUC, the issue is that Octave's `image` objects don't take logical valued images.

Fwiw, the image is converted to `uint8` (all 255) when read in Matlab R2022a:

>> im = imread('white_background.png');
>> whos im
  Name       Size              Bytes  Class    Attributes

  im        65x65x3            12675  uint8
>> im(1,1,:)
  1×1×3 uint8 array
ans(:,:,1) =
   255
ans(:,:,2) =
   255
ans(:,:,3) =
   255


Should we do the same when reading Boolean images?

Markus Mützel <mmuetzel>
Group administrator
Thu 29 Sep 2022 02:54:47 PM UTC, comment #2: 

The white_background.png is at https://savannah.gnu.org/bugs/download.php?file_id=53774

The output is:

>> im = imread('white_background.png');
>> whos im

Variables visible from the current scope:

variables in scope: top scope

   Attr Name        Size                     Bytes  Class
   ==== ====        ====                     =====  =====
        im         65x65x3                   12675  logical

Total is 12675 elements using 12675 bytes

comment #1:

> It would if you could upload the png file. Both error/warning messages suggest that imread returns unsupported data type. What is is shown after the following commands?
>


> im = imread ('white_background.png');
> whos im


>

Yu Hongbo <yuhongbo>
Thu 15 Sep 2022 07:13:38 PM UTC, comment #1: 

It would if you could upload the png file. Both error/warning messages suggest that imread returns unsupported data type. What is is shown after the following commands?


im = imread ('white_background.png');
whos im


Pantxo Diribarne <pantxo>
Group Member
Thu 15 Sep 2022 03:13:02 AM UTC, original submission:  

Both imshow() and set() are failed. Here is my code:

>> im = imread('white_background.png');
>> imshow(im)

error: imshow: TrueColor image must be uint8, uint16, double, or single
error: called from
    imshow at line 114 column 7

>> img = image();
>> set(img, 'cdata', im)
>> warning: opengl_texture::create: invalid image data type, expected double, single, uint8, or uint16

Yu Hongbo <yuhongbo>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #53774:  white_background.png added by yuhongbo (631B - image/png - white_background.png)

 

Digest:
   bug dependencies.

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by pantxo (Posted a comment)
  • -email is unavailable- added by yuhongbo (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 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-10-06 rik5 StatusDuplicate Confirmed
        Dependencies- Depends on bugs #51264
    2022-10-05 rik5 StatusConfirmed Duplicate
        Carbon-Copy- Added carandraug
    2022-10-05 rik5 CategoryPlotting Octave Function
        Item GroupUnexpected Error or Warning Incorrect Result
        StatusNeed Info Confirmed
    2022-10-05 rik5 Summaryimage() handle cannot be set cdata with an imread() result imread returns logical data for 8-bit TrueColor PNG image
    2022-09-29 mmuetzel Release6.4.0 dev
        Operating SystemGNU/Linux Any
    2022-09-29 yuhongbo Attached File- Added white_background.png, #53774
    2022-09-15 pantxo StatusNone Need Info

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code