Reading PNG images not giving alpha values
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?
try to print out some region:
also, it's get(y,x)
@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?indeed, it should !
are you sure, your image HAS an alpha channel ?
@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?link ? i bet a beer, it has no such thing ;)
@berak Can I get your contact ID?
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, Hehe, no, email ID or something I needed to discuss something (Not a doubt or something)
no problem. just look it up on github.
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.