?? mia_pixval.m
字號:
images = findobj(figHandle, 'Tag','MainImage');
if isempty(images)
imageHandle=0; imageType=''; img=[]; x=0; y=0;
return
end
% Make sure that the Image's Button Down & Up functions will queue
set(images, 'ButtonDownFcn', 'mia_pixval(''ButtonDownOnImage'')', ...
'Interruptible', 'off', 'BusyAction', 'Queue');
axHandles = get(images, {'Parent'});
axPositions = get([axHandles{:}], {'Position'});
axCurPt = get([axHandles{:}], {'CurrentPoint'});
% Loop over the axes, see if we are above any of them
imageHandle = 0;
for k=1:length(axHandles)
XLim = get(axHandles{k}, 'XLim');
YLim = get(axHandles{k}, 'YLim');
pt = axCurPt{k};
x = pt(1,1); y = pt(1,2);
if x>=XLim(1) & x<=XLim(2) & y>=YLim(1) & y<=YLim(2)
imageHandle = images(k);
break;
end
end
% Figure out image type
if imageHandle ~= 0
[img,flag] = getimage(imageHandle);
switch flag
case 1
imageType = 'indexed';
case 2 %Grayscale in standard range
imageType = 'intensity';
case 3 %Logical or Grayscale in nonstandard range
if islogical(img)
imageType = 'logical';
else
imageType = 'intensity';
end
case 4
imageType = 'rgb';
otherwise
msgId = 'Images:pixval:invalidImage';
msg = ['Invalid image, GETIMAGE returned flag = ' flag '.'];
error(msgId, '%s', msg);
end
else
imageHandle=0; imageType=''; img=[]; x=0; y=0;
end
%%%
%%% Sub-function - UpdatePixelValues
%%%
function UpdatePixelValues(imageHandle, imageType, displayBar,img,x,y)
% This is the motion callback for when we are displaying
% pixels. Either we are in automatic display mode and the
% mouse pointer is moving around or we are in normal mode
% and there has been a button-down but not yet a button up.
% I get the current point and update the string.
global gVOIpixval old_pt_zoom_main x0_pan_main;%temp variables for distance, zoom and pan operation;
dbud = get(displayBar, 'UserData');
[rows,cols,colors] = size(img);
rp = axes2pix(rows, get(imageHandle,'YData'),y);
cp = axes2pix(cols, get(imageHandle,'XData'),x);
r = min(rows, max(1, round(rp)));
c = min(cols, max(1, round(cp)));
if strcmp(imageType,'indexed')
map=get(dbud.figureHandle, 'Colormap');
idx = img(r,c);
if ~isa(idx, 'double'),
idx = double(idx)+1;
end
idx = round(idx);
if idx<=size(map,1)
pixel = map(idx,:);
else
pixel = map(end,:);
end
else
pixel = double(img(r,c,:));
end
ImgSize = size(double(gVOIpixval.CurrentImage));
if x > ImgSize(2) | x < 1 | y > ImgSize(1) | y < 1
% in zoom or pan mod the cursor might be beyond the image area
return;
end
CurPixVal = double(gVOIpixval.CurrentImage(round(y),round(x)));
% figure out the new string
switch dbud.displayMode
case 'normal' % Just display intensity information
if strcmp(imageType,'rgb') | strcmp(imageType,'indexed')
if isa(img, 'uint8') & strcmp(imageType,'rgb')
pixval_str = sprintf(' %g, %g = %3d,%3d,%3d', ...
round(x),round(y),pixel(1),pixel(2),pixel(3));
elseif isa(img, 'uint16') & strcmp(imageType,'rgb')
pixval_str = sprintf(' %g, %g = %5d,%5d,%5d', ...
round(x),round(y),pixel(1),pixel(2),pixel(3));
elseif islogical(img) & strcmp(imageType,'rgb')
pixval_str = sprintf(' %g, %g = %1d,%1d,%1d', ...
round(x),round(y),pixel(1),pixel(2),pixel(3));
else % all indexed images use double precision colormaps
pixval_str = sprintf(' %g,%g = %5.1f ', ...
round(x),round(y),CurPixVal);
end
else
% intensity
if isa(img, 'uint8')
pixval_str = sprintf(' %g,%g = %1d',round(x),round(y),pixel(1));
elseif isa(img, 'int16')
pixval_str = sprintf(' %g,%g = %1d',round(x),round(y),pixel(1));
elseif islogical(img)
pixval_str = sprintf(' %g,%g = %1d',round(x),round(y),pixel(1));
else
pixval_str = sprintf(' %g,%g = %5.1f',round(x),round(y),pixel(1));
end
end
set(displayBar, 'String', (pixval_str), 'UserData', dbud);
case 'distance'
figureHandle = get(get(imageHandle, 'parent'), 'parent');
mouseclick = get(gcf,'SelectionType');
if strcmp(mouseclick,'normal')
delta_x = (x - dbud.x0)*gVOIpixval.xypixsize(1);
delta_y = (y - dbud.y0)*gVOIpixval.xypixsize(2);
dist = sqrt(delta_x^2 + delta_y^2);
sunit = gVOIpixval.pixunit;
set(dbud.line, 'XData', [dbud.x0 x], 'YData', [dbud.y0 y]);
if strcmp(imageType,'rgb') | strcmp(imageType,'indexed')
if isa(img, 'uint8') & strcmp(imageType,'rgb')
pixval_str = sprintf(' %g,%g = %3d,%3d,%3d dist = %3.3f', ...
x,y,pixel(1),pixel(2),pixel(3),dist);
elseif isa(img, 'uint16') & strcmp(imageType,'rgb')
pixval_str = sprintf(' %g,%g = %5d,%5d,%5d dist = %3.3f', ...
x,y,pixel(1),pixel(2),pixel(3),dist);
elseif islogical(img) & strcmp(imageType,'rgb')
pixval_str = sprintf(' %g,%g = %1d,%1d,%1d dist = %3.3f', ...
x,y,pixel(1),pixel(2),pixel(3),dist);
else % all indexed images use double precision colormaps
pixval_str = sprintf([' %g,%g = %5.1f; dist=%3.1f' ,sunit], ...
round(x),round(y),CurPixVal,dist);
end
else % intensity
if isa(img, 'uint8')
pixval_str = sprintf([' %g,%g = %1d; dist=%3.1f',sunit], ...
round(x),round(y),pixel(1),(dist));
elseif isa(img, 'uint16')
pixval_str = sprintf([' %g,%g = %1d; dist=%3.1f',sunit], ...
round(x),round(y),pixel(1),(dist));
elseif islogical(img)
pixval_str = sprintf([' %g,%g = %1d; dist=%3.1f',sunit], ...
round(x),round(y),pixel(1),(dist));
else
pixval_str = sprintf(' %g,%g = %1.1f; dist =%3.1f', ...
round(x),round(y),pixel(1),(dist));
end
end
set(displayBar, 'String', (pixval_str), 'UserData', dbud);
elseif strcmp(mouseclick,'extend') % zoom mode
CurrentAxes = findobj(figureHandle, 'tag', 'ImaAxes');
%set(CurrentAxes,'Units','pixel');
new_pt = get(0,'PointerLocation');
dy = (new_pt(2) - old_pt_zoom_main(2))/abs(old_pt_zoom_main(2))*5;
zoomFactor = (1-dy);
xLim=get(CurrentAxes,'XLim');
yLim=get(CurrentAxes,'YLim');
xLimNew = [0 zoomFactor*diff(xLim)] + xLim(1) + (1-zoomFactor)*diff(xLim)/2;
yLimNew = [0 zoomFactor*diff(yLim)] + yLim(1) + (1-zoomFactor)*diff(yLim)/2;
set(CurrentAxes,'XLim',xLimNew,'YLim',yLimNew);
old_pt_zoom_main = new_pt;
elseif strcmp(mouseclick,'alt') % pan mode
currentPoint = get(figureHandle,'CurrentPoint');
CurrentAxes = findobj(figureHandle, 'tag', 'ImaAxes');
set(CurrentAxes,'Units','pixel');
dx = currentPoint - x0_pan_main;
x0_pan_main = currentPoint;
ap = get(CurrentAxes,'Position');
xLim = get(CurrentAxes,'XLim');
yLim = get(CurrentAxes,'YLim');
set(CurrentAxes,'XLim',xLim-(diff(xLim)*dx(1)/ap(3)), ...
'YLim',yLim+(diff(yLim)*dx(2)/ap(4)));
set(CurrentAxes,'Units','normalized');
elseif strcmp(mouseclick,'open')% restore the original image
xLimNew = gVOIpixval.xLim;
yLimNew = gVOIpixval.yLim;
CurrentAxes = findobj(figureHandle, 'tag', 'ImaAxes');
set(CurrentAxes,'XLim',xLimNew,'YLim',yLimNew);
end
end
%%%
%%% Sub-function - ButtonDownOnImage
%%%
function ButtonDownOnImage
global old_pt_zoom_main x0_pan_main;%temp for zoom and pan operation
imageHandle = gcbo;
figureHandle = get(get(imageHandle,'Parent'),'Parent');
displayBar = findobj(figureHandle, 'Tag', 'pixel value display bar');
dbud = get(displayBar, 'UserData');
axesHandle = get(imageHandle, 'Parent');
mouseclick = get(gcf,'SelectionType');
if strcmp(mouseclick,'normal')% case of distance measuring
% Set the initial point (x0,y0)
pt = get(axesHandle, 'CurrentPoint');
dbud.x0 = pt(1,1);
dbud.y0 = pt(1,2);
dbud.line = line('Parent', axesHandle, ...
'erasemode', 'xor', ...
'color', [1 0 0], ...
'Xdata', [dbud.x0 dbud.x0], ...
'Ydata', [dbud.y0 dbud.y0],'LineWidth',3);
elseif strcmp(mouseclick,'alt') % pan mode
setptr(figureHandle,'closedhand');
elseif strcmp(mouseclick,'extend') % zoom mode
setptr(figureHandle,'glass');
end
dbud.displayMode = 'distance';
old_pt_zoom_main = get(0,'PointerLocation');% for zoom mode
x0_pan_main = get(figureHandle,'CurrentPoint');% for pan mode
dbud.buttonDownImage = imageHandle;
set(displayBar, 'UserData', dbud);
set(dbud.figureHandle, 'WindowButtonUpFcn', 'mia_pixval(''BackToNormalPixvalDisplay'')');
PixvalMotionFcn(displayBar);
%%%
%%% Sub-function - BackToNormalPixvalDisplay
%%%
function BackToNormalPixvalDisplay
displayBar = findobj(gcbo, 'Tag', 'pixel value display bar');
dbud = get(displayBar, 'UserData');
imageHandle = dbud.buttonDownImage;
mouseclick = get(gcf,'SelectionType');
if strcmp(mouseclick,'normal')% case of distance measuring
delete(dbud.line);
dbud.line = [];
dbud.x0 = []; dbud.y0 = [];
end
set(dbud.figureHandle, 'WindowButtonUpFcn', '');
dbud.displayMode = 'normal';
dbud.buttonDownImage = 0;
set(displayBar, 'UserData', dbud);
PixvalMotionFcn(displayBar);
%%%
%%% Sub-function - MoveDisplayBar
%%%
function MoveDisplayBar
displayBar = gcbo;
dbud = get(displayBar, 'UserData');
oldWindowMotionFcn = get(dbud.figureHandle, 'WindowButtonMotionFcn');
set(dbud.figureHandle, 'WindowButtonMotionFcn', '');
oldPointer = get(dbud.figureHandle, 'Pointer');
oldPointerShapeCData = get(dbud.figureHandle, 'PointerShapeCData');
oldPointerShapeHotSpot = get(dbud.figureHandle, 'PointerShapeHotSpot');
setptr(dbud.figureHandle,'closedhand');
txtpos = get(displayBar, 'Position');
frmPos = get(dbud.DisplayFrame, 'Position');
position = txtpos + [0 0 frmPos(3) 0];
position2 = dragrect(position);
dx = position2(1)-position(1);
dy = position2(2)-position(2);
txtpos = txtpos + [dx dy 0 0];
set(displayBar, 'Position', txtpos);
frmPos = frmPos + [dx dy 0 0];
set(dbud.DisplayFrame, 'Position', frmPos);
btnPos = get(dbud.CloseButton, 'Position');
btnPos = btnPos + [dx dy 0 0];
set(dbud.CloseButton, 'Position', btnPos);
set(dbud.figureHandle, 'Pointer', oldPointer, ...
'PointerShapeCData', oldPointerShapeCData, ...
'PointerShapeHotSpot', oldPointerShapeHotSpot)
set(dbud.figureHandle, 'WindowButtonMotionFcn', oldWindowMotionFcn);
%%%
%%% Sub-function - DeleteDisplayBar
%%%
function DeleteDisplayBar(displayBar)
% Take apart the pixel value display - get rid of the text
% uicontrol and clean up the image objects (remove their
% UserData's and get rid of their ButtonDown & Delete Fcn's)
if nargin<1
displayBar = findobj(gcbf, 'Tag', 'pixel value display bar');
end
if ~isempty(displayBar) % if it's empty, there's no work to do.
dbud = get(displayBar, 'UserData');
set(displayBar, 'DeleteFcn', ''); % Make sure there's no recursion
if ishandle(displayBar)
delete(displayBar);
end
if ishandle(dbud.CloseButton)
delete(dbud.CloseButton);
end
if ishandle(dbud.DisplayFrame)
delete(dbud.DisplayFrame);
end
mfh = findobj('tag','mia_figure1');
set(mfh,'WindowButtonMotionFcn','');
mih = findobj('tag','MainImage');
set(mih,'buttonDownFcn','');
% We are once again restoring the figure state, since
% UIRESTORE also will reactivate the SCRIBE toolbar.
%%uirestore(dbud.oldFigureUIState);
% This is what we did for IPT 2.1/ML 5.2 :
% uisuspend(dbud.figureHandle);
end
%%%
%%% Sub-function - CreatePointer
%%%
function [pointerShape, pointerHotSpot] = CreatePointer
pointerHotSpot = [8 8];
pointerShape = [ ...
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
1 1 1 1 1 1 2 NaN 2 1 1 1 1 1 1 1
2 2 2 2 2 2 2 NaN 2 2 2 2 2 2 2 2
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN
2 2 2 2 2 2 2 NaN 2 2 2 2 2 2 2 2
1 1 1 1 1 1 2 NaN 2 1 1 1 1 1 1 1
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN 1 2 NaN 2 1 NaN NaN NaN NaN NaN NaN
NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN NaN];
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -