Matlab - 图像的缩放颜色条

时间:2017-08-08 14:44:24

标签: image matlab matlab-figure axes colorbar

如何缩放假彩色图像的[1 2 3 4 5 6]*10^4 轴?

我阅读了这篇文章,并复制了代码,但似乎无法正常工作:

MATLAB Colorbar - Same colors, scaled values

请参阅下面的两张图片。在第一个(没有缩放)coloraxis

[0.005 0.01 0.015 0.02 0.025]

在第二张图片中,它是

C = 100000

正确的缩放(使用[0.1 0.2 0.3 0.4 0.5 0.6] )将是

1/C

没有缩放 without scaling

缩放错误 wrong scaling

我希望C缩放coloraxis,我可以自由选择10^4,这样当像素值= C=10^610^-2时,比例应该显示{ {1}}。

我首先将我的图像乘以C的原因是为了获得更多的小数位数,因为低于1的所有值都将显示为零而没有C缩放。

当我运行代码时,我得到yticks作为工作空间变量,其中包含以下值:

[500 1000 1500 2000 2500]

我的代码:

RGB = imread('IMG_0043.tif');% Read Image 
info = imfinfo('IMG_0043.CR2'); % get Metadata
C = 1000000; % Constant to adjust image

x = info.DigitalCamera; % get EXIF
t = getfield(x, 'ExposureTime');% save ExposureTime
f = getfield(x, 'FNumber'); % save FNumber
S = getfield(x, 'ISOSpeedRatings');% save ISOSpeedRatings
date = getfield(x,'DateTimeOriginal');
I = rgb2gray(RGB); % convert Image to greyscale
K = 480; % Kamerakonstante(muss experimentel eavaluiert werden) 
% N_s = K*(t*S)/power(f,2))*L 
L = power(f,2)/(K*t*S)*C; %
J = immultiply(I,L); % multiply each value with constant , so the Image is Calibrated to cd/m^2 

hFig = figure('Name','False Color Luminance Map', 'ToolBar','none','MenuBar','none');
% Create/initialize default colormap of jet.
cmap = jet(16); % or 256, 64, 32 or whatever.
% Now make lowest values show up as black.
cmap(1,:) = 0;
% Now make highest values show up as white.
cmap(end,:) = 1;

imshow(J,'Colormap',cmap) % show Image in false color
colorbar % add colorbar

h = colorbar; % define colorbar as variable

y_Scl = (1/C);
yticks = get(gca,'YTick');

set(h,'YTickLabel',sprintfc('%g', [yticks.*y_Scl]))

ylabel(h, 'cd/m^2')% add unit label
title(date); % Show date in image
caxis auto % set axis to auto
datacursormode on % enable datacursor

img = getframe(gcf);
nowstr = datestr(now, 'yyyy-mm-dd_HH_MM_SS');

folder = 'C:\Users\Taiko\Desktop\FalseColor\';
ImageFiles = dir( fullfile(folder, '*.jpg') );
if isempty(ImageFiles)
    next_idx = 1;
else
    lastfile = ImageFiles(end).name;
    [~, basename, ~] = fileparts(lastfile);
    file_number_str = regexp('(?<=.*_)\d+$', basename, 'match' );  
    last_idx = str2double(file_number_str);
    next_idx = last_idx + 1;
end

newfilename = fullfile( folder, sprintf('%s_%04d.jpg', nowstr, next_idx) );

imwrite(img.cdata, newfilename);

1 个答案:

答案 0 :(得分:3)

问题:

1)您获得的数字YTickgca)但不是颜色条。这将为您提供图形的“像素”坐标,而不是实际值。使用yticks = get(h,'YTick');

2)caxis auto应该在覆盖YTicks之前(并在启用颜色条之后);否则比例和刻度将不匹配。

3)你的意思是C = 100000

结果:

enter image description here