how can I plot a symmetry axis over an image in Matlab?

17 ビュー (過去 30 日間)
Ana
Ana 2023 年 4 月 1 日
回答済み: Amith 2023 年 4 月 27 日
how can I plot a symmetry axis over an image in Matlab using least square method?
  2 件のコメント
John D'Errico
John D'Errico 2023 年 4 月 1 日
Huh?
You have an image. I get that.
Now, apparently there is some line that passes through the image, on either side of which, the image is apparently symmetric? Symmetric in what way? I can think of several ways an image may be symmetric around a line. And the least squares problem would be different depending on how symmetry is interpreted.
May the line be at any angle? Any orientation? Or just vertical or horizontal?
And I'm not even positive this is the question you are asking.

サインインしてコメントする。

回答 (1 件)

Amith
Amith 2023 年 4 月 27 日
Hi,
As per my understanding you wanted to plot a symmetry axis over an image in Matlab using least square method.
To plot a symmetry axis over an image using the least square method, you can follow these general steps:
1. Load your image using the `imread` function and convert it to grayscale if it's a color image.
2. Choose two points on opposite sides of the axis you want to find. These points should be approximately equidistant from the axis.
3. Compute the equation of the line passing through these two points using the least square method. The equation should be in the form `y = ax + b`.
4. Plot the image using the `imshow` function and then plot the symmetry axis line using the `plot` function.
Here's some example code that demonstrates this process:
% Load the image
img = imread('myimage.jpg');
grayImg = rgb2gray(img);
% Choose two points on opposite sides of the axis
point1 = [100, 200]; % [x, y] coordinates of point 1
point2 = [300, 100]; % [x, y] coordinates of point 2
% Compute the equation of the line passing through the two points using least square method
x = [point1(1), point2(1)];
y = [point1(2), point2(2)];
A = [x', ones(size(x'))];
coeffs = A \ y';
a = coeffs(1);
b = coeffs(2);
% Plot the image and the symmetry axis line
figure;
imshow(grayImg);
hold on;
xCoords = linspace(1, size(grayImg, 2), 100);
yCoords = a*xCoords + b;
plot(xCoords, yCoords, 'LineWidth', 2, 'Color', 'r');
In this example, we first load an image and convert it to grayscale. We then choose two points on opposite sides of the axis and compute the equation of the line passing through them using the least square method. Finally, we plot the image using `imshow` and overlay the symmetry axis line on top of it using `plot`.
Note - that this method assumes that the image is symmetric with respect to the axis you want to find, and that the two chosen points are approximately equidistant from the axis. If these assumptions do not hold, the method may not produce accurate results.

カテゴリ

Help Center および File ExchangeImage Processing Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by