Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
提取一个对象的Freeman链码-Matlab_Matlab_Image Processing_Contour_Chaincode - Fatal编程技术网

提取一个对象的Freeman链码-Matlab

提取一个对象的Freeman链码-Matlab,matlab,image-processing,contour,chaincode,Matlab,Image Processing,Contour,Chaincode,我正在尝试此代码以中的代码为基础生成freeman链代码,但它使用了DIPimage。因此,有人知道如何绕过dip_数组函数吗 代码: clc; 清除所有; 图像=rgb2gray(imread('https://upload-icon.s3.us-east-2.amazonaws.com/uploads/icons/png/1606078271536061993-512.png')); BW=imbinarize(图像); BW=填充物(BW,“孔”); BW=BWAREOPEN(BW,100

我正在尝试此代码以中的代码为基础生成freeman链代码,但它使用了DIPimage。因此,有人知道如何绕过dip_数组函数吗

代码:

clc;
清除所有;
图像=rgb2gray(imread('https://upload-icon.s3.us-east-2.amazonaws.com/uploads/icons/png/1606078271536061993-512.png'));
BW=imbinarize(图像);
BW=填充物(BW,“孔”);
BW=BWAREOPEN(BW,100);
BW=padarray(BW,60,60,'both')
BW=补码(BW);
imshow(BW)
[B,L]=BW边界(BW,'noholes');
%%%%%%%https://www.crisluengo.net/archives/324%%%%%
方向=[1,0
1,-1
0,-1
-1,-1
-1, 0
-1, 1
0, 1
1, 1];
indx=查找(倾斜阵列(img),1)-1;
sz=imsize(img);
起点=[楼层(indx/sz(2)),0];
start(2)=indx-(start(1)*sz(2));
cc=[];%链码
坐标=开始;%当前像素的坐标
dir=1;%起始方向
而1
newcoord=coord+directions(dir+1,:);

如果all(newcoord>=0)和&all(newcoord我不想翻译整个代码,我现在没有时间,但我可以给出一些建议:

  • dip_数组(img)
    使用
    dip_图像
    object
    img
    中的像素值提取MATLAB数组。如果在此处使用
    BW
    作为输入图像,只需删除对
    dip_数组
    的调用:
    indx=find(BW,1)-1

  • imsize(img)
    返回图像的大小
    img
    。MATLAB函数
    size
    是等效的(在这种特殊情况下)

  • dip_图像
    对象的尺寸与MATLAB数组的尺寸不同:它们的索引为
    img(x,y)
    ,而MATLAB数组的索引为
    BW(y,x)

  • dip_image
    对象的索引从0开始,而不是像MATLAB数组那样从1开始

最后两点改变了计算
开始的方式。我认为应该是这样的:

indx=find(BW,1);
sz=尺寸(BW);
起点=[1,楼层((indx-1)/sz(2))+1];
start(1)=indx-((start(2)-1)*sz(1));
但是使用
ind2sub
更容易(不确定我为什么在博客文章中做了明确的计算):

indx=find(BW,1);
sz=尺寸(BW);
开始=ind2sub(sz,indx);

出于同样的原因,您可能还想交换
方向的两列,并更改
all(newcoord>=0)&&all(newcoord0)&&all(newcoordDIPimage是免费提供的。您可以使用它。True。我在安装和安装中找不到该函数“要将dip_图像对象转换回MATLAB数组,请使用函数dip_数组”dip_数组的作用是什么?能否将其添加到上面的脚本中?
dip_数组
函数是
dip_图像
class()的一种方法。我在下面的答案中给出了一些提示,希望能帮助您翻译代码。
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