图像的情节出现偏移

发布于 2025-01-23 12:07:38 字数 642 浏览 0 评论 0原文

我正在尝试通过导入的图像绘制圆圈和直线a = b。该图出现了,但我遇到了两个问题:

  • 图像不是中心的 - 在这里,圆圈应该位于图像的中心,
  • 并带有倒置斜率

clear;close all;
I0 = imread('temp.png');
I1 = im2double(I0);
I = imresize(I1,[320 320]);
a=0:1:320;
b = a;

r=320/2;
xc=0; yc=0;
th = linspace( 0, 2*pi, 100);
x = r * cos(th) + xc;
y = r * sin(th) + yc;

figure,imshow(I)
hold on
plot(b,a,'linewidth',3)
hold on
plot(x,y,'white','linewidth',3)

sstatic.net/du3kn.png“ rel =“ nofollow noreferrer 通过绘制(b,-a,'lineWidth',3)而不是通过图像绘制的斜率。

任何帮助都将不胜感激。是的,这是用于作业的,但根本不是最终答案:)

I'm attempting to draw a circle and a straight line a=b over an imported image. The plot appears but I've run into two problems:

  • The image is not centered - here, the circle is supposed to be in the center of the image
  • The line appears with an inverted slope

enter image description here

clear;close all;
I0 = imread('temp.png');
I1 = im2double(I0);
I = imresize(I1,[320 320]);
a=0:1:320;
b = a;

r=320/2;
xc=0; yc=0;
th = linspace( 0, 2*pi, 100);
x = r * cos(th) + xc;
y = r * sin(th) + yc;

figure,imshow(I)
hold on
plot(b,a,'linewidth',3)
hold on
plot(x,y,'white','linewidth',3)

I can fix the slope of the line by plotting (b,-a,'linewidth',3) instead but the line does not draw over the image.

Any help would be much appreciated. Yes this is for an assignment but it would not the final answer at all :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

善良天后 2025-01-30 12:07:38
  1. 点(0,0)不是图像的中心。由于您使用imshow显示映像i,因此轴的大小为i,在您的情况下,0 320。因此,您需要根据此选择圆的中心。在下面的代码中,请参见带有注释%1的修改线。


  2. imshow设置轴 ij模式,用于倒入垂直轴的图像。要绘制该行通常,您可以设置XY模式。请参阅“代码”中的注释%2的添加行。

clear;close all;
I0 = imread('temp.png');
I1 = im2double(I0);
I = imresize(I1,[320 420]);
a=0:1:320;
b = a;

r=320/2;
xc = size(I, 2)/2; yc = size(I, 1)/2;    %1
th = linspace( 0, 2*pi, 100);
x = r * cos(th) + xc;
y = r * sin(th) + yc;

figure,imshow(I)
hold on
axis xy                                  %2
plot(b,a,'r','linewidth',3)
hold on
plot(x,y,'white','linewidth',3)
  1. The point (0,0) is not the center of the image. Since you are displaying the image I with imshow, the axes will have the size of I, in your case from 0 to 320. So you need to choose the center of the circle based on that. See modified line with comment %1 in the code below.

  2. imshow sets the axis ij mode, used for images, which inverts the vertical axis. To plot the line normally you can set the xy mode. See added line with comment %2 in the code.

clear;close all;
I0 = imread('temp.png');
I1 = im2double(I0);
I = imresize(I1,[320 420]);
a=0:1:320;
b = a;

r=320/2;
xc = size(I, 2)/2; yc = size(I, 1)/2;    %1
th = linspace( 0, 2*pi, 100);
x = r * cos(th) + xc;
y = r * sin(th) + yc;

figure,imshow(I)
hold on
axis xy                                  %2
plot(b,a,'r','linewidth',3)
hold on
plot(x,y,'white','linewidth',3)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文