【发布时间】:2021-04-21 10:17:36
【问题描述】:
我正在尝试使用此代码根据https://www.crisluengo.net/archives/324 中的代码生成弗里曼链码,但它使用的是 DIPimage。因此,有人知道如何绕过 dip_array 函数吗?
代码:
clc;
clear all;
Image = rgb2gray(imread('https://upload-icon.s3.us-east-2.amazonaws.com/uploads/icons/png/1606078271536061993-512.png'));
BW = imbinarize(Image);
BW = imfill(BW,'holes');
BW = bwareaopen(BW, 100);
BW = padarray(BW,60,60,'both')
BW = imcomplement(BW);
imshow(BW)
[B,L] = bwboundaries(BW,'noholes');
%%%%%%%https://www.crisluengo.net/archives/324%%%%%
directions = [ 1, 0
1,-1
0,-1
-1,-1
-1, 0
-1, 1
0, 1
1, 1];
indx = find(dip_array(img),1)-1;
sz = imsize(img);
start = [floor(indx/sz(2)),0];
start(2) = indx-(start(1)*sz(2));
cc = []; % The chain code
coord = start; % Coordinates of the current pixel
dir = 1; % The starting direction
while 1
newcoord = coord + directions(dir+1,:);
if all(newcoord>=0) && all(newcoord<sz) ...
&& img(newcoord(1),newcoord(2))
cc = [cc,dir];
coord = newcoord;
dir = mod(dir+2,8);
else
dir = mod(dir-1,8);
end
if all(coord==start) && dir==1 % back to starting situation
break;
end
end
【问题讨论】:
-
DIPimage 是免费的。你可以使用它。
-
是的。我在安装中找不到该函数,并且由于“要将 dip_image 对象转换回 MATLAB 数组,请使用函数 dip_array”,dip_array 有什么作用?你能把它添加到上面的脚本中吗?
-
dip_array函数是dip_image类 (source) 的方法。我在下面的答案中发布了一些提示,希望能帮助您翻译代码。
标签: matlab image-processing contour chaincode