2010-12-11 41 views

回答

0

據我所知,OpenCV沒有「XOR擴張」(雖然這將是非常好的)。
爲了得到相似的結果,您可以嘗試侵蝕(如'd'),並使用被侵蝕的中心作爲Voronoi分割的種子,然後您可以與原始圖像進行「與」運算。

0

侵蝕和擴張後試圖閾值的圖像消除弱元素。只有強大的地區應該留下來,從而改善物體分離。順便說一下,您可以更清楚地瞭解您的cvDilate或cvErode問題。

1

看起來你需要編寫自己的擴張功能,然後自己添加xor功能。

每OpenCV的文檔,這裏是cvdilate使用規則:

DST =擴張(SRC,元素):DST(X,Y)= MAX((X 'Y')的元素)) SRC(X + X 'Y + Y')

這裏是一個起點僞代碼(這不包括XOR碼):

void my_dilate(img) { 

    for(i = 0; i < img.height; i++) { 
    for(j = 0; j < img.width; j++) { 
     max_pixel = get_max_pixel_in_window(img, i, j); 
     img.pixel(i,j) = max_pixel; 
    } 
    } 

} 

int get_max_pixel_in_window(img, center_row, center_col) { 
    int window_size = 3; 
    int cur_max = 0; 
    for(i = -window_size; i <= window_size; i++) { 
    for(j = -window_size; j <= window_size; j++) { 
     int cur_col = center_col + i; 
     int cur_row = center_row + j; 
     if(out_of_bounds(img, cur_col, cur_row)) { 
      continue; 
     } 
     int cur_pix = img.pixel(center_row + i, center_col + j); 
     if(cur_pix > cur_max) { 
      cur_max = cur_pix; 
     } 
    } 
    } 
    return cur_max; 
} 

// returns true if the x, y coordinate is outside of the image 
int out_of_bounds(img, x, y) { 
    if(x >= img.width || x < 0 || y >= img.height || y <= 0) { 
    return 1; 
    } 
    return 0; 
} 
+0

你能告訴我使用這個功能的「out_of_bounds (img,cur_col,cur_row)「。 如果你編寫它的僞代碼,這將是一件好事。 – RidaSana 2012-02-12 23:57:34