Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.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
Matlab 如何找到分支的某些像素的方向?_Matlab_Orientation - Fatal编程技术网

Matlab 如何找到分支的某些像素的方向?

Matlab 如何找到分支的某些像素的方向?,matlab,orientation,Matlab,Orientation,通过为问题创建的代码,我向您展示了我的问题示例,其中我是0和1的矩阵对。你说一个人得到的图像代表一个骨架的两个分支。正如您所看到的,两个分支的某些像素似乎处于相同的方向。我想做的是,取每个分支的3×3像素,比较它们的方向角,如果两个分支的方向相同,那么用1填充分隔像素的空间 I=zeros(20,20); I(1,15)=1; I(2,14)=1; I(3,13)=1; I(1,16)=1; I(4,12)=1; I(7,9)=1; I(8,8)=1; I(9,7)=1; I(9,6)=1;

通过为问题创建的代码,我向您展示了我的问题示例,其中我是0和1的矩阵对。你说一个人得到的图像代表一个骨架的两个分支。正如您所看到的,两个分支的某些像素似乎处于相同的方向。我想做的是,取每个分支的3×3像素,比较它们的方向角,如果两个分支的方向相同,那么用1填充分隔像素的空间

I=zeros(20,20);
I(1,15)=1; I(2,14)=1; I(3,13)=1; I(1,16)=1;

I(4,12)=1;
I(7,9)=1;
I(8,8)=1;
I(9,7)=1;
I(9,6)=1;
I(9,5)=1;
I(10,4)=1;

CC=bwconncomp(I); 
I=labelmatrix(CC); %Labeling of branches

imagesc(I) % figure of problem
I(5,11)=1;
I(6,10)=1;

figure, imagesc(I) % figure of solution that I search

我比较了每个分支边的1次多项式系数:

% generate branches image
I=zeros(20,20);
I(1,15)=1; I(2,14)=1; I(3,13)=1; I(1,16)=1;
I(4,12)=1;
I(7,9)=1;
I(8,8)=1;
I(9,7)=1;
I(9,6)=1;
I(9,5)=1;
I(10,4)=1;
% find connected components
CC=bwconncomp(I);
% get xy coords of connected components
[Y,X] = cellfun(@(ind) ind2sub(size(I),ind),CC.PixelIdxList,'UniformOutput',0);
% get 1st degree polynomial coeffs for each component edges
p1 = cellfun(@(x,y) polyfit(x(1:2),y(1:2),1),X,Y,'UniformOutput',0);
p2 = cellfun(@(x,y) polyfit(x(end-1:end),y(end-1:end),1),X,Y,'UniformOutput',0);
% compare polynomial coefficients
D = pdist2(cell2mat(p1'),cell2mat(p2'));
% find "close" coefficient values
D = D + eye(size(D));
EPS = 1e-3;
[idx1,idx2] = find(D < EPS);
A = zeros(size(I));
[xg,yg] = meshgrid(1:20);
for ii = 1:numel(idx1)
    % chosen poly coeffs
    p = p1{idx1(ii)};
    % relevant xy values
    yy = polyval(p,xg);
    xx = [X{idx1(ii)}(1)+1:X{idx2(ii)}(end)-1 X{idx2(ii)}(end)+1:X{idx1(ii)}(1)-1];
    % fill missing pixels
    A = A + (CC.NumObjects + 1 + ii)*((abs(yy - yg) < EPS) & ismember(xg,xx));
end
subplot(121);
I = labelmatrix(CC); %Labeling of branches
imagesc(I) % figure of problem
subplot(122);
I2 = double(I) + A;
imagesc(I2) % figure of solution that I search

谢谢你的回答。你能告诉我什么是EPS吗?是否可以做同样的事情,但只考虑分支的某些像素?对于我的一些分支,系数会有所不同,因为我们考虑了整个分支,但是如果我们在分支的末尾只考虑两到三个像素,那么在比较中,系数可能相等。EPS只是一个小数字,有助于找到非常接近的系数。目前,它只针对每个分支边缘的两个像素执行,因此这就是您所要求的。当我在整个骨架上运行您的解决方案时,缺少几个像素来填充它只会显示最后找到的像素,我不明白为什么:-0 A=A+CC.numbjects+1+ii*absyy-yg