finding the distance between points of boundaries
Mostra commenti meno recenti
Hi all,
I need help to find the distance between boundaries . I have attached my original microscopy image and the code I wrote to get the more clear boudaries of desired regions of that image . After that my problem is to find the distance between right most points of innner(green) and outer(Red) boundaries . Actually, I have to find the the distance between A and B points indicated in the resulting png.
It would be great if you share some ideas about writing codes for this measurement.
Thank you
Risposta accettata
Più risposte (1)
Matt J
il 26 Lug 2020
If you have the Statistics Toolbox, you can pdist2
D = pdist2(Red,Green)
7 Commenti
Babu Sankhi
il 26 Lug 2020
Modificato: Babu Sankhi
il 26 Lug 2020
Image Analyst
il 26 Lug 2020
That's no problem, but first we need to answer what distance(s) do you want? Do you want
- all distances (thousands of them) from every green point to every red point - all possible combinations (if so why?)
- or do you want the smallest distance that indicates how close the inner boundary comes to the outer boundary at its closest point?
Which is it?
Babu Sankhi
il 26 Lug 2020
Modificato: Babu Sankhi
il 26 Lug 2020
Do you mean I have to find the coordinates of red and green boundary by using toolbox
Yes, and from your posted attachments, you have clearly done that already. Since you only care about the horizontal coordinates, you can modify my initial solution to,
minDistance = pdist2(red(:,1), green(:,1),'cityblock','Smallest',1);
Babu Sankhi
il 26 Lug 2020
Modificato: Babu Sankhi
il 26 Lug 2020
Bruno Luong
il 26 Lug 2020
xred = boundary1(:,2);
xgreen = boundary2(:,2);
distance = max(xred) - max(xgreen);
Matt J
il 26 Lug 2020
But I have thousands of images to do that so using tool box for each is quiet time consuming/and allmost impossible.
The boundarycalculation.m routine that you attached takes about 0.02 sec on my machine once you remove all of the plotting commands. That should allow you to do thousands of images in about a minute or so - doesn't seem so bad to me.
Using the alternative version below, I was able to cut the time by about half. The imclose operations that I commented out may or may not be helpful in removing noise, and in any case don't add much overhead:
tic;
BW=bwareafilt(imbinarize (II),1);
%BW=imclose(BW,ones(3));
BWhole=bwareafilt(imfill(BW,'holes')-BW>0,1);
%BWhole=imclose(BWhole,ones(3));
[~,J]=find(BW);
[~,Jhole]=find(BW);
distance=max(J)-max(Jhole);
toc
%Elapsed time is 0.009772 seconds.
Categorie
Scopri di più su Purple in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
