Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 图像中的主要颜色_Java_Algorithm_Opencv_Colors - Fatal编程技术网

Java 图像中的主要颜色

Java 图像中的主要颜色,java,algorithm,opencv,colors,Java,Algorithm,Opencv,Colors,我想在一张图片中找到最真实的颜色。在Java/Android中 我有一个来自openCv的Mat对象,它引用了图像,我可以得到每个像素的RGB值 很容易,但我认为仅仅将红色、蓝色和绿色分别平均是不可行的算法 我认为最好将最频繁的{r,g,b}搜索为三元组 你同意吗? 你能帮我实现这个算法吗,我不知道!提前谢谢下面是一个做三重计数的伪代码 Hashmap<string,int> colors int max; string max_color; f

我想在一张图片中找到最真实的颜色。在Java/Android中 我有一个来自openCv的Mat对象,它引用了图像,我可以得到每个像素的RGB值 很容易,但我认为仅仅将红色、蓝色和绿色分别平均是不可行的算法

我认为最好将最频繁的{r,g,b}搜索为三元组

你同意吗?
你能帮我实现这个算法吗,我不知道!提前谢谢

下面是一个做三重计数的伪代码

    Hashmap<string,int> colors 

    int max;
    string max_color;

    for(int i=0;i<height;i++) {

      for(int j=0;j<width;j++) {

         int count = 0;
         string red = pixel[i][j].red.to_string;
         string green = pixel[i][j].green.to_string;
         string blue = pixel[i][j].blue.to_string;
         string key = red + "," + green + "," + blue;
         if(hashmap contains pixel[i][j]) {

             count = hashmap.get(key)
             count++;
             hashmap.write(key,count);
         }

         else {
           count = 1;
           hashmap.insert(key,count);  
         }

         if(count > max) {
            max = count;
            max_color = key;
         }

      }



    }

  res = max_color.split(',')

这不会像眼睛和大脑看到的那样,给你最真实的颜色。假设{0,0,0}出现在1000个像素上,990次{255,0,0},990次{254,1,0},990次{255,1,0},990次{255,0,1},还有990次{255,0,1},依此类推。你认为这行得通吗?你是将颜色范围定义为一种颜色,还是全部是256*256*256颜色