讀取多個Block內的像素到陣列 |
尚未結案
|
Yao
一般會員 發表:2 回覆:0 積分:0 註冊:2004-04-19 發送簡訊給我 |
各位好,目前我讀取2張jpg的圖片(連續的圖片),其中一張是I Frame,一張是P
Frame,我擷取I Frame中一個16*16 Block內的像素到陣列,從 P Frame中找到
I Frame 16*16 Block的相對位址,並以此Block上,下,左,右各8 pixels為擷取範
為,在此範圍中,以 16*16 為一個Block,每個Block一次移動一個pixel代表另一個Block,所以共有17*17個Block,但我不知如何將每個Block內的pixels值存入到陣列中再和I Frame中Block的pixels做運算,共得到17*17個值,再從中找出最小值,以下是我寫的範例:
import java.awt.*;
import java.lang.Math;
import java.awt.event.*;
import java.applet.*;
import java.awt.image.*; public class Compare extends java.applet.Applet {
Image pframe, block, pframeblock;
public void init(){
block=getImage(getDocumentBase(), "IFrame.jpg");
pframe=getImage(getDocumentBase(), "PFrame.jpg");
int [] p1 = new int [16*16];
int [] p2 = new int[16*16];
int x,y;
PixelGrabber blockpg = new PixelGrabber(block, 32, 32, 16, 16, p1, 0, 16);
try {
blockpg.grabPixels();
} catch (InterruptedException e) {}
for(x=24;x<40;x )
for(y=24;y<40;y )
for(j=0;j<289;j ){
PixelGrabber framepg = new PixelGrabber(pframe, x, y, 16, 16, p2[j], 0, 16);
}
try {
framepg.grabPixels();
} catch (InterruptedException e) {}
}
public static void compare(int[] p1, int[] p2) {
int [] min=new int[17*17];
int result = 0;
int i,j;
for (i=0; i<16*16; i )
for(j=0;j<289;j ){
result = result Math.abs(getred(p1[i])-getred(p2[i])) Math.abs(getgreen(p1[i])-getgreen(p2[i])) Math.abs(getblue(p1[i])-getblue(p2[i]));
min[j]=result;
float w=Math.min(min[j]);
System.out.println("The min is :" w);
}
}
public static int getred(int pixval) { // extracts the red value from the pixel
return (pixval >> 16) & 0xff;
}
public static int getgreen(int pixval) { // extracts the green value from the pixel
return (pixval >> 8) & 0xff;
}
public static int getblue(int pixval) { // extracts the blue value from the pixel
return (pixval ) & 0xff;
}
}
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |