Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image 将选定像素的MATLAB缩放图像叠加到灰度图像_Image_Matlab_Overlay_Grayscale - Fatal编程技术网

Image 将选定像素的MATLAB缩放图像叠加到灰度图像

Image 将选定像素的MATLAB缩放图像叠加到灰度图像,image,matlab,overlay,grayscale,Image,Matlab,Overlay,Grayscale,我不熟悉MATLAB图像处理,目前我有两幅图像-一幅是我的对象的灰度图像,另一幅是使用imagesc函数从MATLAB生成的缩放图像。我试图在灰度图像上叠加这个缩放图像,以获得更容易观察的空间分辨率。附件为两张图片: A) 灰度图像: B) 缩放图像: 我遇到了一些困难。首先,缩放后的图像不会以相同的像素尺寸保存,但我可以使用imwrite函数绕过这一点: im = imagesc(ScaledDiff); imwrite(get(im,'cdata'),'scaleddiff.tif')

我不熟悉MATLAB图像处理,目前我有两幅图像-一幅是我的对象的灰度图像,另一幅是使用imagesc函数从MATLAB生成的缩放图像。我试图在灰度图像上叠加这个缩放图像,以获得更容易观察的空间分辨率。附件为两张图片:

A) 灰度图像:

B) 缩放图像:

我遇到了一些困难。首先,缩放后的图像不会以相同的像素尺寸保存,但我可以使用imwrite函数绕过这一点:

im = imagesc(ScaledDiff);
imwrite(get(im,'cdata'),'scaleddiff.tif')
但是,这样做将导致colorbar和colormap丢失。其次,即使我设法将缩放图像缩小到灰度图像的大小,覆盖它仍然是一个挑战。理想情况下,对于缩放图像值小于0.02的像素,我希望将透明度(或“alpha”)设置为0

任何关于如何做到这一点的想法都将不胜感激!对不起,我不清楚


更新: 多亏了Rotem,我成功地覆盖了灰度图像和热图的特定区域:

但是,我需要显示与热图值对应的颜色栏,因为否则信息将丢失,覆盖将无效。我该怎么做?下面是我的代码片段,其中ScaledIndiff包含热图上显示的0到0.25之间的值:

Brightfield = imread('gray.jpg'); % read background image
I1 = ind2rgb(gray2ind(Brightfield), gray); % convert indices into RGB scale

scale = 1000;
ScaledIntDiff2 = round(ScaledIntDiff.*scale); 
I2 = ind2rgb(ScaledIntDiff2, jet(256)); % this is for the heatmap

threshold = 0.02;
I2R = I2(:,:,1); I2G = I2(:,:,2); I2B = I2(:,:,3);
I1R = I1(:,:,1); I1G = I1(:,:,2); I1B = I1(:,:,3);
% Replace pixels in I2 with pixels in I1 if the value of ScaledIntDiff of those pixels is below the threshold
I2R(ScaledIntDiff<threshold) = I1R([ScaledIntDiff<threshold]);
I2G(ScaledIntDiff<threshold) = I1G([ScaledIntDiff<threshold]);
I2B(ScaledIntDiff<threshold) = I1B([ScaledIntDiff<threshold]);
I2(:,:,1) = I2R; I2(:,:,2) = I2G; I2(:,:,3) = I2B;

figure
imshow(I2) 
Brightfield=imread('gray.jpg');%读取背景图像
I1=ind2rgb(灰色2IND(亮场),灰色);%将索引转换为RGB比例
比例=1000;
scaledIndiff2=圆形(scaledIndiff.*比例);
I2=ind2rgb(标度为TDIFF2,jet(256));%这是热图
阈值=0.02;
I2R=I2(:,:,1);I2G=I2(:,:,2);I2B=I2(:,:,3);
I1R=I1(:,:,1);I1G=I1(:,:,2);I1B=I1(:,:,3);
%如果I2中的像素的ScaledIndiff值低于阈值,则将其替换为I1中的像素
I2R(标度dDiff检查以下各项:

I = imread('CKbi2Ll.jpg'); %Load input.

%Convert I to true color RGB image (all pixels R=G=B are gray color).
I1 = ind2rgb(I, gray(256));

%Convert I to true color RGB image with color map parula (instead of using imagesc)
I2 = ind2rgb(I, parula(256));

%Set the transparency (or 'alpha') to 0 for those pixels with < 0.02 in scaled image value.
%Instead of setting transparency, replace pixels with values from I1.
threshold = 0.02; %Set threshold to 0.02
I2(I1 < threshold) =  I1(I1 < threshold);

%Blend I1 and I2 into J.
alpha = 0.3; %Take 0.3 from I2 and 0.7 from I1.
J = I2*alpha + I1*(1-alpha);

%Display output
imshow(J);



第一条建议:不要使用
imagesc
,使用
ind2rgb
创建RGB图像。例如:
I=imread('cameran.tif');J=ind2rgb(I,parula(256));imshow(J)
。如果仍然需要调整图像大小,请使用:
imresize
。谢谢!它可以工作,但我需要显示色条来显示上述值(0到0.25)。你知道怎么做吗?你的意思是在色条中只显示
parula
colormap
colormap;
cm=parula(256);
cm=cm(1:64,:);
colormap(cm);
如果这不是你的意思,发布一个新问题。将问题最小化(特别询问关于显示颜色条的问题)。更清楚地了解“显示颜色条以显示以上(0到0.25)的值”的含义。这不是我的意思。如果你看我的原始帖子,在“B)缩放图像”下:,您可以在图片右侧看到颜色栏,范围从0到0.25。我想在叠加图像旁边显示此内容。我在原始帖子中提到,我希望保留颜色栏,因此我没有发布新问题。
colormap(parula(256));
TLabels = cellstr(num2str((linspace(0, 0.25, 6))'));
T = linspace(1, 250, 6);
colorbar('Ticks', T', 'TickLabels', TLabels);
imshow('ClmypzU.jpg');
colormap(jet(256));
TLabels = cellstr(num2str((linspace(0, 0.25, 6))'));
T = linspace(1, 250, 6);
colorbar('Ticks', T', 'TickLabels', TLabels);