[Scilab-users] buliding masks for images

P M p.muehlmann at gmail.com
Mon Mar 4 22:12:22 CET 2019


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 <sgougeon at free.fr>:

> 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
> users at lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190304/573f107a/attachment.htm>


More information about the users mailing list