finding x,y coordinates of tip ends in a binary image

1 view (last 30 days)
Hi, im trying to find coordinates for tips ends of a pacemaker in an x-ray image. I have thresholded the image and used corner detection to plot the areas im looking for. In most cases, one of the tip ends should be at a higher point than the other so i was thinking of raster scanning the image firstly from top to bottom and stopping at the first point of detection and similarly from bottom to top stopping at the first point of detection. Showing the coordinates of these points should give me the locations im looking for. My problem is....how do i do it?? This is my code so far, any help appreciated:
x= imread('pacemaker.png'); % Reading template image
x= im2double(x); % converts the image to numbers
x= rgb2gray(x); % convert from coloured to gray scale
subplot(2,2,1), imshow(x); % Sublotting the template image
title \bf\fontsize{11}'Pacemaker';
horsobel=[-1 0 1; -2 0 2; -1 0 1]; % using sobel filter for horizontal gradient
versobel=[-1 -2 -1; 0 0 0; 1 2 1]; % using sobel filter for vertical gradient
[m,n]= size(x); for i=1:m for j=1:n if x(i,j)<=.099 b(i,j)=0; else b(i,j)= 255; end end end
subplot(2,2,2),imshow(b);
title \bf\fontsize{11}'Thresholded image';
Ix= conv2(b,horsobel);
Iy= conv2(b,versobel);
G=[1 4 1; 4 7 4; 1 4 1]/27 % gaussian filter
Ixsq= Ix.^2; Ixsqg= conv2(Ixsq,G); Iysq= Iy.^2; Iysqg= conv2(Iysq,G); a=0.04; k=(Ixsqg).*(Iysqg); K1=(Ix.*Iy) k1g=conv2(K1,G); k1= k1g.^2; K2= (Ixsqg+Iysqg); k2= K2.^2;
K= k-k1-a.*(k2);
subplot(2, 2, 3),imshow(K); % Sublotting the gaussian filtered image
title \bf\fontsize{11}'Corner detection';
% To get the [x,y] coordinates of the pacemaker tip ends, lets assume that % the end of one tip is at a high point and the end of the other tip is at % a low point. Raster scanning from top to bottom picking up the first % point of image difference and south to north picking up the same % difference should give the coordinates of both tips.
H= size(K,1); % Image Height
W= size(K,2); % Image Width
for i=1:1:H % Scanning every row
for j=1:1:W % Scanning every column
end
end
for i=h=H:-1:1 % Scanning every row in reverse (i.e. from south to north)
for j=W:-1:1 % Scanning every column in reverse (i.e. from south to north)
end
end

Answers (0)

Categories

Find more on Images in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!