Calculate the distance between objects area using matlab.

5 ビュー (過去 30 日間)
sombat supha
sombat supha 2020 年 1 月 5 日
コメント済み: Image Analyst 2020 年 1 月 5 日
I want to know the distance H (highest vertical) and L (longest horizontal) as shown in the picture A1.jpg in the white part. How to write a program using matlab?
image.jpeg
A1.jpg

採用された回答

darova
darova 2020 年 1 月 5 日
Use this
I1 = edge(I);
[m,n] = size(I1);
ldist = zeros(1,m);
for i = 1:m
ind = find(I1(i,:)); % find indices of boundary
if ~isempty(ind)
ldist(i) = max(ind)-min(ind); % find difference
else
ldist(i) = 0;
end
end
max(ldist) % longest distance
The same for longest height

その他の回答 (1 件)

Image Analyst
Image Analyst 2020 年 1 月 5 日
I gave you a compact solution there:
props = regionprops(binaryImage, 'BoundingBox', 'Perimeter');
width = props.BoundingBox(3); % Horizontal distance.
height = props.BoundingBox(4); % Vertical distance.
If you wanted to use find(), you can do it like this, rather than with a for loop
[rows, columns] = find(binaryImage);
width = max(columns) - min(columns);
height = max(rows) - min(rows);
Also you need to decide if width is counting pixels, or going from center to center of pixels. So, does this array [0, 1, 1, 1 , 0] have a width of 3 or 2? To answer, you might need to know the physics/optics of how your image was generated.
  2 件のコメント
sombat supha
sombat supha 2020 年 1 月 5 日
First your question
I want to know the size of the white space And you have answered. I accept.
In my question on this page
I want to know the distance H (highest vertical) and L (the longest horizontal) in the white area. I accept. Thank you very much for answering my question.
Image Analyst
Image Analyst 2020 年 1 月 5 日
In your other question you wanted to know the width and height (same as here) and perimeter. If you want to know the size (area) of the white region, you'll have to ask regionprops() for 'Area'.

サインインしてコメントする。

製品


リリース

R2015a

Community Treasure Hunt

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

Start Hunting!

Translated by