[英]How can I “plot” an image on top of another image with a different colormap?
我有兩個圖像,一個100x100,我想用灰度繪制,一個20x20,我想用另一個色彩圖繪制。 后者應疊加在前者上。
這是我目前的嘗試:
A = randn(100);
B = ones(20);
imagesc(A);
colormap(gray);
hold on;
imagesc(B);
colormap(jet);
這有幾個問題:
colormap
更改所有像素的顏色。) 我怎樣才能解決這個問題?
我想要一個與此相似的效果,除了我的彩色疊加是矩形而不是褶皺:
只需更改它,以便為A傳遞完整且正確的顏色矩陣(即100x100x3矩陣),而不是讓它決定:
A = rand(100); % Using rand not randn because image doesn't like numbers > 1
A = repmat(A, [1, 1, 3]);
B = rand(20); % Changed to rand to illustrate effect of colormap
imagesc(A);
hold on;
Bimg = imagesc(B);
colormap jet;
要在其父軸中設置B圖像的位置,可以使用其XData和YData屬性,當此代碼完成時,這些屬性都設置為[1 20]。 第一個數字指定圖像中最左側/最高點的坐標,第二個數字指定圖像中最右側/最低點的坐標。 如果圖像與原始尺寸不匹配,它將拉伸圖像。
例:
xpos = get(Bimg, 'XData');
xpos = xpos + 20; % shift right a bit
set(Bimg, 'XData', xpos);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.