Ellipse angle dimension and axis
1 回表示 (過去 30 日間)
古いコメントを表示
Hi
I need help with fitting automatically to ellipse. (
I have a photo of a spot from a camera. (added A=imread of the file in the matlab.mat file, can see the photo as imagesc(double(A)))
Each pixel has some kind of dimention (for example 150um , 150e-6)
How can i find the main axis of the ellipse in the photo? (need also to align it to pixel size so angle is a must)
Also, made fourier on it
Y=fftshift(fft2(double(A)))
and when looking at the fourier image, how can i do the same fit there around 0? (in the fourier we also have an angled shape).
*note that i need to have automatic finding of the result. not by hand as each photo will be different.
0 件のコメント
回答 (1 件)
Image Analyst
2021 年 9 月 29 日
編集済み: Image Analyst
2021 年 9 月 29 日
Try this. You might also want to take a look at bwferet().
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'matlab.mat';
s = load(fileName)
grayImage = s.A;
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the red channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 1);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 2, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
grayImage(grayImage == 1) = 255;
lowThreshold = 3445;
highThreshold = inf;
%[lowThreshold, highThreshold] = threshold(lowThreshold, highThreshold, grayImage);
mask = grayImage >= lowThreshold & grayImage <= highThreshold;
% Display the image.
subplot(2, 2, 2);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Take largest blob.
mask = bwareafilt(mask, 1);
% Fill holes
mask = imfill(mask, 'holes');
% Display the image.
subplot(2, 2, 3);
imshow(mask, []);
impixelinfo;
axis('on', 'image');
title('Mask Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Make measurements.
props = regionprops(mask, 'Centroid', 'Orientation', 'MajorAxisLength');
xCenter = props.Centroid(1);
yCenter = props.Centroid(2);
hold on;
plot(xCenter, yCenter, 'r+', 'LineWidth', 2);
% Find endpoints of line along major axis.
radius = props.MajorAxisLength / 2;
x1 = xCenter - radius * cosd(props.Orientation)
y1 = yCenter + radius * sind(props.Orientation)
x2 = xCenter + radius * cosd(props.Orientation)
y2 = yCenter - radius * sind(props.Orientation)
plot([x1, x2], [y1, y2], 'r-', 'lineWidth', 2)
3 件のコメント
Image Analyst
2021 年 10 月 2 日
It should work on the Fourer transform image also. Not sure how identifying the oval and drawing a line along the major axis would cancel some of the noise though. If you erased the transform outside the oval then inverse transformed, it would reduce high frequencies (which may be noise). To do that on the real part you'd do
ftReal(~mask) = 0; % Erase outside the mask on the real image part of the Fourier transform.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!