选择最小化距离的像素

时间:2013-02-23 22:37:41

标签: matlab select pixel distance minimize

说我有以下两个矩阵:

>> x = [1 4 3; 6 4 3; 6 9 3; 2 4 3; 5 4 0; 5 3 1; 6 4 7];
>> y = [0 0 1; 1 1 0; 1 1 0; 0 1 1; 0.2 0.8 0.54; 1 1 1; 0 0 0];

您可以将x视为某个图片,将y视为某个感兴趣区域x的每个元素的成员资格

假设我将x中具有会员等级= 1的元素设置为1核心),将其他元素设置为0,如下所示:

x = zeros(size(y));
x(y==1) = 1;

在这种情况下,我将得到以下输出:

     0     0     1
     1     1     0
     1     1     0
     0     1     1
     0     0     0
     1     1     1
     0     0     0

现在,对于0的元素,我将其值替换为相应位置中y的值,如下所示:

x(x==0)=y(x==0);

现在,我选择4-neighbours core four_neighbourhood_pixels = imdilate(core, strel('diamond', 1)) - core; 但不在核心中的像素,如下所示:

p

我的问题是:我们如何选择属于four_neighbourhood_pixels的像素x,以最小化core&之间的距离。 pdist([x,core],'minkowski');

如果距离我计算如下:

x

前提是前一个命令中的zeros在用y取代会员值four_neighbourhood_pixels i后的相应位置后才是矩阵?

那么,如何选择属于x的像素,该像素最小化core与被替换为零的{{1}}之间的距离?

感谢。

1 个答案:

答案 0 :(得分:0)

如果我理解正确,core是以下矩阵:

 0     0     1
 1     1     0
 1     1     0
 0     1     1
 0     0     0
 1     1     1
 0     0     0

首先找到xcore之间的距离。

dist=pdist([x,core],'minkowski');
dist1=squareform(dist);
[row1,row2]=find(dist1==min(dist1(:)); %interpretation: you get the minimum distance  between row1 and row2 of [x core]

如果我的理解是正确的,请确认:

您希望x中的像素最小化距离dist,它应该属于four_neighbourhood_pixels。这是矩阵[x core]

 1     4     3     0     0     1
 6     4     3     1     1     0
 6     9     3     1     1     0
 2     4     3     0     1     1
 5     4     0     0     0     0
 5     3     1     1     1     1
 6     4     7     0     0     0

假设您获得第2行和第3行之间的最小值。现在基于此告诉我们你的意思是“找一个最小化的像素......”

相关问题