📄 idisp.m
字号:
function idisp(z, clip, ncmap)
%IDISP Interactive image display tool
%
% IDISP(image)
% IDISP(image, clip)
% IDISP(image, clip, n)
%
% Display the image in current figure and create buttons for:
% * region zooming
% * unzooming
% * drawing a cross-section line. Intensity along line will be
% displayed in a new figure.
%
% Left clicking on a pixel will display its value in a box at the top.
%
% The second form will limit the displayed greylevels. If CLIP is a
% scalar pixels greater than this value are set to CLIP. If CLIP is
% a 2-vector pixels less than CLIP(1) are set to CLIP(1) and those
% greater than CLIP(2) are set to CLIP(2). CLIP can be set to [] for
% no clipping.
% The N argument sets the length of the greyscale color map (default 64).
%
% SEE ALSO: iroi, image, colormap, gray
%
% Copyright (c) Peter Corke, 1999 Machine Vision Toolbox for Matlab
% maxvalue = max(max(z))
% minvalue = min(min(z))
if nargin < 3,
% ncmap = 64;
ncmap = 256;
end
if (nargin > 0) & ~isstr(z),
% command line invocation, display the image
figure;
clf
colormap(gray(256))
n = ncmap;
if nargin == 2,
if length(clip) == 2,
z(find(z<clip(1))) = clip(1);
z(find(z>clip(2))) = clip(2);
elseif length(clip) == 1,
z(find(z>clip)) = clip;
end
end
hi = image(z);
set(hi, 'CDataMapping', 'scaled');
htf = uicontrol(gcf, ...
'style', 'text', ...
'units', 'norm', ...
'pos', [.6 .93 .4 .07], ...
'string', '' ...
);
ud = [gca htf hi axis];
% set(gca, 'UserData', ud);
set(hi, 'UserData', ud);
hpb=uicontrol(gcf,'style','push','string','line', ...
'units','norm','pos',[0 .93 .1 .07], ...
'userdata', ud, ...
'callback', 'idisp(''line'')');
hzm=uicontrol(gcf,'style','push','string','zoom', ...
'units','norm','pos',[.1 .93 .1 .07], ...
'userdata', ud, ...
'callback', 'idisp(''zoom'')');
huz=uicontrol(gcf,'style','push','string','unzoom', ...
'units','norm','pos',[.2 .93 .15 .07], ...
'userdata', ud, ...
'callback', 'idisp(''unzoom'')');
set(hi, 'UserData', ud);
set(gcf, 'WindowButtonDownFcn', 'idisp(''down'')');
set(gcf, 'WindowButtonUpFcn', 'idisp(''up'')');
return;
end
% otherwise idisp() is being invoked on a GUI event
if nargin == 0,
% mouse push or motion request
h = get(gcf, 'CurrentObject'); % image
ud = get(h, 'UserData'); % axis
h_ax = ud(1); % axes
tf = ud(2); % string field
hi = ud(3); % the image
cp = get(h_ax, 'CurrentPoint');
x = round(cp(1,1));
y = round(cp(1,2));
imdata = get(hi, 'CData');
% set(tf, 'String', ['(' num2str(x) ', ' num2str(y) ') = ' num2str(imdata(y,x))]);
set(tf, 'String', ['(' num2str(y) ', ' num2str(x) ') = ' num2str(imdata(y,x))]);
drawnow
elseif nargin == 1,
switch z,
case 'down',
% install pixel value inspector
set(gcf, 'WindowButtonMotionFcn', 'idisp');
idisp
case 'up',
set(gcf, 'WindowButtonMotionFcn', '');
case 'line',
h = get(gcf, 'CurrentObject'); % push button
ud = get(h, 'UserData');
ax = ud(1); % axes
tf = ud(2); % string field
hi = ud(3); % the image
set(tf, 'String', 'First point');
[x1,y1] = ginput(1);
x1 = round(x1); y1 = round(y1);
set(tf, 'String', 'Last point');
[x2,y2] = ginput(1);
x2 = round(x2); y2 = round(y2);
set(tf, 'String', '');
imdata = get(hi, 'CData');
dx = x2-x1; dy = y2-y1;
if abs(dx) > abs(dy),
x = min(x1,x2):max(x1,x2);
y = round(dy/dx * (x-x1) + y1);
nim = size(x,2);
for kn = 1:nim
imgout(kn) = imdata(y(kn),x(kn));
end
figure;plot(x,imgout);grid on;xlabel('Coordinate (X)')
else
y = min(y1,y2):max(y1,y2);
x = round(dx/dy * (y-y1) + x1);
nim = size(y,2);
for kn = 1:nim
imgout(kn) = imdata(y(kn),x(kn));
end
figure;plot(y,imgout);grid on;xlabel('Coordinate (Y)')
end
%%%%%%%%%%%%%%%%%%%%%
% nim = size(x,2);
% for kn = 1:nim
% imgout(kn) = imdata(y(kn),x(kn));
% end
% figure;plot(x,imgout)
%%%%%%%%%%%%%%%%%%%%%
case 'zoom',
h = get(gcf, 'CurrentObject'); % push button
ud = get(h, 'UserData');
ax = ud(1); % axes
tf = ud(2); % string field
hi = ud(3); % the image
set(tf, 'String', 'First point');
[x1,y1] = ginput(1);
x1 = round(x1); y1 = round(y1);
set(tf, 'String', 'Last point');
[x2,y2] = ginput(1);
x2 = round(x2); y2 = round(y2);
set(tf, 'String', '');
axes(ax);
axis([x1 x2 y1 y2]);
case 'unzoom',
h = get(gcf, 'CurrentObject'); % push button
ud = get(h, 'UserData');
h_ax = ud(1); % axes
axes(h_ax);
axis(ud(4:7));
end
end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -