Distance between the dots

I want to calculate the distance between the top and bottom dot.

3 Comments

Distance in pixels or in real-world units? If the latter, when I display the image in my browser at 100% magnification it's about two and a half inches. If I zoom in to 150% magnification it's about three and three-quarters. Which one of those measurements do you consider correct? There's nothing in that image to give a different scale to indicate the size of the physical object that I assume was photographed to create this image. [Could you necessarily distinguish a picture of the real Eiffel Tower from a picture of a souvenir replica of the Eiffel Tower sold in a Paris gift shop?]
This sounds like it could be a homework assignment for an image processing course. If it is, show us the code you've written to try to solve the problem and ask a specific question about where you're having difficulty and we may be able to provide some guidance.
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.
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)

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

Products

Asked:

on 27 Aug 2024

Edited:

DGM
on 17 Sep 2024

Community Treasure Hunt

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

Start Hunting!