使用rgb值对数组中的相似图像进行分组

时间:2017-09-21 01:27:06

标签: java cluster-analysis

我每秒从视频中提取帧并完成镜头边界检测。 现在我在聚类相似图像时遇到问题,我想使用这种Shot Clustering算法,我想在java中实现它,但在处理多维数组时遇到问题。

1)制作N个簇,每个镜头一个。

2)当2个群集之间的差异大于预定义阈值时停止。

3)在指定的时间限制(50秒)内找到最相似的一对簇R和S. 4)合并R和S(更具体地说,将S合并为R)。

5)转到第2步。

但我不知道如何在指定时间内在一个阵列中获得类似的图像。 谁有人可以帮忙? 这是我试图实现的代码。

  for(int i=1;i<files.length;i++){
           File fileIn=new 
File("C:\\Users\\PC\\Documents\\NetBeansProjects\\hamid\\"+i+".png");
         newimage.open_image(fileIn.toString());
        newimage.colour_histogram();
        float colorAv[]=newimage.get_colour_average();
        int sum=0;
        for(int j=0;j<colorAv.length;j++){
            sum+=colorAv[j];    //rgb value of each image
        }
        arr[i]=sum;
    }
    int[] res= new int[files.length];
    int count=0;
    res[count]=count+1;
    count++;
    for (int j=1;j<files.length;j++)
    {
        if(j>1){
        int dif = Math.abs(arr[j]-arr[j-1]); 
        if(dif>18){
        res[count]=j;
        count++;
        }
        }
    }
   System.out.println("Toral shots are"+count);
    for(int k=0; k<count;k++){
    }
    int shotdiff[]=new int[count];
   int i=0; 
            int j=0;
    int shots[][]= new int[count][count];
     int resp=0;
     int arr_count=0;
            shots[i][j]=res[resp];
            arr_count++;
            resp++;
       for(int array=0;array<count;array++){
           shotdiff[i]=Math.abs(arr[shots[i][0]]-arr[res[resp]]);
            if(shotdiff[i]<=18){
                j++;
                shots[i][j]= res[resp];
            resp++;
             }
            else {
            if(j==0){
                shots[i+1][j]= res[resp];
                resp++;
            arr_count++;
              }

     }          
        }

代码适用于存储前三个值,但第四个值必须存储在一个新数组中,因为它与之前的图像不相似。 rgb颜色直方图值。现在我在这一步遇到问题当与以前的值有不同的值时,如何添加新数组

0 个答案:

没有答案