Quantifying the floral trait in flower such as style length and opening/aperture of flower from x-ray image

2 次查看(过去 30 天)
I have been meaning to measure the style length of flower i.e blueberry flower from the x-ray image. can anyone suggest me the best way to measure the style length of flower and opening of flower?? The problem is with the orientation of flower when i extract each flower after normalisation some of them are orienting left or right not accurately upward.

回答(1 个)

Altaïr
Altaïr 2025-7-8
编辑:Altaïr 2025-7-8
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
I = imread('1996.jpg');
Igray = rgb2gray(I);
imageViewer(Igray)
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:
% Step 1: Read the image
img = imread('1996.jpg'); % Change to your filename
% Step 2: Convert to grayscale if not already
if size(img,3) == 3
grayImg = rgb2gray(img);
else
grayImg = img;
end
% Enhance contrast
grayImg = imadjust(grayImg);
% Step 3: Convert into binary image
bw = imbinarize(grayImg, 'adaptive', 'ForegroundPolarity', 'bright', 'Sensitivity', 0.3);
% Remove small objects (optional)
bw = bwareaopen(bw, 500);
% Step 4: Get region properties
props = regionprops(bw, 'BoundingBox', 'Centroid', 'MajorAxisLength', 'MinorAxisLength', 'Orientation');
% Step 5: Plot rectangles and ellipses on the original image
imshow(img, []); hold on;
for k = 1:length(props)
% Draw rectangle
rectangle('Position', props(k).BoundingBox, 'EdgeColor', 'r', 'LineWidth', 2);
% Draw ellipse
phi = linspace(0, 2*pi, 100);
x = (props(k).MajorAxisLength/2) * cos(phi);
y = (props(k).MinorAxisLength/2) * sin(phi);
% Rotation matrix
theta = deg2rad(-props(k).Orientation);
R = [cos(theta) -sin(theta); sin(theta) cos(theta)];
coords = R * [x; y];
% Center ellipse at centroid
plot(coords(1,:) + props(k).Centroid(1), coords(2,:) + props(k).Centroid(2), 'g', 'LineWidth', 2);
end
hold off;
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:
  1 个评论
Walter Roberson
Walter Roberson 2025-7-8
This distance can then be converted to physical units using the image's pixels-per-inch value.
Note that when present at all, EXIF information about image resolution is wrong much more often than it is right. It is typically set to a nominal resolution such as 100, rather than being set according to the actual source.
This particular image has
XResolution: 37.499995
YResolution: 37.499995
which is half of 74.9999, which seems a bit suspicious to me. I suspect that it is some nominal units rather than being truly 37 1/2 pixels per inch true resolution

请先登录,再进行评论。

标签

Community Treasure Hunt

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

Start Hunting!

Translated by