我正在尝试使用此代码根据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