Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
in the name of god

hi every body

i want to write an image processing project that i need quickly algorithm, but the code that i used is low. my code is :

C++
CImage i;
unsigned char gray[1000][1000];
i.Load(_T("1.jpg"));
for(int x=0;x<i.GetWidth();x++){
   for(int y=0;y<i.GetHeight();y++){
      COLORREF color=i.GetPixel(x,y);
      int ave=(GetRValue(color)+GetGValue(color)+GetBValue(color))/3;
      gray[x][y]=ave;
   }
}


can everyone help me?
thanks in advance
Posted

1 solution

Look here - it has a slow and fast method...
Converting Color to Grayscale Using ATL::CImage[^]
Here also has a more theoretic explanation of different approaches - it seems to me that avarage method should perform best...
http://www.johndcook.com/blog/2009/08/24/algorithms-convert-color-grayscale/[^]
 
Share this answer
 
Comments
Mahdi Nejadsahebi 3-Feb-14 1:45am    
dear friend
thanks for your answer
but i want to know what code is more faster from "GetPixel()" and "GetRValue()" functions to get color from image.
Kornfeld Eliyahu Peter 3-Feb-14 2:09am    
I see...
In that case you may consider one of these:
1. CImage::GetBits - you will get a pointer to the bits of the image as a continuous byte array, and you can move on it only by calculating indexes
2. CImage::GetColorTable/CImage::SetColorTable - it will enable you edit only the color table of the image without hitting the pixels at all

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900