Behind the scenes in the computer’s memory, color is always talked about as a series of 24 bits of information for each pixel. In an image, the color with the largest proportional area is called the dominant color. A strictly dominant color takes more than half of the total area. Now given an image of resolution M by N (for example, 800x600), you are supposed to point out the strictly dominant color.
dominant color 主色 M by N
输入描述:
Each input file contains one test case. For each case, the first line
contains 2 positive numbers: M (<=800) and N (<=600) which are the
resolutions of the image. Then N lines follow, each contains M
digital colors in the range [0, 224). It is guaranteed that the
strictly dominant color exists for each input image. All the numbers
in a line are separated by a space.
All the numbers in a line are separated by a space 空格分割每个数字
输出描述:
For each test case, simply print the dominant color in a line.
输出描述:
输入
5 3
0 0 255 16777215 24
24 24 0 0 24
24 0 24 24 24
输出
24
#include<iostream>
#include<map>
//using namespace std;
int main()
{
int m,n;
std::cin>>m>>n;
std::map<int,int>arr;//使用map映射 键为像素值, 值为该像素值出现的次数
int half = m*n/2;
for(int i=0;i<n;i++)
{
for(int j=0;j<m;j++)
{
int temp;
std::cin>>temp;
arr[temp]++;
if(arr[temp] > half)
{
std::cout<<temp;
return 0;
}
}
}
return 0;
}
本文探讨了如何通过分析图像中像素的颜色值来找出图像的主色。使用了一个24位颜色信息的数据结构,并通过遍历图像的每个像素,统计不同颜色出现的频率,最终确定了占据超过一半面积的严格主色。文章提供了详细的算法实现,包括输入输出的描述和C++代码示例。
335

被折叠的 条评论
为什么被折叠?



