Distance between the dots

조회 수: 3 (최근 30일)
Viswajit Talluru
Viswajit Talluru 2024년 8월 27일
편집: DGM 2024년 9월 17일
I want to calculate the distance between the top and bottom dot.
  댓글 수: 3
Viswajit Talluru
Viswajit Talluru 2024년 8월 27일
This is not for a homework. We heat the samples and just want to know if the samples expand or not. Just some number from picture to picture. Samples about 40 mm.
DGM
DGM 2024년 8월 27일
Without calibration information, the size of anything is ambiguous in absolute terms. I'm assuming that the camera is not fixed inside the oven, so if the object position, camera position or lens parameters change, then relative measurements are also ambiguous. What is the distance between the target and the back of the oven, relative to the distance between the target and the camera?
It's also not very sensible to use a single image to design a segmentation routine that needs to handle many other possibly different images. I say that because I see four irregular dots. I can't trust that the dots will be clearly defined in other images, given that one of the four is barely present in this image.

댓글을 달려면 로그인하십시오.

답변 (1개)

Aastha
Aastha 2024년 9월 16일
I understand that you are trying to find the distance between dots in the image that you have provided.
To accomplish this, I have assumed that the location of the cylinder is known and can be cropped out as part of the processing.
You may refer to the steps mentioned below to find the distance between the dots:
1. Import the cropped image into MATLAB using the “imread” function.
image = imread("image_cropped.jpeg");
figure(1);
imshow(image);
2. To isolate the dots, you can binarize the image using the “imbinarize” function in MATLAB. To binarize the image, first it should be converted to Gary scale using the “rgb2gray“ function.
if size(image, 3) == 3
grayImg = rgb2gray(image);
else
grayImg = image;
end
binaryImg = imbinarize(grayImg);
3. The binarization process yields artifacts in form of small specks which can be removed using an Erosion Filter. This can be done using the code snippet below:
se = strel('disk', 1);
erodedImg = imerode(binaryImg, se);
4. Once the image has been binarized and processed, you can find the location of the dots using the “bwconncomp” function that finds the connected components. This provides clusters which indicate all the pixels that are part of the dots. You may refer to the code snippet below to achieve this:
cc = bwconncomp(erodedImg);
minSize = 50;
largeComponents = find(cellfun(@numel, cc.PixelIdxList) >= minSize);
5. The distances between the dots can be seen as the distance between the centroids of the dots.Thus, you can first find the centroids of the dots using the connected components. Subsequently, the distance between the centroids can be computed using the code snippet below:
props = regionprops(filteredImg, 'Centroid');
centroids = cat(1, props.Centroid);
for i = 1:size(centroids, 1)
for j = i+1:size(centroids, 1)
dist = norm(centroids(i, :) - centroids(j, :));
line([centroids(i, 1), centroids(j, 1)], [centroids(i, 2), centroids(j, 2)], 'Color', 'cyan');
text((centroids(i, 1) + centroids(j, 1)) / 2, (centroids(i, 2) + centroids(j, 2)) / 2, sprintf('%.2f', dist), ...);
fprintf('Distance between centroid %d and %d: %.2f\n', i, j, dist);
end
end
centroids = cat(1, props.Centroid);
for i = 1:size(centroids, 1)
for j = i+1:size(centroids, 1)
dist = norm(centroids(i, :) - centroids(j, :));
line([centroids(i, 1), centroids(j, 1)], [centroids(i, 2), centroids(j, 2)], 'Color', 'cyan');
text((centroids(i, 1) + centroids(j, 1)) / 2, (centroids(i, 2) + centroids(j, 2)) / 2, sprintf('%.2f', dist), ...);
fprintf('Distance between centroid %d and %d: %.2f\n', i, j, dist);
end
end
I tried to find the distances between the dots using the steps mentioned above and I got the following result:
I hope this helps!
  댓글 수: 1
DGM
DGM 2024년 9월 17일
편집: DGM 2024년 9월 17일
Consider the two objects:
Can we do any of the following:
  • determine their diameters in mm?
  • determine the ratio of their diameters?
  • determine whether there even is any difference in diameter?
What if they were in the same photo?
Now at least we can compare them directly to each other, right? Can we tell how many different sizes are pictured?

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by