2012-12-05 69 views
3

我有一個包含一些點(或對象)的圖像。我想在此圖像上創建另一個圖像庫,以顯示與這些對象的距離。例如,這個新圖像應該在對象位置具有最大值。 matlab中有沒有解決方案?距離圖像到matlab中的對象

enter image description here

+0

什麼距離,是你想說明什麼? 「......與這些物體的距離」並不能說明你測量的是什麼。 – dustincarr

回答

6

可以使用bwdist對於這一點,其計算在二進制圖像從所述信號中的每個像素的距離。

%# read the image 
img = imread('http://i.stack.imgur.com/Hc7ay.png'); 
%# convert to grayscale 
gs = im2bw(img); 
%# segment the objects 
sig = gs~=1; 
%# remove the border 
sig = sig(5:end-4,5:end-4); 

%# calculate the distance 
distFromObjects = -bwdist(sig); 

enter image description here

+0

看起來像一個voronoi digram,不是嗎? – Acorbe

+0

是的,因爲這是如何定義voronoi圖:) – Jonas

+0

非常感謝喬納斯,但我如何控制半徑?在matlab和bwdist中沒有這樣的選項。 – Sam