[Scilab-users] buliding masks for images

classic Classic list List threaded Threaded
3 messages Options
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] buliding masks for images

Dear all,

I build some masks with scilab, that I want to apply later on a set of images.
I can build these masks a batch process, because I have pixel coordinates that define the mask coordinates.
Each mask itself will be an image....
For now I use xs2svg and/or xs2png

Now: Is there a way to export images from scilab applying alpha channel?

I ask, because several masks will be layered on top of each other...together with a mask that is build manually by a user.
To get the final result I - for now - have to make each (mask-) image a bit transparent, to still see the underlaying image.
Thus I loose the original color of the mask image.

I could probably build an R-G-B-alpha image such as:

img = zeros[imgHeight, imgWidht ,4];

R = img[ : , : ,1];
G = img[ : , : ,2];
B = img[ : , : ,3];
A = img[ : , : ,4];

and than set the right pixel values at the right positions.

However: It seems, that it is not possible to add the alpha channel to an image when exporting it to a native image file..such as png.

imwrite (IPCV-toolbox) seems to support only 8bit (one-channel) or 24bit (3-channel) image.

Many thanks,
Philipp


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: buliding masks for images

Hello Philipp,

Le 04/03/2019 à 14:15, P M a écrit :

> Dear all,
>
> I build some masks with scilab, that I want to apply later on a set of
> images.
> I can build these masks a batch process, because I have pixel
> coordinates that define the mask coordinates.
> Each mask itself will be an image....
> For now I use xs2svg and/or xs2png
>
> Now: Is there a way to export images from scilab applying alpha channel?
>
> I ask, because several masks will be layered on top of each
> other...together with a mask that is build manually by a user.
> To get the final result I - for now - have to make each (mask-) image
> a bit transparent, to still see the underlaying image.
> Thus I loose the original color of the mask image.
>
> I could probably build an R-G-B-alpha image such as:
>
> img = zeros[imgHeight, imgWidht ,4];
>
> R = img[ : , : ,1];
> G = img[ : , : ,2];
> B = img[ : , : ,3];
> A = img[ : , : ,4];
>
> and than set the right pixel values at the right positions.
>
> However: It seems, that it is not possible to add the alpha channel to
> an image when exporting it to a native image file..such as png.

Interesting piece of information. It would deserve being documented in
the xs*() pages for formats theoretically supporting the transparency.
Have you tried with xs2gif() as well?

At least, since Scilab 5.5.0, images with an alpha channel can be
handled and display with Matlpot().

>
> imwrite (IPCV-toolbox) seems to support only 8bit (one-channel) or
> 24bit (3-channel) image.

Have you tried with https://atoms.scilab.org/toolboxes/scicv ? It is
likely the most huge external image processing library available for Scilab.

Regards
Samuel

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
der_Phil der_Phil
Reply | Threaded
Open this post in threaded view
|

Re: buliding masks for images

Thanks for the reply.

- no , I did not test xs2gif() yet.

I just installed scicv.

First Off:
- it does read images (png's) with alpha channel.

But it seems that it converts it to a 3-channel image:

Example:

Beeing RGBA_test.png a 4 channel image



scicv_Init();

img = imread("RGBA_test.png",CV_LOAD_IMAGE_ANYDEPTH);
matplot(img);
disp(getImageType(img));
// this will translate into a image of type:    CV_8UC1   = 8 bit, 1 channel...hence a grayscale image with 256 pixel values


//use:
img = imread("RGBA_test.png",CV_LOAD_IMAGE_COLOR);
// this will translate into a image of type:    CV_8UC3   = 8 bit, 3 channel...hence a color image with 256 pixel values for each channel

So I am not sure if imwrite() will use transparency.
The help is quite short on that.
It states:
imwrite(filename, img[, params])
But it does not explain what "params" is.

The openCV help on imwrite however brings hope, since the scicv toolbox is based on openCV:

...from the openCV help:

It is possible to store PNG images with an alpha channel using this function.
To do this, create 8-bit (or 16-bit) 4-channel image BGRA, where the alpha channel goes last.
Fully transparent pixels should have alpha set to 0, fully opaque pixels should have alpha set to 255 (65535).

Best regards,
Philipp

Am Mo., 4. März 2019 um 19:05 Uhr schrieb Samuel Gougeon <[hidden email]>:
Hello Philipp,

Le 04/03/2019 à 14:15, P M a écrit :
> Dear all,
>
> I build some masks with scilab, that I want to apply later on a set of
> images.
> I can build these masks a batch process, because I have pixel
> coordinates that define the mask coordinates.
> Each mask itself will be an image....
> For now I use xs2svg and/or xs2png
>
> Now: Is there a way to export images from scilab applying alpha channel?
>
> I ask, because several masks will be layered on top of each
> other...together with a mask that is build manually by a user.
> To get the final result I - for now - have to make each (mask-) image
> a bit transparent, to still see the underlaying image.
> Thus I loose the original color of the mask image.
>
> I could probably build an R-G-B-alpha image such as:
>
> img = zeros[imgHeight, imgWidht ,4];
>
> R = img[ : , : ,1];
> G = img[ : , : ,2];
> B = img[ : , : ,3];
> A = img[ : , : ,4];
>
> and than set the right pixel values at the right positions.
>
> However: It seems, that it is not possible to add the alpha channel to
> an image when exporting it to a native image file..such as png.

Interesting piece of information. It would deserve being documented in
the xs*() pages for formats theoretically supporting the transparency.
Have you tried with xs2gif() as well?

At least, since Scilab 5.5.0, images with an alpha channel can be
handled and display with Matlpot().

>
> imwrite (IPCV-toolbox) seems to support only 8bit (one-channel) or
> 24bit (3-channel) image.

Have you tried with https://atoms.scilab.org/toolboxes/scicv ? It is
likely the most huge external image processing library available for Scilab.

Regards
Samuel

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users