how to measure the shortest distance from a point to the edge ?

8 vues (au cours des 30 derniers jours)
Shan  Kapoor
Shan Kapoor le 4 Jan 2012
Hi All,
Can somebody help me how to measure the shortest length ( Perpendicular length) from the dots indicated inside black rectangle to the edge of the black portion on both sides in the following image ?? also, how to measure the shortest length between the points indicated in blue color??

Réponse acceptée

Walter Roberson
Walter Roberson le 6 Jan 2012
I see the black band, and I see scattered white dots. I do not see any blue points?
The shortest distance from a point (x,y) to the edge of the black is
min([x, width-x, y, height-y])
  2 commentaires
Shan  Kapoor
Shan Kapoor le 7 Jan 2012
Dear Walter,
Thank you your response...
I am very new to image analysis. I am sorry I do not know how to use the above function. here is my prolem to mathematically describe structures like below.
https://picasaweb.google.com/116243239493929305987/December292011#5694903096028938802
The two dots are the output of a simple matlab code to find the ultimate points ([trI,trJ] by the code below. and "tr2pkDists" are the distances from those points to the edges.
%---------------------------------------------------------
% Read the image and convert to BW mask of peaks
I_orig = imread('4.png');
figure, imshow(I_orig)
I = rgb2gray(I_orig);
BW_peaks = im2bw(I);
figure, imshow(BW_peaks)
% How far is every non-peak pixel from its nearest peak
maxDistsMask = imregionalmax(distFromPeaks);
[trI,trJ] = find(maxDistsMask);
trVals = I(maxDistsMask);
tr2pkDists = distFromPeaks(maxDistsMask)
I_norm = double(I)/double(max(I(:)));
figure, imshow(cat(3,I_norm,max(BW_peaks, I_norm),I_norm)), hold on
plot(trJ,trI,'.'),
% Now if we look at all of the maxdists in the image, how far away from
% peaks are they?
figure, plot(sort(tr2pkDists)), title 'Distribution of cusp spacing'
%-----------------------------------------------------------------------
as you can see, this is not enough as it does not give a total description.
right now I am here...
https://picasaweb.google.com/116243239493929305987/December292011#5694903944956708626
If I could do something like below, my issue is resolved...
https://picasaweb.google.com/116243239493929305987/December292011#5694903541436663602
ie, 1) find the shortest distance between the ultimate points.
2) find the shotest distances from point lying on the shrtest distance line from 1) to the edge of image ( to both sides, upper and lower)
and apply this method to images like below.
https://picasaweb.google.com/116243239493929305987/ImageAnalysis02#5691495061279679666
seek your suggestions.. Thanks you.
Shanoob
Image Analyst
Image Analyst le 7 Jan 2012
See my comment above regarding bwulterode() and bwdist().

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 5 Jan 2012
Use bwdist(). The max of the output image returned by bwdist() is the distance to the closest boundary. Of course this is all a guess since your link doesn't work and I can't see your image. Or use bwboundaries() and run around the boundary coordinates using Pythagorean theorem to find the distance to some know, fixed coordinate.
  3 commentaires
Image Analyst
Image Analyst le 6 Jan 2012
Really?
Image Analyst
Image Analyst le 7 Jan 2012
I see you finally posted the link below. Since the dots are the ultimate eroded set, which you can get from
ultimateErosion = bwulterode(originalBW);
The distance from any point, including those at the center of your circles, is given by bwdist(). I'm really puzzled as to why you think bwdist doesn't work for irregularly shaped objects. Did you try it? It does work. Just try it.

Connectez-vous pour commenter.

Community Treasure Hunt

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

Start Hunting!

Translated by