?? mia_zpixval.m
字號(hào):
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 old_pt_zoom_z x0_pan_z;%temp for zoom and pan
dbud = get(displayBar, 'UserData');
[rows, cols, colors] = size(img);
y = min(y,rows);% y > rows happens in some case /LB
rp = axes2pix(rows, get(imageHandle,'YData'),y);
cp = axes2pix(cols, get(imageHandle,'XData'),x);
r = min(rows, max(1, round(rp)));
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
% figure out the new string
figureHandle = get(get(imageHandle, 'parent'), 'parent');
switch dbud.displayMode
case 'normal' % Just display intensity information
FigDataIn = get(figureHandle,'Userdata');
ImVolume = get(FigDataIn.ImaHandlerX,'UserData');
%x = ImVolume.X;
%y = ImVolume.Y;
%z = ImVolume.Z;
%pixel(1) = ImVolume.PixInt;
if isa(img, 'uint8')
pixval_str = sprintf(' %g,%g,%g = %3d',round(x),round(y), round(ImVolume.Z),pixel(1));
elseif isa(img, 'int16')
pixval_str = sprintf(' %g,%g,%g = %5d',round(x),round(y), round(ImVolume.Z), pixel(1));
else
pixval_str = sprintf(' %g,%g,%g = %5.1f',round(x),round(y), round(ImVolume.Z),pixel(1));
end
set(displayBar, 'String', pixval_str, 'UserData', dbud);
case 'distance'
mouseclick = get(gcf,'SelectionType');
if strcmp(mouseclick,'normal')
FigDataIn = get(figureHandle,'Userdata');
fighandlerX = FigDataIn.ImaHandlerX;
fighandlerY = FigDataIn.ImaHandlerY;
FigData = FigDataIn.CData;
set(fighandlerX,'CData',rot90(squeeze(FigData(:,round(cp),:,:))));
set(fighandlerY,'CData',rot90(squeeze(FigData(round(rp),:,:))));
ImVolume = get(FigDataIn.ImaHandlerX,'UserData');
ImVolume.X = x;
ImVolume.Y = y;
ImVolume.PixInt = pixel(1);
set(FigDataIn.ImaHandlerX,'UserData',ImVolume);
if isa(img, 'uint8')
pixval_str = sprintf(' %g,%g,%g = %3d',round(x),round(y), round(ImVolume.Z),pixel(1));
elseif isa(img, 'int16')
pixval_str = sprintf(' %g,%g,%g = %5d', round(x),round(y), round(ImVolume.Z), pixel(1));
else
pixval_str = sprintf(' %g,%g,%g = %5.1f',round(x),round(y), round(ImVolume.Z),pixel(1));
end
set(displayBar, 'String', pixval_str, 'UserData', dbud);
elseif strcmp(mouseclick,'extend') % zoom mode
CurrentAxes = findobj(figureHandle, 'type', 'axes');
%set(CurrentAxes,'Units','pixel');
new_pt = get(0,'PointerLocation');
dy = (new_pt(2) - old_pt_zoom_z(2))/abs(old_pt_zoom_z(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_z = new_pt;
elseif strcmp(mouseclick,'alt') % pan mode
currentPoint = get(figureHandle,'CurrentPoint');
CurrentAxes = findobj(figureHandle, 'type', 'axes');
set(CurrentAxes,'Units','pixel');
dx = currentPoint - x0_pan_z;
x0_pan_z = 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 = dbud.xLim;
yLimNew = dbud.yLim;
CurrentAxes = findobj(gcf, 'type', 'axes');
set(CurrentAxes,'XLim',xLimNew,'YLim',yLimNew);
end
end
%%%
%%% Sub-function - ButtonDownOnImage
%%%
function ButtonDownOnImage
global old_pt_zoom_z x0_pan_z;%temp for zoom and pan operation
%imageHandle = gcbo;
currentHandle = gcbo;
if strcmp(get(currentHandle,'type'),'image')
imageHandle = currentHandle;
else
currentParentHandle = get(currentHandle,'Parent');
currentChildrensHandles = get(currentParentHandle,'children');
imageHandle = currentChildrensHandles(3);
end
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
%
elseif strcmp(mouseclick,'alt') % pan mode
setptr(figureHandle,'closedhand');
elseif strcmp(mouseclick,'extend') % zoom mode
setptr(figureHandle,'glass');
end
%
% Turn on the PlotEdit options on X,Y slice images
%
FigDataIn = get(figureHandle,'Userdata');
%delete the positioning line
ImVolume = get(FigDataIn.ImaHandlerX,'UserData');
if ishandle(ImVolume.Xxline)
delete(ImVolume.Zxline);
delete(ImVolume.Zyline);
delete(ImVolume.Yxline);
delete(ImVolume.Yyline);
delete(ImVolume.Xxline);
delete(ImVolume.Xyline);
end
set(FigDataIn.ImaHandlerX,'UserData',ImVolume);
% 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]);
dbud.displayMode = 'distance';
old_pt_zoom_z = get(0,'PointerLocation');% for zoom mode
x0_pan_z = get(figureHandle,'CurrentPoint');% for pan mode
dbud.buttonDownImage = imageHandle;
set(displayBar, 'UserData', dbud);
set(dbud.figureHandle, 'WindowButtonUpFcn', 'mia_Zpixval(''BackToNormalPixvalDisplay'')');
PixvalMotionFcn(displayBar);
%%%
%%% Sub-function - BackToNormalPixvalDisplay
%%%
function BackToNormalPixvalDisplay
displayBar = findobj(gcbo, 'Tag', 'pixel value display bar');
dbud = get(displayBar, 'UserData');
imageHandle = dbud.buttonDownImage;
%
% Turn off the PlotEdit options on X,Y slice images and
% write the last X,Y,Z coordinates to the FigDataIn struct
%
[imageHandleTmp,imageType,img,x,y]= OverImage(dbud.figureHandle);
figureHandle = get(get(imageHandle,'Parent'),'Parent');
FigDataIn = get(figureHandle,'Userdata');
axesHandleX = get(FigDataIn.ImaHandlerX, 'Parent');
axesHandleY = get(FigDataIn.ImaHandlerY, 'Parent');
axesHandleZ = get(FigDataIn.ImaHandlerZ, 'Parent');
%draw the positioning line
Xyrange = get(axesHandleX,'Ylim');
Xxrange = get(axesHandleX,'Xlim');
Yyrange = get(axesHandleY,'Ylim');
Yxrange = get(axesHandleY,'Xlim');
Zyrange = get(axesHandleZ,'Ylim');
Zxrange = get(axesHandleZ,'Xlim');
ImVolume = get(FigDataIn.ImaHandlerX,'UserData');
if ishandle(ImVolume.Xxline)
delete(ImVolume.Xxline);
delete(ImVolume.Xyline);
delete(ImVolume.Yxline);
delete(ImVolume.Yyline);
delete(ImVolume.Zxline);
delete(ImVolume.Zyline);
end
LineWidthCur = 2;
%lines in saggital slice
ImVolume.Xxline=line('Parent', axesHandleX,'color', [0 1 1],'EraseMode','xor', ....
'LineWidth',LineWidthCur,'Xdata',[ImVolume.Y ImVolume.Y],'Ydata',[0 Xyrange(2)], ...
'ButtonDownFcn','mia_Xpixval(''ButtonDownOnImage'')');
ImVolume.Xyline=line('Parent', axesHandleX,'color', [0 1 1],'EraseMode','xor', ...
'LineWidth',LineWidthCur,'Xdata',[0 Xxrange(2)],'Ydata', [ImVolume.Z ImVolume.Z], ...
'ButtonDownFcn','mia_Xpixval(''ButtonDownOnImage'')');
%lines in axial slice
ImVolume.Zxline=line('Parent', axesHandleZ,'color', [0 1 1],'EraseMode','xor', ....
'LineWidth',LineWidthCur,'Xdata',[ImVolume.X ImVolume.X],'Ydata',[0 Zyrange(2)], ...
'ButtonDownFcn','mia_Zpixval(''ButtonDownOnImage'')');
ImVolume.Zyline=line('Parent', axesHandleZ,'color', [0 1 1],'EraseMode','xor', ...
'LineWidth',LineWidthCur,'Xdata',[0 Zxrange(2)],'Ydata', [ImVolume.Y ImVolume.Y], ...
'ButtonDownFcn','mia_Zpixval(''ButtonDownOnImage'')');
% set(FigDataIn.ImaHandlerX,'UserData',ImVolume);
%lines in coronal slice
ImVolume.Yxline=line('Parent', axesHandleY,'color', [0 1 1],'EraseMode','xor', ....
'LineWidth',LineWidthCur,'Xdata',[ImVolume.X ImVolume.X],'Ydata',[0 Xyrange(2)], ...
'ButtonDownFcn','mia_Ypixval(''ButtonDownOnImage'')');
ImVolume.Yyline=line('Parent', axesHandleY,'color', [0 1 1],'EraseMode','xor', ...
'LineWidth',LineWidthCur,'Xdata',[0 Yxrange(2)],'Ydata', [ImVolume.Z ImVolume.Z], ...
'ButtonDownFcn','mia_Ypixval(''ButtonDownOnImage'')');
set(FigDataIn.ImaHandlerX,'UserData',ImVolume);
%delete(dbud.line);
%dbud.line = [];
%dbud.x0 = []; dbud.y0 = [];
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
% 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];
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)