Overlaying Contour plot and png image
16 次查看(过去 30 天)
显示 更早的评论
Hello all,
I am looking to produce a contour plot with an image in the background denoting location points corresponding with the contours. I have scoured the MATLAB answers and other internet sources and have found many overlay methods, but am having trouble with scaling the image to the size of the contour plot figure.
I am combining the two figures:
and am getting the following with the contour in the far right corner:
If anyone may have some insight to this problem, I would be eternally grateful. Thank you for your time!
I have the following code:
figure
rotor = imread('turbdots.png');
imagesc([0 9],[0 21],rotor)
imshow(rotor)
hold on
contourf(Qww.Q4mat,'Showtext','on')
xlabel("z position")
ylabel("y position")
title("Q4")
set(gcf,'numbertitle','off','name','y vs z - ww contour')
0 个评论
回答(1 个)
Gaurav Ahuja
2017-5-16
It is difficult to identify the reason for obtaining the results shown by you, as there is no data provided to deal with. It would be helpful if you could share the image you want to overlay and elaborate on how did you obtain the contour for it, as your results suggest a miss match in the size of image and contour.
However, based on the description provided by you, following is kind of a kludge that should work for your use case. So I think the issue you were facing was because the 'contourf' was drawn on the same axis and axis for the figure was bigger.
Therefore we would try to follow the following order of steps
1) Draw the contour first
2) Note the range of axis (given by 'XLim' and 'YLim')
3) Hold on to current axis
4) Do 'imshow()' with the specification of the 'Xdata' and 'Ydata' as the range seen in step (2) (Xdata = XLim and Ydata = YLim) and preserve its handle.
5) Change the 'AlphaData' of ImageHandel to value between '0' and '1' (opaque) to adjust the transparency.
if true
% obtaining the contour plot and image data in some variable
Z = 10 + peaks; % to get contour
img = imread('coloredChips.png'); % image to overlay
% drawing contour and overlaing image
figure
[c,cont] = contourf(Z,2)
contP = get(cont,'Parent')
X = contP.XLim
Y = contP.YLim
hold on
imgh = imshow(img,'XData',X,'YData',Y)
imgh.AlphaData = .2
end
2 个评论
HARISH KUMAR
2023-1-23
@Gaurav Ahuja Hi, I am facing same kind of problem, i have image i cropped it, the place where i want do some image processing. i cropped it, did image processing, using that data i plotted contour. Now i want to place the contour plot to its orginal place (note : i should be able set transparency to that contour plot so that i can see my original image through contour).
Please guide me
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Contour Plots 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!