1

我在应用这种细化算法时遇到问题,我不知道提供的代码有什么问题。输出图像与阈值图像几乎相同。 阈值图像 瘦身后

非MaxSupp:

 %this function returns a boolean matrix to be multiplied with thresholded image(element wise)
 function [ marks ] = nonMaxSupp( mag,dir )
    [m,n]=size(mag);
    marks=uint8(ones(size(mag)));
    for i=2:m-1
        for j=2:n-1
            if mag(i,j) ~=0
               angle=dir(i,j)+180;
               if (angle>=340 || angle<=22.5) || (angle>=157.5 && angle<=202.5)  %horizontal
                if (mag(i,j+1)>mag(i,j)) || (mag(i,j-1)>mag(i,j))
                    marks(i,j)=0;
                end

            elseif (angle>22.5 && angle<=67.5) || (angle>202.5 && angle<=247.5) %45
                 if (mag(i+1,j+1)>mag(i,j)) || (mag(i-1,j-1)>mag(i,j))
                    marks(i,j)=0;
                 end
            elseif (angle>67.5 && angle<=112.5) || (angle>247.5 && angle<=292.5) %vertical
                 if (mag(i-1,j)>mag(i,j)) ||(mag(i+1,j)>mag(i,j))
                    marks(i,j)=0;
                end
            else %135
                 if (mag(i-1,j+1)>mag(i,j)) || (mag(i+1,j-1)>mag(i,j))
                    marks(i,j)=0;
                 end
            end
        end
    end 
end

end

坡度:

function [ mag,dir ] = gradient(I,h1,h2)
[m,n]=size(I);
mag=I;
dir=zeros(size(I));
for i=2:m-1
    for j=2:n-1
        x=convolution(h2,I(i-1:i+1 ,j-1:j+1));
        y=convolution(h1,I(i-1:i+1 ,j-1:j+1));
        mag(i,j)=sqrt(x^2 +y^2);
        dir(i,j)=(180*atan2(y,x)/pi);

    end
end
end
4

0 回答 0