Dear,
image transparency and Scilab seem to popup as a topic once in a while.
Transparency is said to not be supported in Scilab, e.g.: see
However Matplot()
(native Scilab) and matplot()
(scicv) do support RGBA images.
The point is, that imread()
from the various image processing toolboxes clip the alpha channel from the input image.
E.g.:
A 100x100x4 RGBA image (PNG) will be loaded as 100x100x3 data structure by imread()
of IPCV.
However, there is a workaround:
You can extract the alpha channel of the input image and save it as a separate image. This can be done rather easy with e.g.: IrfanView by displaying just the alpha channel and saving this as a new file.
Once there is a separate alpha-channel image, one can load both images (orig as RGB & alpha) into Scilab.
The alpha-channel will be saved as an gray scale image.
Done this, one can reunite both parts (RGB + ALPHA) by loading the separatly with imread()
.
img_RGB = imread(PATH_TO_IMAGE);
img_ALPHA = imread(PATH_TO_ALPHA_CHANNEL_IMAGE);
In Scilab one can than build a structure that holds 4 channels, e.g.:
img = uint8(zeros(imgHeight, imgWidth, 4));
Next, one can reunite the separate images together into one.
img(:,:,1:3) = uint8(img_RGB);
img(:,:,4) = uint8(img_ALPHA);
If we also load a background image:
img_background = imread(PATH_IMG_BACK);
we can display the result
subplot(1,3,1);
Matplot(img_background);
subplot(1,3,2);
Matplot(img_RGB);
subplot(1,3,3);
Matplot(img_background);
Matplot(img);
Note:
The ALPHA channel in this example contained only 0 and 255 as values.
You may use values in the range [0 255] to get other transparency effects.
In the hope, that this will help here and there…
Best Regards,
Philipp