PIL Picture Mode Am I Halftone?

I am trying to specify the colors of my image in Integer format instead of (R, G, B) format. I suggested that I need to create the image in "I" mode, as according to the documentation:

Image mode determines the type and depth of the pixel in the image. The current version supports the following standard modes:

  • 1 (1-bit pixels, black and white, stored with one pixel per byte)
  • L (8-bit pixels, black and white)
  • P (8-bit pixels displayed in any other mode using the color palette)
  • RGB (3 x 8-bit pixels, true color)
  • RGBA (4x8-bit pixels, true color with transparency mask)
  • CMYK (4x8-bit pixels, color separation)
  • YCbCr (3x8-bit pixels, color video format)
  • i (32-bit signed integer pixels)
  • F (32-bit floating point pixels)

However, this is similar to a grayscale image. Is this expected? Is there a way to specify a color image based on a 32-bit integer? In my MWE, I even allowed PIL to decide how to convert β€œred” to β€œI” format.


MWE

from PIL import Image ImgRGB=Image.new('RGB', (200,200),"red") # create a new blank image ImgI=Image.new('I', (200,200),"red") # create a new blank image ImgRGB.show() ImgI.show() 
+5
source share
1 answer

Is there a way to specify a color image based on a 32-bit integer?

Yes, use the RGB format for this, but instead use an integer instead of β€œred” as the color argument:

 from PIL import Image r, g, b = 255, 240, 227 intcolor = (b << 16 ) | (g << 8 ) | r print intcolor # 14938367 ImgRGB = Image.new("RGB", (200, 200), intcolor) ImgRGB.show() 
+4
source

All Articles