Overlaying a contourf plot on a grayscale image

6 ビュー (過去 30 日間)
behzad
behzad 2018 年 10 月 18 日
編集済み: jonas 2018 年 10 月 20 日
Hi guys, I need to overlay a displacement contour of a deformed plate image (using contourf command) on its original grayscale undeformed image. How can I do that in matlab? Thank you

採用された回答

jonas
jonas 2018 年 10 月 18 日
編集済み: jonas 2018 年 10 月 18 日
You can use two linked axes with different colormaps. Example:
% Axes
ax(1)=axes('color','none','xcolor','none','ycolor','none');hold on
ax(2)=axes('color','none','xcolor','none','ycolor','none','ydir','reverse');hold on
linkaxes(ax,'xy')
axis([-3 3 -3 3])
% Contour data
[X,Y,Z] = peaks;
% Image
axes(ax(2))
I = imread('cameraman.tif');
imagesc(I,'XData',[min(X(:)) max(X(:))],'YData',[min(Y(:)) max(Y(:))]);
colormap(ax(2),'gray')
% Contour
axes(ax(1))
h = contour(X,Y,peaks);hold on
colormap(ax(1),'parula')
Just make sure the axes have the same position. If you create a colorbar "outside" of the axes area, then one axis will shrink. Usually I just create the colorbar "inside" and then move it outside by adapting its position properties.
  16 件のコメント
behzad
behzad 2018 年 10 月 20 日
Due to a black margin in the grayscale image, the two axes did not coincide. Fortunately I managed to solve the problem using the below command.
ax(1).Position = [...];
Thank you very much for your helps.
jonas
jonas 2018 年 10 月 20 日
編集済み: jonas 2018 年 10 月 20 日
My pleasure!
You could also try adding this argument to imshow
imshow(..., 'border', 'tight')
It should remove any extra space around the image.

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by