I think the the title is self explanatory. Although I search actually for the blackest and reddest pixel by columns, I guess answering the first automatically answers the second.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming that your bitmap stores colors in RGB color format (not YCbCr or CYMK) and further assuming that 8 bits are used per color component, the pixel closest to (0,0,0) is the blackest and the pixel closest to (255,0,0) is the reddest. Assuming that this is not really new information to you, I guess your question is rather how to calculate "the distance", so you can find out which one is the closest, correct?
To find out what the blackest pixel is, RGB might not be an optimal color representation; I’d prefer HSL for that. A pixel in HSL format consists of three values, H is the hue (the base color), S is the saturation (how much "gray" is mixed into the color) and L is the lightness (basically the brightness). The pixel with the lowest L value (L is between 1.0 and 0.0) would then be closest to black; two pixels with different H/S values, but same L value are equally "black", even though they might have different colors.
To find out which pixel is closest to red, you’d compare the HSL values of the pixels and search for the pixel with a H value closest to 0.0 degree (since 0.0 degree is red and H is between 0.0 and 360.0 degree, however 360.0 degree equals 0.0 degree), an S value closest to 1.0 (since 1.0 means full color, while 0.0 means fully gray) and an L value closest to 0.5 (since 0.0 would be black and 1.0 would be white).
E.g. in HSL dark yellow is 49.5/0.893/0.497, dark blue is 248.3/0.601/0.373, so you can clearly see that the dark blue pixel has a brightness (= lightness) of 0.373, the dark yellow one of only 0.497, thus the dark blue one is definitely "darker" than the yellow one (closer to black), which solves your first question.
Which pixel is redder? Red is 0.0/1.0/0.5. You can calculate for each component how much it is off of the ideal red pixel. Whether you "weight" all components equally or whether you consider hue (color) difference as more important than other differences (and by what factor) is rather up to your definition of red. You can exclusively go by hue if you want.
This page has a nice recipe on how to convert RGB step by step to HSL (and back again, if you have to):
http://130.113.54.154/~monger/hsl-rgb.html
To give you an idea of how the HSL color space looks like, here are some pictures from Wikipedia that try to visualize this color space:
http://upload.wikimedia.org/wikipedia/commons/a/a0/Hsl-hsv_models.svg
HSV is an alternative color space that shares some properties with HSL, however I personally prefer HSL. Both use the same definition of hue H, but they use very different definitions of saturation and thus also a different definitions of lightness/brightness.