Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I know if the image is in RGB or BGR format?

Is there any way to know in advance if an image used as an input to a system is in RGB or BGR format?

I am using OpenCV with java API and I would like to convert an input image into grayscale or L*a*b* color space, but in OpenCV you have to specify first whether the image you want to convert is in RGB or BGR.

The type of the image I am using is either .jpg or .png.

like image 808
user2121 Avatar asked Jun 12 '15 11:06

user2121


1 Answers

If you are reading in the image file, or you have access to the code that reads in the file, know it is:

  • BGR order if you used cv2.imread()
  • RGB order if you used mpimg.imread() (assuming import matplotlib.image as mpimg)

If you don't know how the file was opened, the accepted answer BufferedImage is great for Java.
I would like to find a way to do the same in Python!

like image 70
SherylHohman Avatar answered Sep 18 '22 00:09

SherylHohman