# 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

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);