Overlay a plot on an image
90 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Fed
el 8 de Feb. de 2021
Respondida: Ravi Kumar Pallantla
el 10 de Ag. de 2022
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/513052/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/513057/image.jpeg)
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/513077/image.jpeg)
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 comentarios
KALYAN ACHARJYA
el 8 de Feb. de 2021
Editada: KALYAN ACHARJYA
el 8 de Feb. de 2021
@Federica In the image, pixels are positioned based on Indices [0-r] and [0-c] in both in y and x direction. In the 2nd data, the values within 0-1, you may check for the normalize the 2nd data with repect to the 1st one?
Actually how do consider the maping of 2nd data with respect to image indices?
Respuesta aceptada
Kiran Felix Robert
el 11 de Feb. de 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
3 comentarios
Skylar Strickler
el 29 de Mzo. de 2022
Hey Kiran, what would I change to the code above to not only overlay the plot, but then to save that image with the overlayed plot as its own file?
Kiran Felix Robert
el 30 de Mzo. de 2022
Hi Skylar, just use the 'Get Current figure' and 'Saveas' function to save the figure.
For eg, add the following line after the last line of the above code, this will save the figure as a PNG file named 'saved'
saveas(gcf,'saved.png')
Más respuestas (1)
Ravi Kumar Pallantla
el 10 de Ag. de 2022
There is a script in file exchange to plot data on an image file. Hope it will be helpful to you.
0 comentarios
Ver también
Categorías
Más información sobre Image Processing and Computer Vision en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!