# How to detect whether the object has triangular shape?

The task is to detect arrow from medical images. After segmenting, arrow-like objects can be connected with other connected components (noise). In this context, detecting a part of the object that characterizes an arrowhead would be a solution since template based shape descriptor does not perform well. Please help! enter image description here  ## 1 Answer

I think you can find the orientation of the arrow using principal component analysis (or fitting an ellipse and taking major/minor axis directions).

To locate the arrow head, use distance transform. You'll have to preprocess the image, like flood-filling the region. Because the arrow head base is usually the widest part of the image, you should get a peak there.

Now you can use this point along with the two orthogonal vectors calculated earlier. In the image below I've translated those vectors to go through the distance-transform peak(I didn't do any calculations, the image is just for illustration). The blue axis (second component in PCA or the minor axis of ellipse) now divides the image into two halves, and if you take projection of each half on to the blue axis, the half that contains the arrow head should give you a triangular profile (blue and orange profiles in the image below). EDIT

Another approach would be to use the distance transform peak to isolate the neighborhood of the arrow head. If we threshold the distance transformed image by some fraction of the peak value, for the arrow head we should still get a triangular shape. Now we can prepare a mask centered on the peak to extract this region. Below is a simple Matlab code that does this for a specific image:

im = imread('arrow.jpg');
gray = rgb2gray(im);
bw = im2bw(gray, graythresh(gray));
di = bwdist(bw);
[mx, mxidx] = max(di(:));
[ypeak, xpeak] = ind2sub(size(di), mxidx);
bw2 = di > mx*.5;
se = strel('disk', double(ceil(mx*1.5)), 0);
mask = zeros(size(bw2));
mask(ypeak, xpeak) = 1;
mask = imdilate(mask, se);
figure,
subplot(1, 3, 1), imshow(bw), title('binary')
subplot(1, 3, 2), imshow(bw2.*di, []), title('thresholded dist')
subplot(1, 3, 3), imshow(mask.*di.*bw2, []), title('masked')


And the result is: • Thanks a lot for such a nice suggestion. We are still having problem with the following arrow variants: a) curved arrows, arrow (just a triangle). In this context, detection triplet (from arrow head would be a possible solution). Thanks! – Santosee Aug 20 '14 at 14:11
• Anybody body has any idea of detecting arrowhead from an object? – Santosee Aug 21 '14 at 16:35
• Idea related to projection profiles: You can find the peak and area of the profile, then derive isosceles triangle having the same area and height. Now if you do a cross-correlation between the profile and the triangle, I think you should get a high similarity for triangular profile. – dhanushka Aug 22 '14 at 0:51
• @ Dhanushka, Do you think you get the peak from the curved arrows? or when other objects are connected at the tail? – Santosee Aug 22 '14 at 14:15
• Please edit your question and add a comment to the answer if you want to draw the attention. Do not edit an answer to ask another question. – dhanushka Sep 6 '14 at 10:46