Reputation: 169
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:
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 :)
Upvotes: 2
Views: 170
Reputation: 112659
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.
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)
Upvotes: 3