2013-11-02 48 views
0

我想對我獲得的數據應用kmeans聚類。在這裏,我附上了一個鏈接。請檢查。使用KMean對圖像進行分組

http://arxiv.org/ftp/arxiv/papers/0910/0910.1849.pdf

在這個環節中提供的算法,我已經做了,直到座截斷算法的3.2,即第4點。我不知道如何進一步進行。請幫助。代碼直到我已經實現的地方給出如下。它在Java中。

import java.awt.image.*; 
import java.io.File; 
import java.io.IOException; 
import javax.imageio.ImageIO; 
import java.util.ArrayList; 


public class BlockTruncation{ 

    public static void main(String[] args) throws IOException 
    { 
     BufferedImage bufImgs = ImageIO.read(new File("C://Users/Chandni/chandni's   pics/2013-04-06-1449.jpg")); 




     ArrayList<Integer> RH=new ArrayList<Integer>(); 
     ArrayList<Integer> RL=new ArrayList<Integer>(); 
     ArrayList<Integer> GH=new ArrayList<Integer>(); 
     ArrayList<Integer> GL=new ArrayList<Integer>(); 
     ArrayList<Integer> BH=new ArrayList<Integer>(); 
     ArrayList<Integer> BL=new ArrayList<Integer>(); 
     /* ArrayList RL[]=new int[15]; 
     int GH[]=new int[15]; 
     int GL[]=new int[15]; 
     int BH[]=new int[15]; 
     int BL[]=new int[15];*/ 

     int red[]=new int[(bufImgs.getWidth()* bufImgs.getHeight())]; 
     int green[]=new int[(bufImgs.getWidth()* bufImgs.getHeight())]; 
     int blue[]=new int[(bufImgs.getWidth()* bufImgs.getHeight())]; 
     int c=0; 

      for(int r=0;r<bufImgs.getWidth();r++) 
      { 
       for(int s=0;s<bufImgs.getHeight();s++) 
       { 
        int color = bufImgs.getRGB(r, s); 

        red[c]=(color>>16) & 0xFF; 
        green[c]=(color>>8) & 0xFF; 
        blue[c]=color & 0xFF; 

        c++; 

       } 
      } 
      double mean_pix[]=new double[3]; 
      mean_pix[0]=mean_no(red); 
      mean_pix[1]=mean_no(green); 
      mean_pix[2]=mean_no(blue); 

      for(int k=0;k<mean_pix.length;k++) 
      { 
       System.out.println(mean_pix[k]); 
      } 

      for(int p=0;p<red.length;p++) 
      { 
       if(red[p]<mean_pix[0]) 
       { 
        /*for(int q=0;q<RL.length;q++) 
        { 
         RL[q]=red[p]; 
        }*/ 
        RL.add(red[p]); 
       } 
       else 
       { 
        /* for(int q=0;q<RL.length;q++) 
        { 
         RH[q]=red[p]; 
        }*/ 
        RH.add(red[p]); 
       } 
      } 
      System.out.println("RH :"); 
      { 
       for(int g:RH) 
       { 
        System.out.println(g); 
       } 
      } 

      System.out.println("RL :"); 
      { 
       for(int g:RL) 
       { 
        System.out.println(g); 
        } 
       } 
      } 


    static double mean_no(int[] col) 
    { 
     double sum=0; 
     for(int rgb:col) 
     { 

      sum+=rgb; 

     } 

     return (sum/col.length); 
    } 

} 
+0

點號3.2.5實際上是指3.3中描述的步驟:K-Means *是一個聚類算法。我想你應該花一些時間來閱讀這個話題。 – Matt

回答

0

您需要閱讀更多文獻。特別是:

  • 顏色矩
  • K-均值聚類

沒有閱讀這些文獻,你就無法理解你鏈接的文章。