在MATLAB中防止颜色栏调整图像大小 [英] Prevent Color Bar from Resizing Image in MATLAB

查看:351
本文介绍了在MATLAB中防止颜色栏调整图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在MATLAB中向图像添加颜色条,而又不会丢失图形的原始分辨率.

I am trying to add color bars to an image in MATLAB without losing the original resolution of the figure.

此链接说明了如何处理添加彩条会调整原始图像的大小.但是,该解决方案通过使用插值法(从底部开始的第6行中使用的set方法)进行放大来制作原始的松散信息.对于我的应用程序来说,避免这种情况的发生至关重要(尝试观察摩尔纹对子采样的影响)

This link explains how to deal with the fact that adding a color bar resizes the original image. But the solution makes the original loose information by enlarging using interpolation (the set method used in the 6th line from the bottom). It is crucial to my application that this does not happen (Trying to observe Moire effects on sub-sampling)

我正在使用的代码附在下面

The code I am using is appended below

%% Load images using relative paths
path1 = '../data/circles_concentric.png';
path2 = '../data/barbaraSmall.png';
img1 = imread(path1, 'png');
img2 = imread(path2, 'png');
%Shrinking factor
d1 = 2;
d2 = 3;
img1_shrunk1 = myShrinkImageByFactorD(img1, d1);
imshow(img1_shrunk1);
colorbar(gca); 
img1_shrunk2 = myShrinkImageByFactorD(img1, d2);
figure, imshow(img1_shrunk2);
colorbar(gca);

推荐答案

我已经解决了这个问题,只需将颜色条放在单独的轴上即可.

I have dealt with this problem by simply putting the colorbar in a separate axis.

%Import image and colormap
[img,map]=imread('image.tif');

%Create figure and show the image on ax1
fig=figure;
ax1=axes(fig);
imshow(img,map,'Parent',ax1);

%Create ax2 and make it invisible
ax2=axes(fig,...
    'Position',[ax1.Position(1)+ax1.Position(3),ax1.Position(2),0.2,0.7]);
axis off
set(ax2,'color','none');

%Apply colormap to ax2 and, colorbar and adjust CLim
colormap(map);
colorbar(ax2,'Position',...
    [ax1.Position(1)+ax1.Position(3)+0.03,0.1,0.05,0.7],...
        'AxisLocation','in');
ax2.CLim=[minValue,maxValue];

这篇关于在MATLAB中防止颜色栏调整图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆