Finding the Angle of Intersection of elements from two images

7 views (last 30 days)
I am trying to analyze the intersection points between two skeletonized, binary images.
An example of the two images that need to be compared are as below
First image:
Second image:
Using Imagej I can easily find where all the intersect points are.
However, what I need to do in Matlab is find where these two images intersect and find out at what angle they intersect.
There are many intersection points on each image so it can't be a "manual" process for each intersection.
Once I know the angle of intersection I need to be able to sort the intersection points based on the calculated angle.
Any help is much appreciated! Thanks!
Ari on 25 Jun 2015
Edited: Matt J on 25 Jun 2015
In each of the skeletonized images there are a bunch of lines and if you compare them they intersect at various points (which like you said can be found using the find function). Now, at the intersect point, I want to find the angle at which the line segment from one image intersects with a line segment from the other image (the intersect which caused the overlap). Thanks!

Sign in to comment.

Accepted Answer

Ashish Uthama
Ashish Uthama on 25 Jun 2015
Edited: Ashish Uthama on 26 Jun 2015
Attached an image (generated by imshowpair).
A rough off the top steps: (assumes the two images are available as logical matrices in im1 and im2)
  • Use find(im1&im2) to obtain intersection points
  • Since you dont have straight lines, pick a MxN window around a neighborhood of the intersection point to approximate the lines
  • Pad both images by M and N padarray
  • For each intersection point
  1. Extract an MxN region from each image
  2. Fit a line to each set of points in the MxN subregion (tons of ways to do this, search in this form or elsewhere)
  3. Determine the angle (tons of ways to do this, search in this form or elsewhere)
Some code to help you get started (I couldn't go further since there are a lot of 'edge' cases that your question does not clarify. The key issue is that the image doest really have 'line' segments, and I am not sure how best to approximate. For example - uncomment the two lines and inspect each nhood - you'll know what I mean)
function t
im1 = im2bw(imread('/tmp/1.jpg'));
im2 = im2bw(imread('/tmp/2.jpg'));
N = 10;
im1Pad = padarray(im1,[N N], 'both');
im2Pad = padarray(im2,[N N], 'both');
%%Find intersection points
[rInds, cInds] = find(im1Pad&im2Pad);
%%Extract (2N+1)x(2N+1) window about each intersection point
for ind=1:numel(rInds)
rInd = rInds(ind);
cInd = cInds(ind);
nhood1 = im1Pad(rInd-N:rInd+N, cInd-N:cInd+N);
nhood2 = im2Pad(rInd-N:rInd+N, cInd-N:cInd+N);
% imshowpair(nhood1,nhood2);
% pause
% Rest of the logic goes here

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!