2014-03-02 1 views
2

소벨 엣지 감지를 사용하여 이미지가 변조 된 방법을 감지해야합니다. 가장자리 필터를 구현할 수 있었지만 변조를 감지하는 데 사용하는 방법을 파악할 수 없었습니다. 훼손된 부분을 다른 색상으로 강조하여 변조를 보여주고 싶습니다.가공에서 소벨 에지를 사용하여 변조 감지

누군가 도와 줄 수 있습니까?

PImage img, edgeImg; 

int[][] sobelx = { { -1, -2, -1 }, { 0, 0, 0 }, { 1, 2, 1 } }; 

int[][] sobely = { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }; 

void setup() { 
    img = loadImage("face1.jpg"); 
    size(img.width, img.height); 
    edgeImg = createImage(img.width, img.height, RGB); 
} 

void draw() { 
    image(img, 0, 0); 
    int matrixsize = 3; 
    loadPixels(); 
    img.loadPixels(); 
    int loc = 0; 

    for (int x = 1; x < img.width - 1; x++) { 
     for (int y = 1; y < img.height - 1; y++) { 
      loc = x + y * img.width; 
      int sx = convolution(x, y, sobelx, matrixsize, img); 
      int sy = convolution(x, y, sobely, matrixsize, img); 
      int sum = abs(sy) + abs(sx); 
      sum = constrain(sum, 0, 255); 
      edgeImg.pixels[loc] = sum; 
     } 
    } 

    edgeImg.updatePixels(); 
    image(edgeImg, 0, 0); 
    filter(THRESHOLD, 0.8); 
} 

int convolution(int x, int y, int [][] mat, int matrixsize, PImage img) { 
    float rtotal = 0.0; 
    float gtotal = 0.0; 
    float btotal = 0.0; 
    int total = 0; 

    int offset = matrixsize/2; 

    for(int i=0; i<matrixsize; i++) { 
     for(int j=0; j<matrixsize; j++) { 

      int xloc = x + i - offset; 
      int yloc = y + j - offset; 

      int loc = xloc + img.width*yloc; 
      loc = constrain(loc,0,img.pixels.length - 1); 

      rtotal = rtotal + red(img.pixels[loc])*mat[i][j]; 
      gtotal = gtotal + green(img.pixels[loc])*mat[i][j]; 
      btotal = btotal + blue(img.pixels[loc])*mat[i][j]; 

      total = total + int(brightness(img.pixels[loc])*mat[i][j]); 
     } 
    } 

    rtotal = constrain(rtotal, 0, 255); 
    gtotal = constrain(gtotal, 0, 255); 
    btotal = constrain(btotal, 0, 255); 

    return total; 
} 
+0

소벨 엣지 검출만을 사용하면 정확한 일반 이미지 탬 퍼링 검출 알고리즘을 구현하는 것이 매우 어려울 수 있습니다. 이미지를 조작 할 수있는 방법에 제한이 있습니까? –

답변

0

나는 알고리즘이 특정 목적을 위해 이용 될 수 있는지 모르겠지만, 난 당신이 결과를 원래의 이미지에 동일한 필터를 실행하고 비교해야합니다 생각합니다.

PImage original = loadImage("face1.jpg"); 
PImage edgeImg;        // previously created 

original.loadPixels(); 
edgeImg.loadPixels(); 

for (int i=0; i<original.pixels.length; i++) { 
    color origPx = original.pixels[i]; 
    color edgePx = edgeImg.pixels[i]; 

    // compare red values, since the edgeImg is B&W 
    if ((origPx >> 16 & 0xFF) != (edgePx >> 16 & 0xFF)) { 
    // don't match? do something! 
    } 
}