pymagery — python imagery
1.7.0 documentation / mode_convert plugin
Mode conversion is the process of converting color modes. The three color modes supported are monochrome, grayscale, and RGB. Any conversion from right-to-left (e.g., RGB -> grayscale) results in information loss and, hence, is non-reversable. You can, of course, upconvert but that information loss doesn't magically reappear so you will never, ever get a color image out of a monochrome image.
The plugin prototype is:
The threshold argument is only valid when converting to monochrome. Other conversions do not accept a threshold.
Conversion from RGB to grayscale involves a weighted average of the sub-pixel values to determine the grayscale value. These weights were taken from http://www.w3.org/Graphics/Color/sRGB (see end of Part 2). Thus, the grayscale value is R*0.2126 + G*0.7152 + B*0.0722 which are then capped at 255. (Since the coefficients sum to greater than 255 then the weighted sum can be over 255. Everything above 255 is simply ignored.)
Conversion from grayscale to monochrome is a matter of comparing the pixel value to the supplied threshold (128 is the default if none is provided) and if the value exceeds then it is considered 1 (white) otherwise 0 (black). Conversion from RGB to monochrome is identical to conversion to grayscale first then a second conversion from grayscale to monochrome (again, using the threshold).
Conversion from grayscale to RGB simply a matter of representing that gray value in RGB. In other words, all three color channels (red, green, blue) are set to the grayscale value.
Conversion from monochrome to grayscale is simply a matter of representing 1 (white) as 255 and 0 (black) as 0. Conversion from monochrome to RGB is identical to conversion to grayscale first then a second conversion from grayscale to RGB.
The following example converts an RGB (a PPM file stores RGB) to grayscale then monochrome:
Change Log
- 1.0.0 — added