Find the actual distances in an image.

I want to find the minimum x(1) value which touches the image,A. Then maximum x(2) value which touches the image,A.(ps:image is attached). I made the axis ON. SO i want to let the program identify the x(min), x(max),y(min) and y(max), next draw straight lines(as shown in the image) along above said points(eg:x(1),x(2),etc) and then perform the spatial calibration (note; image is not symmetric). Can anyone give me a hint how to resolve this issue.

2 comentarios

Adam
Adam el 15 de Abr. de 2016
Where is your image coming from? And is it actually an image or a line plot? This kind of thing would usually just be calculated on the raw data that produces the image, but without knowing what format that is in it is hard to suggest clear solutions.
Chathu
Chathu el 15 de Abr. de 2016
it is an image. Let me add it here now. Sorry for the confusion.

Iniciar sesión para comentar.

 Respuesta aceptada

Mohammad Abouali
Mohammad Abouali el 15 de Abr. de 2016
Similar approach to this should work:
I=imread('P3290337.JPG');
I=padarray(I,[1 1 0],0);
thresh = 15;
mask = ~(I(:,:,1) < thresh & I(:,:,2) < thresh & I(:,:,1) < thresh);
xProj = any(mask);
xMin = find(xProj,1,'first')-0.5;
xMax = find(xProj,1,'last');
yProj = any(mask,2);
yMin = find(yProj,1,'first');
yMax = find(yProj,1,'last');
imshow(I);
hold on
plot([xMin xMin],ylim,'r','LineWidth',2)
plot([xMax xMax],ylim,'r','LineWidth',2)
plot(xlim,[yMin yMin],'r','LineWidth',2)
plot(xlim,[yMax yMax],'r','LineWidth',2)

4 comentarios

Chathu
Chathu el 15 de Abr. de 2016
Editada: Chathu el 16 de Abr. de 2016
Thank you so much, Mohammad. That works beautifully !!
Chathu
Chathu el 16 de Abr. de 2016
Mohammad Abouali, Thank you so much for your response but i have another small doubt to clarify( i will ask it here as it is related to this). Suppose i want to find distances of the x and y direction, at their intersections, should i just say , as below..
Euclidean Distance=sqrt ([x(max) - x(min)]^2 + [y(max) - y(min)]^2 )
By calculating the Euclidean distance, my objective is to find the real world coordinates along the x and y direction.
Kindly tell me whether that is correct? Thank you in advance.
Mohammad Abouali
Mohammad Abouali el 19 de Abr. de 2016
Editada: Mohammad Abouali el 19 de Abr. de 2016
If you need to know the real world coordinates then you need your image to be geo-referenced. Have a look at pix2map() function.
another easy solution is that if you know how wide are each pixel then you can multiply the Euclidiean distance in pixel unit by the size of each pixel and you get the distance in your requested unit. However, this is only good for short distances, If your image is covering large areas you can not use this method to compute the distance and you should use other methods. For example, if you are measuring the distance between to cities located in two different state you should not do this. Also this requires your image to be corrected for distortions so that all pixels do have same size.
Chathu
Chathu el 30 de Abr. de 2016
@ Mohammad, i saw your response just now. Your approach is perfect for my purpose, as it is short distance.
Thank you so much for your response. Highly appreciate it:)

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 16 de Abr. de 2016

1 voto

See my spatial calibration demo.

1 comentario

Chathu
Chathu el 16 de Abr. de 2016
Thank you so much Image Analyst. Highly appreciated.

Iniciar sesión para comentar.

Categorías

Más información sobre Images en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 15 de Abr. de 2016

Comentada:

el 30 de Abr. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by