Home > Software engineering >  What statistical image 256 kinds of color in the most times?
What statistical image 256 kinds of color in the most times?

Time:11-20

I thought is to iterate through the image, use map statistical color histogram, and then map sort by value, the final results, always feel to do so stupid, have bosses have other method

CodePudding user response:

No one,,,

CodePudding user response:

 
BMP "//"
Void CBmpColorsDlg: : OnButton1 ()
{
CWaitCursor wait;
CRect the rect.
//
GetClientRect (& amp; The rect);
The CDC * pDc=GetDC ();
The CDC dcMem.
DcMem. CreateCompatibleDC (pDc);
DcMem. SelectObject (& amp; M_img);//
PDc - & gt; BitBlt (0, 0, m_bmWidth m_bmHeight, & amp; DcMem, 0, 0, SRCCOPY);
//get all colors
STD: : vector ColorIndex;
For (int y=0; Y & lt; M_bmHeight; Y++)
{
For (int x=0; X & lt; M_bmWidth; X++)
{
COLORREF RGB=dcMem. GetPixel (x, y);
ColorIndex. Push_back (RGB);
}
}
//statistics all sorts of color number
Int Total=colorIndex. The size ();//m_bmHeight * m_bmWidth=253760;
//afxDump & lt; STD: : vector The list;
ListData temp (colorIndex [0], 0).//start from 0
List. The push_back (temp);//[0]=0 xfefefe; Len=4069
//color data analysis
Int N=1;
For (int I=0; i {//take out each colorIndex [I], with N see if the list [j]. Color of an equal
For (int j=0; J & lt; N; J++)
{
If (colorIndex [I]==a list [j]. Journal of color)//when I=0,==
{
The list [j] num++;
break;//the next I
}
If (j)==N - 1
{//if not equal, and it is colorIndex last one, is this colorIndex added to the list
ListData temp (colorIndex [I], 1);//start from 1
List. The push_back (temp);
N++;//for I next time & lt; The Total, more than a list [j]. Journal of color
break;//must! Otherwise; The Size!=Total
}
}
}
//
Cstrings num.
Int numMax=0;
Cstrings color;
Int Size=0;
Int colors=list. The size ();
M_ListBox. ResetContent ();
For (int jj=0; Jj{
Color. The Format (" 0 x % of 06 x ", the list [jj]. Color);
Size +=list [jj] num;
If (numMax & lt; List [jj] num) numMax=list [jj]. Num.
Num. The Format (" % d ", a list [jj] num);
+ num m_ListBox. AddString (color);
}
Color. The Format (" % d % d ", colors - 1, Size);
M_ListBox. AddString (color);
//66843-66612=231
If (the Size!=Total) AfxMessageBox (" Lost something?" );
TRACE1 (" % d ", numMax);//6215
//the draw color Histogram x, y num
//double kY=200.0/numMax;
//x
//# define top 500
//# define LFT fell 20
//pDc - & gt; MoveTo (LFT fell, top);
//pDc - & gt; The LineTo (LFT fell + 300, top);
//for (int kk=0; Kk & lt; Colors; Kk++)
//{
//pDc - & gt; MoveTo (LFT fell + kk, top);
//pDc - & gt; LineTo (LFT fell + kk, top - (int) (list) [r]. Kk num * kY));
//}
The ReleaseDC (pDc);
}

CodePudding user response:

Reply 2 floor, ListData is what? You define your own classes? I can't search

CodePudding user response:

refer to the second floor schlafenhamster response:
 
BMP "//"
Void CBmpColorsDlg: : OnButton1 ()
{
CWaitCursor wait;
CRect the rect.
//
GetClientRect (& amp; The rect);
The CDC * pDc=GetDC ();
The CDC dcMem.
DcMem. CreateCompatibleDC (pDc);
DcMem. SelectObject (& amp; M_img);//
PDc - & gt; BitBlt (0, 0, m_bmWidth m_bmHeight, & amp; DcMem, 0, 0, SRCCOPY);
//get all colors
STD: : vector ColorIndex;
For (int y=0; Y & lt; M_bmHeight; Y++)
{
For (int x=0; X & lt; M_bmWidth; X++)
{
COLORREF RGB=dcMem. GetPixel (x, y);
ColorIndex. Push_back (RGB);
}
}
//statistics all sorts of color number
Int Total=colorIndex. The size ();//m_bmHeight * m_bmWidth=253760;
//afxDump & lt; STD: : vector The list;
ListData temp (colorIndex [0], 0).//start from 0
List. The push_back (temp);//[0]=0 xfefefe; Len=4069
//color data analysis
Int N=1;
For (int I=0; i {//take out each colorIndex [I], with N see if the list [j]. Color of an equal
For (int j=0; J & lt; N; J++)
{
If (colorIndex [I]==a list [j]. Journal of color)//when I=0,==
{
The list [j] num++;
break;//the next I
}
If (j)==N - 1
{//if not equal, and it is colorIndex last one, is this colorIndex added to the list
ListData temp (colorIndex [I], 1);//start from 1
List. The push_back (temp);
N++;//for I next time & lt; The Total, more than a list [j]. Journal of color
break;//must! Otherwise; The Size!=Total
}
}
}
//
Cstrings num.
Int numMax=0;
Cstrings color;
Int Size=0;
Int colors=list. The size ();
M_ListBox. ResetContent ();
For (int jj=0; Jj{
Color. The Format (" 0 x % of 06 x ", the list [jj]. Color);
Size +=list [jj] num;
If (numMax & lt; List [jj] num) numMax=list [jj]. Num.
Num. The Format (" % d ", a list [jj] num);
+ num m_ListBox. AddString (color);
}
Color. The Format (" % d % d ", colors - 1, Size);
M_ListBox. AddString (color);
//66843-66612=231
If (the Size!=Total) AfxMessageBox (" Lost something?" );
TRACE1 (" % d ", numMax);//6215
//the draw color Histogram x, y num
//double kY=200.0/numMax;
//x
//# define top 500
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related