lessthanoptimal / BoofCV

Fast computer vision library for SFM, calibration, fiducials, tracking, image processing, and more.

Home Page:http://boofcv.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Alpha channel has random index

c4da opened this issue · comments

When I convert Buffered Image to Planar than the alpha channel can be sometimes found with rgbF32.getBand(0) and other times with rgbF32.getBand(3). Am I doing something wrong?

Planar<GrayF32> rgbF32 = ConvertBufferedImage.convertFromPlanar(imageSource, null,true, GrayF32.class);

the imageSource is a BufferedImage.TYPE_INT_ARGB_PRE

EDIT:
I found out that my BufferedImage Type is not always TYPE_INT_ARGB_PRE but is sometimes TYPE_INT_ARGB.
So for TYPE_INT_ARGB_PRE you can find the alpha channel at 0 index.
For TYPE_INT_ARGB the alpha is at 3.

The current code does not handle TYPE_INT_ARGB_PRE, which explains why you're seeing some issues. Thanks for explaining what the _PRE means since Oracle's JavaDoc does not! I'll add this to the list of stuff to fix. Thanks!

https://docs.oracle.com/javase/7/docs/api/java/awt/image/BufferedImage.html

Bumping this issue up in priority.

After more investigation, PRE stands for premultiplying the alpha channel. The channel order issue has been fixed but you still might not like the results since the RGB colors will be premultiplied and if not handled correctly will not appear correctly.

latest code has the fix. Feel free to re-open if additional work is needed.