[英]How can I “plot” an image on top of another image with a different colormap?
I've got two images, one 100x100 that I want to plot in grayscale and one 20x20 that I want to plot using another colormap. 我有两个图像,一个100x100,我想用灰度绘制,一个20x20,我想用另一个色彩图绘制。 The latter should be superimposed on the former.
后者应叠加在前者上。
This is my current attempt: 这是我目前的尝试:
A = randn(100);
B = ones(20);
imagesc(A);
colormap(gray);
hold on;
imagesc(B);
colormap(jet);
There are a couple of problems with this: 这有几个问题:
colormap
changes the color of all pixels.) colormap
更改所有像素的颜色。) How can I fix this? 我怎样才能解决这个问题?
I want an effect similar to this, except that my coloured overlay is rectangular and not wibbly: 我想要一个与此相似的效果,除了我的彩色叠加是矩形而不是褶皱:
Just change it so that you pass in a full and proper color matrix for A (ie 100x100x3 matrix), rather than letting it decide: 只需更改它,以便为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;
To set the position of B's image within its parent axes, you can use its XData and YData properties, which are both set to [1 20] when this code has completed. 要在其父轴中设置B图像的位置,可以使用其XData和YData属性,当此代码完成时,这些属性都设置为[1 20]。 The first number specifies the coordinate of the leftmost/uppermost point in the image, and the second number the coordinate of the rightmost/lowest point in the image.
第一个数字指定图像中最左侧/最高点的坐标,第二个数字指定图像中最右侧/最低点的坐标。 It will stretch the image if it doesn't match the original size.
如果图像与原始尺寸不匹配,它将拉伸图像。
Example: 例:
xpos = get(Bimg, 'XData');
xpos = xpos + 20; % shift right a bit
set(Bimg, 'XData', xpos);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.