Opacity and scicv

Dear,

opacity in graphs (and images) seem to pop up as a request once in a while.

A recent question (as of 05.2024) , see:

Well, an older discussion pointed out to use scicv, but no final statement about opacity was done back then.
https://lists.scilab.org/pipermail/users/2019-March/014858.html

The recent request made me think again, and I put together some code.
If I am not to wrong, scicv do can handle opacity, but it is a bit tricky and not well documented.

I used scicv 0.6.2.

Analyzing the saved images with IrfanView, the 3-channel image seem to have no alpha channel, but the 4-channel image does.

// PURPOSE:         Play around with opacity of images
//
// BACKGROUND:      try to use scicv toobox to create images with opacity
//
// INPUT:           https://docs.opencv.org/3.4/d4/da8/group__imgcodecs.html  (some openCV source)
//  
// OUTPUT:          some generic images
//
// DEPENDECIES:     scicv toolbox
//
//
// PREPARE SCILAB
clc();
clear();
close();

// SUBROUTINES      none

// DEFINES
OUT_DIR         = 'D:\Scilab_Uebungen\Try_Opacity_with_Scicv' + '\'

// CODE

scicv_Init();

// load image as 3 channel image
img_1           = imread(getSampleImage("lena.jpg"));
img_2           = new_Mat(size(img_1, 'c'), size(img_1, 'r'), CV_8UC3, 128);     // img1 is of size [255 255]
img_Out         = add(img_1, img_2);


// Create 3 channel images (BGR)
backgroundColor = [255, 0, 0]
imgNew_1        = new_Mat(255, 255, CV_8UC3, backgroundColor);
backgroundColor = [0, 0, 255]
imgNew_2        = new_Mat(255, 255, CV_8UC3, backgroundColor);
imgNew_Out      = add(imgNew_1, imgNew_2) 


// create 4 channel images (ABGR (?) )
backgroundColor = [25, 255, 0, 0]
imgNew_1_A      = new_Mat(255, 255, CV_8UC4, backgroundColor);
backgroundColor = [25, 0, 0, 255]
imgNew_2_A      = new_Mat(255, 255, CV_8UC4, backgroundColor);
imgNew_Out_A    = add(imgNew_1_A, imgNew_2_A)


// display images
subplot(3,3,1)
matplot(img_1);
subplot(3,3,2)
matplot(img_2);
subplot(3,3,3)
matplot(img_Out);

subplot(3,3,4)
matplot(imgNew_1);
subplot(3,3,5)
matplot(imgNew_2);
subplot(3,3,6)
matplot(imgNew_Out);

subplot(3,3,7)
matplot(imgNew_1_A);
subplot(3,3,8)
matplot(imgNew_2_A);
subplot(3,3,9)
matplot(imgNew_Out_A);


// export images
imwrite(OUT_DIR + "RGB.png", imgNew_Out);
imwrite(OUT_DIR + "RGBA.png", imgNew_Out_A);


// delete images
delete_Mat(img_1);
delete_Mat(img_2);
delete_Mat(img_Out);

delete_Mat(imgNew_1);
delete_Mat(imgNew_2);
delete_Mat(imgNew_Out);

delete_Mat(imgNew_1_A);
delete_Mat(imgNew_2_A);
delete_Mat(imgNew_Out_A);

// ################################################################
// END OF SCRIPT
printf("\n");
printf("REACHED END OF SCRIPT.");

That’s different stuff. As I already said opacity can be handled in Matplot objects, which are used for 2D True Color image display by scicv and IPCV. But the only supported color system for other objects is the one using indexed colors.

Matplot entities are well documented, see Matplot properties - Description of the Matplot entities properties and the image_type field.

S.