# Opacity and scicv

**URL:** https://scilab.discourse.group/t/opacity-and-scicv/495
**Category:** General usage
**Created:** [May 3, 2024, 9:52pm UTC](https://scilab.discourse.group/t/opacity-and-scicv/495 "2024-05-03T21:52:12Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![philipp](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/philipp/32/53_2.png) [@philipp](https://scilab.discourse.group/u/philipp)
#### Post date: [May 3, 2024, 9:52pm UTC](https://scilab.discourse.group/t/opacity-and-scicv/495/1 "2024-05-03T21:52:12Z")

</div>

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:

> [@Opacity adjustment and export of multi-page pdfs not possible?](https://scilab.discourse.group/t/opacity-adjustment-and-export-of-multi-page-pdfs-not-possible/480/2):
>
> Hello, Scilab does not handle TrueColor model (only RGB indexed colors) in general. The only entity handling RGBA is the Matplot entity (see [Matplot - 2D plot of a matrix using colors](https://help.scilab.org/Matplot)). Multipage pdf are not supported. S.

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](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.

```auto
// 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.");

```

---

<div class="post-metadata">

### Author: ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)
#### Post date: [May 6, 2024, 6:52am UTC](https://scilab.discourse.group/t/opacity-and-scicv/495/2 "2024-05-06T06:52:55Z")

</div>

> [@philipp](#):
>
> opacity in graphs (and images)

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](https://help.scilab.org/docs/2024.0.0/en_US/Matplot_properties.html) and the image\_type field.

S.
