📄 imuihist.m
字号:
function imuihist(varargin)
%IMUIHIST - Draw histogram of gray and rgb image
% Member of IMUI
% Kotaimen.C, 2002/05 - 2002/07, All Rights Reserved
if ~ischar(varargin{1})
CX = varargin{1};
Action = 'BuildGUI';
else
Action = varargin{1};
end
switch Action
case 'BuildGUI'
ud.fig = dialog( ...
'Position', [0 0 380 220], ...
'Name', 'Histogram', ...
'HandleVisibility', 'on', ...
'WindowStyle', 'modal', ...
'WindowButtonMotionFcn', 'imuihist(''MouseMotion'')', ...
'Visible', 'off');
ud.axes = axes( ...
'Units', 'pixel', ...
'Position', [10 50 256 128], ...
'Visible', 'on', ...
'Box', 'on', ...
'TickDir', 'out', ...
'XLim', [0 255], ...
'XTick', [0 127 255], ...
'YTick', [], ...
'FontSize', 8);
ud.pop = uicontrol(ud.fig, ...
'Style', 'popupmenu', ...
'Units', 'pixel', ...
'Position', [10 188 258 24], ...
'BackgroundColor', 'w', ...
'String', '', ...
'Callback', 'imuihist(''UpdateHistogram'')');
ud.close = uicontrol(ud.fig, ...
'Style', 'pushbutton', ...
'Units', 'pixel', ...
'Position', [290 188 72 24], ...
'FontWeight', 'bold', ...
'String', 'Close', ...
'Callback', 'delete(gcf)');
ud.info = uicontrol(ud.fig, ...
'Style', 'text', ...
'Units', 'pixel', ...
'Position', [10 5 256 20], ...
'FontName', 'Courier New', ...
'FontSize', 9, ...
'String', '...');
movegui(ud.fig, 'center')
if isrgb(CX)
[ud.L.hdata, x] = imhist(CX, 256);
[ud.R.hdata, x] = imhist(CX(:,:,1), 256);
[ud.G.hdata, x] = imhist(CX(:,:,2), 256);
[ud.B.hdata, x] = imhist(CX(:,:,3), 256);
set(ud.pop, 'String', ...
{'Luminance', 'Red', 'Green', 'Blue'})
else
[ud.L.hdata, x] = imhist(CX, 256);
set(ud.pop, 'String', ...
{'Luminance'}, 'Enable', 'off')
end
set(ud.fig, ...
'Visible', 'on', ...
'UserData', ud)
imuihist('UpdateHistogram')
case 'UpdateHistogram'
ud = get(gcf, 'UserData');
if ~isempty(allchild(ud.axes))
delete(allchild(ud.axes))
end
switch get(ud.pop, 'Value')
case 1
histdata = ud.L.hdata;
for i = 0 :255
line([i, i], [0.1, histdata(i + 1)], ...
'Color', [i i i]/255 *0.8);
end
case 2
histdata = ud.R.hdata;
for i = 0 :255
line([i, i], [0.1, histdata(i + 1)], ...
'Color', [i 0 0]/255);
end
case 3
histdata = ud.G.hdata;
for i = 0 :255
line([i, i], [0.1, histdata(i + 1)], ...
'Color', [0 i 0]/255);
end
case 4
histdata = ud.B.hdata;
for i = 0 :255
line([i, i], [0.1, histdata(i + 1)], ...
'Color', [0 0 i]/255);
end
end
case 'MouseMotion'
ud = get(gcf, 'UserData');
temp = get(ud.axes, 'CurrentPoint');
cpx = temp(1, 1);
cpy = temp(1, 2);
xlim = get(ud.axes, 'XLim');
ylim = get(ud.axes, 'YLim');
if all([cpx > xlim(1), cpx < xlim(2), ...
cpy > ylim(1), cpy < ylim(2)])
switch get(ud.pop, 'Value')
case 1
histdata = ud.L.hdata;
case 2
histdata = ud.R.hdata;
case 3
histdata = ud.G.hdata;
case 4
histdata = ud.B.hdata;
end
histlevel = round(cpx);
histcount = histdata(histlevel + 1);
set(ud.info, 'String', ...
sprintf('Level :%d, Count : %d', ...
histlevel, histcount));
set(gcf, 'Pointer', 'cross')
else
set(gcf, 'Pointer', 'arrow')
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -