1

i have a problem in applying this thinning algorithm and I don't know what's the problem with the code provided.the output image is almost the same as the thresholded image. thresholded Image After thinning

nonMaxSupp:

 %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

gradient:

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
Haitham Khedr
  • 99
  • 2
  • 10
  • The code seems to be doing the job (there is some thinning). The problem is that you want *more* thinning? I do not know much about this algoritm, but have you tried iterating over it? call it 5 times and see who it goes. – Ander Biguri Aug 03 '15 at 10:27
  • It looks like the issue might lie in the way the images are stored or displayed because they seem very whitewashed. What is the data type for these matrices? If they're uint8, are many of the elements capped out at 255? If so, that may make nonmaxima suppression ineffective because every white pixel would be a local maximum. – NullPointerException Oct 06 '21 at 05:17

0 Answers0