Based on the query, the goal seems to be measuring the distance between two points in an image. There are a couple of methods available for this task:
Image Viewer approach
For a small number of images, the "Image Viewer" in MATLAB offers a straightforward solution:
1. Import the image using the following command
Converting the image to grayscale can enhance contrast and simplify the measurement process.
2. The CONTRAST tab in Image Viewer allows for adjusting image contrast. Using the "Measure Distance" option in the VIEWER tab, the pixel length between two points can be measured. This distance can then be converted to physical units using the image's pixels-per-inch value.
Further examples can be found on the documentation page:
Programmatic approach
For processing a larger number of images, a programmatic method is more efficient. The following example demonstrates how to use the "regionprops" function to identify and analyze features:
img = imread('1996.jpg');
grayImg = imadjust(grayImg);
bw = imbinarize(grayImg, 'adaptive', 'ForegroundPolarity', 'bright', 'Sensitivity', 0.3);
bw = bwareaopen(bw, 500);
props = regionprops(bw, 'BoundingBox', 'Centroid', 'MajorAxisLength', 'MinorAxisLength', 'Orientation');
imshow(img, []); hold on;
rectangle('Position', props(k).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
phi = linspace(0, 2*pi, 100);
x = (props(k).MajorAxisLength/2) * cos(phi);
y = (props(k).MinorAxisLength/2) * sin(phi);
theta = deg2rad(-props(k).Orientation);
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
plot(coords(1,:) + props(k).Centroid(1), coords(2,:) + props(k).Centroid(2), 'g', 'LineWidth', 2);
This code reads an image, converts it to grayscale, enhances contrast, and then binarizes it. After removing small objects, it uses regionprops to identify features and plots bounding rectangles and ellipses on the original image. When framing such logic, fine tuning the threshold values will be required based on specific image characteristics. The lengths of the major and minor axes of the ellipses, or the sides of the rectangles, can be used to estimate distances such as flower width or style length.
For additional information on measuring connected components in images, these resources may be useful: