MATLAB Answers

Overlay a plot on an image

76 views (last 30 days)
Fed
Fed on 8 Feb 2021
Commented: Fed on 11 Feb 2021
Hi,
I have to overlay a plot on a image. Here is my code:
Imm = imread('imageLeft.png');
figure()
imshow(Imm)
hold on
plot(pos_sensor_Lx,pos_sensor_Ly,'-o')
where Imm is the image (634x484x3 uint 8) while pos_sensor_Lx and pos_sensor_Ly are two column vectors 3487x1 double with values all normalized between [0;1].
When I plot the vectors and the image separately, I get this results:
Overlaying them, I ideally had to see the scan path well distribuited on the white and red dots of the image. Anyway when I overlay them I can't see the scan path over the image because of the very small values of the vector elements. Here the result I get:
All the values are clustered as shown.
Is there a way to adjust the image dimensions or the value of the vector elements to get the result I want?
Thank you
  4 Comments
Fed
Fed on 8 Feb 2021
Thank you for your answer.
How do you suggest to normalize the 2nd data respect to the 1st ones?
I would like to change the size of imageLeft so to have the same dimensions of the scan-path. In this way I could overlay them and see the data from the eye tracker on the first image.
It'd be great if it would be possible to represent imageLeft on the range [0.38 ; 0.46] for the x axis and [0.61 ; 0.67] for the y axis as in the scan - path

Sign in to comment.

Accepted Answer

Kiran Felix Robert
Kiran Felix Robert on 11 Feb 2021
Hi Federica,
Use the following code as an example to normalize your 2nd data based on the first and overlay it on the image.
Imm = imread('image.jpeg');
figure()
% Synthesis - [0,1] Normalized random data
P = rand(1,50); % -> X-variable
Q = rand(1,50); % -> Y-Variable
% Normalizing with respect to image pixels and quantizing
C = size(Imm)
P = uint16(P*C(1));
Q = uint16(Q*C(2));
% Overlay Plot
imshow(Imm)
hold on
plot(P,Q)
hold off
  1 Comment
Fed
Fed on 11 Feb 2021
Thank you so much!

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!