how measure major and minor axis of ellipse from image used matlab
17 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mushtaq Al-Jubbori
le 1 Déc 2019
Commenté : Mushtaq Al-Jubbori
le 7 Sep 2020
see a picture
3 commentaires
Réponse acceptée
Image Analyst
le 1 Déc 2019
Try this:
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
imtool close all; % Close all imtool figures if you have the Image Processing Toolbox.
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 22;
% Check that user has the Image Processing Toolbox installed.
hasIPT = license('test', 'image_toolbox');
if ~hasIPT
% User does not have the toolbox installed.
message = sprintf('Sorry, but you do not seem to have the Image Processing Toolbox.\nDo you want to try to continue anyway?');
reply = questdlg(message, 'Toolbox missing', 'Yes', 'No', 'Yes');
if strcmpi(reply, 'No')
% User said No, so exit.
return;
end
end
%===============================================================================
% Read in a color demo image.
folder = pwd;
baseFileName = '6.bmp';
% Get the full filename, with path prepended.
fullFileName = fullfile(folder, baseFileName);
if ~exist(fullFileName, 'file')
% Didn't find it there. Check the search path for it.
fullFileName = baseFileName; % No path this time.
if ~exist(fullFileName, 'file')
% Still didn't find it. Alert user.
errorMessage = sprintf('Error: %s does not exist.', fullFileName);
uiwait(warndlg(errorMessage));
return;
end
end
grayImage = imread(fullFileName);
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(grayImage);
if numberOfColorBands > 1
fprintf('This image is RGB. I will change it to gray scale.\n');
grayImage = grayImage(:, :, 2);
end
% Display the original image.
subplot(2, 2, 1);
imshow(grayImage);
axis('on', 'image');
title('Green Channel Image', 'FontSize', fontSize);
impixelinfo;
% Enlarge figure to full screen.
set(gcf, 'Units', 'Normalized', 'Outerposition', [0, 0.1, 1, 0.9]);
subplot(2, 2, 2);
imhist(grayImage);
grid on;
title('Intensity Histogram', 'FontSize', fontSize);
% It's gray scale. Threshold to create a binary image.
binaryImage = grayImage < 90; % or whatever value works.
subplot(2, 2, 3);
imshow(binaryImage, []);
axis('on', 'image');
title('Binary Image', 'FontSize', fontSize);
% Get rid of partial blobs leaving the field of view.
binaryImage = imclearborder(binaryImage);
% Get rid of blobs less than 500 in area.
binaryImage = bwareaopen(binaryImage, 500);
binaryImage = imfill(binaryImage, 'holes');
[labeledImage, numberOfblobs] = bwlabel(binaryImage);
% Apply a variety of pseudo-colors to the regions.
coloredLabelsImage = label2rgb (labeledImage, 'hsv', 'k', 'shuffle');
% Display the pseudo-colored image.
subplot(2, 2, 4);
imshow(coloredLabelsImage);
axis('on', 'image');
title('Filled Binary Image', 'FontSize', fontSize);
% Make measurements of area.
props = regionprops(binaryImage, 'Area', 'MajorAxisLength', 'MinorAxisLength')
allAreas = [props.Area]
majorAxisLength = [props.MajorAxisLength]
minorAxisLength = [props.MinorAxisLength]
msgbox('Done! lengths are in the command window.');
allAreas =
901 869 895 828 938 950 897 982 893 849 876
majorAxisLength =
Columns 1 through 5
42.3096288162948 41.4884349273287 42.8162935858843 41.2903546123474 42.7337289342248
Columns 6 through 10
44.1105808446811 42.0295867943025 38.2652632328308 42.4311889315166 41.8919530940952
Column 11
38.6585845668433
minorAxisLength =
Columns 1 through 5
27.4939460477342 27.0457380137077 27.0387459149836 26.0994881281772 28.1097891482489
Columns 6 through 10
27.8269540727149 27.5096530490088 32.7371049402545 27.2963558415452 26.2322961767191
Column 11
28.9929460861065
17 commentaires
Image Analyst
le 7 Sep 2020
So is the energy correlated with whether it has a substantial tail, or how fast the blob travels from frame to frame? And assuming you could measure various metrics about the shape, what is the equation for energy base on those metrics, like
energy = headRadiusOfCurvature - 10*tailRadiusOfCurvature + 4*feretDiameter + 189 * circularity; % or whatever.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Image Segmentation and Analysis dans Help Center et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!