how can I plot a graph over an image in Matlab?

410 ビュー (過去 30 日間)
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS 2022 年 6 月 30 日
コメント済み: Adam Danz 2022 年 7 月 5 日
I want to plot the graph over the 1st image.

採用された回答

Kevin Holly
Kevin Holly 2022 年 6 月 30 日
Load Example Image
exampleimage = imread('peppers.png');
Flip the image vertically (y-axis direction will be flipped vertically later)
exampleimage = flipud(exampleimage);
Display image
imshow(exampleimage)
Use hold on so more children can be added to the axes
hold on
Create scatter plot
x=1:20:300;
y=x;
scatter(x,y,'filled','w')
Change y-dir to normal (Note, y-dir is upside down when images are displayed by default)
set(gca,'YDir','normal') %gca stand for get current axes
  6 件のコメント
Rik
Rik 2022 年 7 月 5 日
Do you want to put them in subplots, or do you want to put all images in the same axes?
Adam Danz
Adam Danz 2022 年 7 月 5 日

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

その他の回答 (2 件)

Adam Danz
Adam Danz 2022 年 6 月 30 日
Plot the image using image or imagesc or some other image function that allows you to specify the x and y values of the image. That way you set the image coordinates to the data coordinates.
Then just hold on and plot the data into the same axes.
Note that image functions flip the y axis so you may need to flip it back to normal using set(gca, 'YDir','Normal') or flip your data when you plot it.
If you have additional questions, share the code you've got so far and let us know specificially where you're stuck.
  2 件のコメント
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS 2022 年 6 月 30 日
a=imread('F:\Google drive\6.Internship\surge\Core Internship\IMG_0.jpg');
b=imread('F:\Google drive\6.Internship\surge\Core Internship\IMG_20.jpg');
c=a(:,:,3)-b(:,:,3);
imadjust(c);
H=fspecial("average",10);
cAvg=imfilter(c,H);
max(max(c));
min(min(c));
no_row=size(c,1);
no_col=size(c,2);
Xbox=50;
P=floor(no_col/Xbox);
k=zeros(1,4857);
x=linspace(1,Xbox,Xbox);
q=zeros(453,4857);
y=linspace(1,Xbox,Xbox);
for i=1:453
for j=1:4857
if cAvg(i,j)>10
q(i,j)=cAvg(i,j);
else
q(i,j)=5;
end
end
end
l=zeros(45,Xbox);
for m=1:45
for n=1:Xbox
l(m,n)=mean(mean(q(((m-1)*10+1):10*m,((n-1)*24+1):P*n)));
end
end
for i=1:Xbox
p=l(:,i);
for j=1:45
if p(j)>=10
o(i)=j;
break
else o(i)=45;
end
end
end
for i=1:Xbox
v=((45-o)*20)/45;
end
plot(y,v,'Bx')
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS 2022 年 6 月 30 日
For the graph and the image, the y-axis values are opposite to each other.

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


Rik
Rik 2022 年 6 月 30 日
You need to use the same axes. The easiest solution is to use hold, probably the line below will already do what you need:
hold(gca,'on')
  1 件のコメント
DARSHAN KUMAR BISWAS
DARSHAN KUMAR BISWAS 2022 年 6 月 30 日
a=imread('F:\Google drive\6.Internship\surge\Core Internship\IMG_0.jpg');
b=imread('F:\Google drive\6.Internship\surge\Core Internship\IMG_20.jpg');
c=a(:,:,3)-b(:,:,3);
imadjust(c);
H=fspecial("average",10);
cAvg=imfilter(c,H);
max(max(c));
min(min(c));
no_row=size(c,1);
no_col=size(c,2);
Xbox=50;
P=floor(no_col/Xbox);
k=zeros(1,4857);
x=linspace(1,Xbox,Xbox);
q=zeros(453,4857);
y=linspace(1,Xbox,Xbox);
for i=1:453
for j=1:4857
if cAvg(i,j)>10
q(i,j)=cAvg(i,j);
else
q(i,j)=5;
end
end
end
l=zeros(45,Xbox);
for m=1:45
for n=1:Xbox
l(m,n)=mean(mean(q(((m-1)*10+1):10*m,((n-1)*24+1):P*n)));
end
end
for i=1:Xbox
p=l(:,i);
for j=1:45
if p(j)>=10
o(i)=j;
break
else o(i)=45;
end
end
end
for i=1:Xbox
v=((45-o)*20)/45;
end
plot(y,v,'Bx')

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

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by