Talk:Grayscale image

Revision as of 15:39, 17 January 2009 by rosettacode>Dmitry-kazakov (Terms)

Linear color space

If I am not wrong, the equation L = 0.2126·R + 0.7152·G + 0.0722·B only works correctly in linear color space. Most images, however, are stored in sRGB color space. If you want to do the conversion correctly for a real world image, you should first convert it into linear color space.

But for simplicity, I guess, we could assume that the image is already in linear color space (even if it actually would require at least 16 bit color depth instead of 8 bit). --PauliKL 17:00, 15 January 2009 (UTC)

The "parent" task is silent about the color model. If you want to fix it in this way or another, I think, you should better start there.
Surely we could define some additional tasks dealing with different color models and conversions between them. I am not sure that this would meet much interest.
Thinking further in this direction, there are so many areas in image processing / computer graphics, that I seriously doubt if RC would ever able to represent more than just a fraction of. Especially because most of them quickly grow out of "boy" format. I wished to add image segmenting tasks, by region growing, by pyramid etc, but then I realized that already this would be far over the top... --Dmitry-kazakov 18:33, 15 January 2009 (UTC)
Color models are not relevant in the parent task. Creating a storage for image and plotting pixels do not care about color models. Color models are needed when doing conversions, such as RGB to grayscale conversion.
How so? Color points are kept in a definite model. When plotted the device expects images in a certain format which includes color model specification as well. --Dmitry-kazakov 17:11, 16 January 2009 (UTC)
No. Color points are not "kept" in any model. The image storage is just a block of memory. The memory does not care what is stored in it. You only need to know how much memory you need to reserve. An RGB value is plotted into the image by writing the values of R, G and B in memory. The memory model used (gamma etc.) has no effect on this operation. --PauliKL 21:01, 16 January 2009 (UTC)
Image storage is not a memory block. It is a set of language objects that used to store and process images. --Dmitry-kazakov 15:39, 17 January 2009 (UTC)
The point is that the CIE conversion function mentioned requires linear color mode. If linear color model is not used, you could use just about any weighting factors for R, G and B, and it does not help to use so many decimal digits. A common function used in sRGB color space is L = 0.3*R + 0.59*G + 0.11*B . When this is applied to and sRGB image, the results are closer to CIE conversion than when you use the CIE function in sRGB color space. I just thought that this should be mentioned, in case someone is planning to use the code examples given here in a real application.
Another commonly overlooked fact is that most image processing functions such as resizing only work correctly in linear color space. But that is another story.
--PauliKL 16:00, 16 January 2009 (UTC)
No, they work in any model, of course. It is so that the algorithm depends on the model, obviously. --Dmitry-kazakov 17:11, 16 January 2009 (UTC)
No, they do not work. An image editor performs an operation always the same way, it does not care about the memory model. If you order the program to add the values of two pixels, it adds the values of two pixels. And that works correctly only in linear color space. If you do not believe me, try it. The color space is only relevant when you perform conversion from one color space to another. In theory, it would be possible to convert each pixel separately to linear color space and back when performing each image editing operation, but that would make the image editor so extremely slow that nobody would want to use it. --PauliKL 21:01, 16 January 2009 (UTC)
No, I don't believe you. Pixels are not numbers, you cannot add them unless you define a vector space of, supplied by a definition of the operation +. The operation + in that space corresponding to certain semantics (to be specified) is a part of a color model. --Dmitry-kazakov 15:39, 17 January 2009 (UTC)
Return to "Grayscale image" page.