Scilab & IPCV - imread()

Dear,

working on image transparency (see: Image transparency is possible in Scilab) I came across a rather strange phenomena.

It seems to me, that imread()changed it’s behavior between some versions.

Example: Loading a 24bit image (RGB + ALPHA)

PC 1: Scilab 2025, IPCV 4.5.0

  • img = imread(PATH_TO_IMG);
  • [nr_rows nr_cols nr_ch] = size(img);
  • nr_ch = 3

PC 2: Scilab 6.1.1, IPCV 4.1.2

  • img = imread(PATH_TO_IMG);
  • [nr_rows nr_cols nr_ch] = size(img);
  • nr_ch = 4
  • Matplot(img(:,:,4)) shows indeed the alpha channel

The IPCV ChangeLog states:

  • Version 4.1 (17-Juy-19):
  • […]
    1. imread to be able to read alpha channels,

In fact the help page for IPCV 4.1.2 would be incomplete, since it only mentions RGB images:

  • For RGB images, this is a MxNx3 unsigned char matrix.

It should also mention:

  • For RGBA images, this is a MxNx4 unsigned char matrix

I have 2 questions:

  1. Can somebody confirm the different behavior in IPCV versions?

  2. If this is all true, can somebody explain the reason for the “downgrade” ? Is this connected to Scilab itself or is this connected to IPCV?

For testing you can do:

img = imread(PATH_TO_RGBA_IMG);
disp(size(img));

Test image:

Thank you,
Philipp

I also want to mention:

Scilab 6.1.1, IPCV 4.1.2

imwrite(img,'OUT_PATH.png') creates a RGBA image, if img is a 4-channel matrix.

Is it possible to conclude, that Scilab together with IPCV were once able to handle opacity / transparency with images?

Best Regards,
Philipp

You should ask @kailup (the author of IPCV).

S.

After looking into the sources (IPCV/macros/imread.sci at 40b3169092eff06d8d0d189c6b2ca82fbb76e562 · tanchinluh/IPCV · GitHub), 4.2 version has added a second (and undocumented) parameter to imread which allows to control the way images are loaded and eventually converted on-the-fly. For example,

 x=imread("RGBA.png",IMREAD_GRAYSCALE=1); size(x)

 ans = [1x2 double]

   420.   434.

loads the image as a grayscale image. However, the prototype of imread() does not allow to set more than one option (which is likely a misconception), and the default setting (IMREAD_ANYDEPTH=1,IMREAD_ANYCOLOR = 1) strips the alpha channel. After playing with the different values, using IMREAD_LOAD_GDAL=1 does preserve the alpha channel:

--> x=imread("RGBA.png",IMREAD_LOAD_GDAL=1); size(x)

 ans = [1x3 double]

   420.   434.   4.

I suggest that the next version of IPCV should preserve all image channels (@kailup, don’t you think so ?) as version <= 4.1, so in that case the default setting should be IMREAD_LOAD_GDAL=1 instead of IMREAD_ANYDEPTH=1,IMREAD_ANYCOLOR = 1 when the image filename ends with .png ?

S.

In fact there is another possible value of the mode (IMREAD_UNCHANGED)(OpenCV: Flags used for image file reading and writing) which seems to me even more portable (whatever the actual image format).

S.

Hello Stéphane,

thanks for your investigation.

BR
Philipp