convert color image to grayscale image ?
-
dear all howt to convert color image to grayscale image in c++? anyone has such code? thanks a lot
Li Zhiyuan
Can't you simply average the color components, i.e.
COLORREF color, gray;
//...
BYTE avg = (GetRValue(color) + GetGValue(color) + GetBValue(color))/3;
gray = RGB(avg, avg, avg);?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Can't you simply average the color components, i.e.
COLORREF color, gray;
//...
BYTE avg = (GetRValue(color) + GetGValue(color) + GetBValue(color))/3;
gray = RGB(avg, avg, avg);?
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarkethen (R = 100, G = 0, B = 0) and (R= 0, G =100, B = 0) and (R=0, g= 0, b= 100) all gives the same value, that is if the image has 3 region each filled with Red, Green, Blue respectively, then the whole image has same gray value (can't identify the regions)
modified on Thursday, February 21, 2008 5:06 AM
-
then (R = 100, G = 0, B = 0) and (R= 0, G =100, B = 0) and (R=0, g= 0, b= 100) all gives the same value, that is if the image has 3 region each filled with Red, Green, Blue respectively, then the whole image has same gray value (can't identify the regions)
modified on Thursday, February 21, 2008 5:06 AM
Color to Gray space conversion is lossy by definition: RGB Color space allows 2^24 different values for color image pixels, while the constraint RGB(x,x,x) implies 2^8 different values for gray pixels. Thus we have a mapping of a 2^24 set to 2^8 set, i.e. a lossy mapping. Average is a very simple method to obtain a grayscale image, maybe also a naive (though working) one, but the lossy nature of the conversion is unavoidable. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Color to Gray space conversion is lossy by definition: RGB Color space allows 2^24 different values for color image pixels, while the constraint RGB(x,x,x) implies 2^8 different values for gray pixels. Thus we have a mapping of a 2^24 set to 2^8 set, i.e. a lossy mapping. Average is a very simple method to obtain a grayscale image, maybe also a naive (though working) one, but the lossy nature of the conversion is unavoidable. :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeI know that. but averaging u meantion cannot differentiate even very distinct colours RED, GREEN, BLUE. I personally don't believe that averaging is a solution. eventhough the actual solution is some sort of weighted average :)
modified on Thursday, February 21, 2008 5:52 AM
-
I know that. but averaging u meantion cannot differentiate even very distinct colours RED, GREEN, BLUE. I personally don't believe that averaging is a solution. eventhough the actual solution is some sort of weighted average :)
modified on Thursday, February 21, 2008 5:52 AM
Rajkumar R wrote:
but averaging u meantion cannot differentiate even very distinct colours RED, GREEN, BLUE.
The above is obviously true.
Rajkumar R wrote:
I personally don't believe averaging is a solution.
You're wrong. It is a quite acceptable solution, because (as I've already written) is a function mapping the color space set to the the grayspace one. It is also a reasonable mapping. Of course there are many possible solutions and the better one maybe application-dependent. Now a simple question: are you able to distinguish a full red from a full green in a B/W movie? Does it matter to the Director? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke -
Rajkumar R wrote:
but averaging u meantion cannot differentiate even very distinct colours RED, GREEN, BLUE.
The above is obviously true.
Rajkumar R wrote:
I personally don't believe averaging is a solution.
You're wrong. It is a quite acceptable solution, because (as I've already written) is a function mapping the color space set to the the grayspace one. It is also a reasonable mapping. Of course there are many possible solutions and the better one maybe application-dependent. Now a simple question: are you able to distinguish a full red from a full green in a B/W movie? Does it matter to the Director? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain ClarkeCPallini wrote:
distinguish a full red from a full green in a B/W movie? Does it matter to the Director?
lol !!! :laugh: , instead he can put black screen, save light energy. :)
-
CPallini wrote:
distinguish a full red from a full green in a B/W movie? Does it matter to the Director?
lol !!! :laugh: , instead he can put black screen, save light energy. :)
thanks all friends how to blur or mask a color image, actually i load a jpeg image to computer, now i would like to smooth via Gaussion function, but one of friend said i have to convert color image to grayscale image and then i can blur, so now i don't how to do? anyone has such code or suggestion? thanks a lot
Li Zhiyuan
-
dear all howt to convert color image to grayscale image in c++? anyone has such code? thanks a lot
Li Zhiyuan
-
thanks all friends how to blur or mask a color image, actually i load a jpeg image to computer, now i would like to smooth via Gaussion function, but one of friend said i have to convert color image to grayscale image and then i can blur, so now i don't how to do? anyone has such code or suggestion? thanks a lot
Li Zhiyuan
Image Processing for Dummies with C# and GDI+ Part 2 - Convolution Filters [^] although written in C#, it is easy to understand the gaussian blur implementation, i think it is not converting to greyscale before blur.
-
search for "MakeInactiveDemo" in codeproject he has a function to convert image to grayscale