You can also use an if statement to check if the mode of the image is RGBA before calling the Image.convert() method. how to use rgb in python; count function in python; string reverse function in . Color images are represented as multi-dimensional arrays - a collection of three two-dimensional arrays, one each for red, green, and blue channels. First, while the coefficients are correct for sRGB or Rec709, to convert from color to Y. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. For a test scenario, convert rgba(0,0,0,.7) on background rgb(255,255,255) using both formulas; hkurabko's forumala clearly produces the correct answer. Now read the LAB image from the location. This method simply removes the alpha channel from the RGBA images, the transparency will turn into black (or sometimes noises) in the resulting images. By definition, however, this won't work in most cases. pythonjpgpng - CSDN If you want to set the \[S \leftarrow \fork{\frac{V-min(R,G,B)}{V}}{if \(V \neq 0\)}{0}{otherwise}\], \[H \leftarrow \forkfour{{60(G - B)}/{(V-min(R,G,B))}}{if \(V=R\)} {{120+60(B - R)}/{(V-min(R,G,B))}}{if \(V=G\)} {{240+60(R - G)}/{(V-min(R,G,B))}}{if \(V=B\)} {0}{if \(R=G=B\)}\]. This answer works with the CSS's definition of alpha. OpenCV provides the cvtColor function that allows to convert an image from one color space to another. You probably want to use an image's convert method: import PIL.Image rgba_image = PIL.Image.open (path_to_image) rgb_image = rgba_image.convert ('RGB') Share Improve this answer Follow edited Oct 7, 2019 at 6:30 ejuhjav 2,620 2 24 31 answered May 14, 2018 at 14:06 Noctis Skytower 21.2k 16 82 116 Add a comment 15 While it is possible to convert images from YUYV (also known as YUV422) into RGB via COLOR_YUV2RGB_YUYV, there is no reverse .