Distance between the dots

3 views (last 30 days)
Viswajit Talluru
Viswajit Talluru on 27 Aug 2024
Edited: DGM on 17 Sep 2024
I want to calculate the distance between the top and bottom dot.
  3 Comments
Viswajit Talluru
Viswajit Talluru on 27 Aug 2024
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 on 27 Aug 2024
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.

Sign in to comment.

Answers (1)

Aastha
Aastha on 16 Sep 2024
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 Comment
DGM
DGM on 17 Sep 2024
Edited: DGM on 17 Sep 2024
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?

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!