0

Im trying to create a program that finds images that are similar to each other and i found a site ( http://www.hackerfactor.com/blog/index.php?/archives/432-Looks-Like-It.html ) that gives steps for making a function that creates a fingerprint of an image, the first step is to reduce the size of the image to a 8 by 8 ( 64 pixel ) image, but i cant figure out how to convert a group of pixels into one pixel e.g.

[(R,G,B)][(R,G,B)][(R,G,B)]
[(R,G,B)][(R,G,B)][(R,G,B)]
[(R,G,B)][(R,G,B)][(R,G,B)]

take this group of pixels, each pixel has a diffrent R, G and B value, how can i take them all and turn them into one set of values e.g.

[(R,G,B)]

I thought maybe add all the R, G and B values up and then average them but that seemed to simple, dose anyone know how to do this ? i am writing this program in java.

4

1 に答える 1

1

ダウンスケーリングを行うには、さまざまな補間/再サンプリング手法が多数あります。期待する結果に応じて 1 つを選択できます。単純なもの、つまり最近傍補間です。しかし、これは単純であるため、非常に詳細な結果にはなりません。

写真が実際に写真である場合 (ピクセルアートではなく)、より高度な手法、つまり線形補間線形補間、または双三次補間が適しています。しかし、リンク内の縮小された画像にも詳細があまり残っていないため、(少なくとも最初は) Nearest Neighbor で十分に見えます。

public int[] resizePixels(int[] pixels,int w1,int h1,int w2,int h2) {
    int[] temp = new int[w2*h2] ;
    double x_ratio = w1/(double)w2 ;
    double y_ratio = h1/(double)h2 ;
    double px, py ; 
    for (int i=0;i<h2;i++) {
        for (int j=0;j<w2;j++) {
            px = Math.floor(j*x_ratio) ;
            py = Math.floor(i*y_ratio) ;
            temp[(i*w2)+j] = pixels[(int)((py*w1)+px)] ;
        }
    }
    return temp ;
}

この Java 関数は、ピクセル値の配列 (元のサイズ - w1 および h1) を受け取り、寸法が w2 x h2 の最近傍 (アップ/ダウン) スケーリングされたピクセルの配列を返します。こちらもご覧ください

于 2012-12-12T12:28:05.597 に答える