Reading PNG images not giving alpha values

asked 2017-07-11 04:21:52 -0600

arqam gravatar image

I am trying to read a png image but I don't see the alpha values when I parse through the image.

Mat srcImage = Imgcodecs.imread("image_matting_example.png", IMREAD_UNCHANGED);
        byte[] buffer = new byte[4];
        Mat alphaOne = srcImage.clone();
        for(int x=100;x<440;x++){
            for(int y=20;y<60;y++){
                alphaOne.get(x,y,buffer);;
            }
        }

Here the code gives me an error as the buffer array value that I get is having just 3 values which is actually BGR(or RGB) but I am not able to see the Alpha channel, so any reason why this error is happening?

edit retag flag offensive close merge delete

Comments

try to print out some region:

System.out.println( srcImage.dump() ) ; // does it have 4 channels ?
System.out.println( srcImage.submat(ymin,ymax,xmin,xmax) )

also, it's get(y,x)

berak gravatar imageberak ( 2017-07-11 04:28:34 -0600 )edit

@berak the submat gives : Mat [ 50*50*CV_8UC3, isCont=false, isSubmat=true, nativeObj=0x7ff53d533800, dataAddr=0x1248e7576 ] So how is a png image having 3 channels, shouldn't it have 4 channels with one being alpha?

arqam gravatar imagearqam ( 2017-07-11 04:36:59 -0600 )edit

indeed, it should !

are you sure, your image HAS an alpha channel ?

berak gravatar imageberak ( 2017-07-11 04:48:11 -0600 )edit

@berak The image that I downloaded is of png format. When reading using imread it doesn't show the alpa value. So is there anywhere I am going wrong?

arqam gravatar imagearqam ( 2017-07-11 04:52:31 -0600 )edit

link ? i bet a beer, it has no such thing ;)

berak gravatar imageberak ( 2017-07-11 05:13:15 -0600 )edit

@berak Can I get your contact ID?

arqam gravatar imagearqam ( 2017-07-11 06:47:55 -0600 )edit

if you're smart, you'll find it on github.

(but i think, opencv related questions are best hanled here, where "more eyeballs make any bug shallow".)

berak gravatar imageberak ( 2017-07-11 06:51:26 -0600 )edit

@berak, Hehe, no, email ID or something I needed to discuss something (Not a doubt or something)

arqam gravatar imagearqam ( 2017-07-11 06:57:54 -0600 )edit

no problem. just look it up on github.

berak gravatar imageberak ( 2017-07-11 07:01:27 -0600 )edit

Are you on windows? Right click on the file->Properties->Details->Bit Depth and tell us what it is.

On Ubuntu there's something called pnginfo, but I admit to never having used it.

Tetragramm gravatar imageTetragramm ( 2017-07-11 18:38:37 -0600 )edit