1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| function test
fig = figure;
movegui(fig,'center');
handles = load('clown.mat');
colormap(handles.map);
handles.im = imagesc(handles.X);
axis image
set(fig,'windowbuttondownfcn',@wbdfcn);
guidata(fig,handles);
function wbdfcn(obj,event)
handles = guidata(obj);
hold on
pt1 = get(gca,'CurrentPoint');
handles.ROI = rbbox;
pt2 = get(gca,'CurrentPoint');
handles.ROI = round([pt1(1,2) pt1(1,1) pt2(1,2) pt2(1,1)]);
handles.r = rectangle('position',[pt1(1,1) pt1(1,2) pt2(1,1)-pt1(1,1) pt2(1,2)-pt1(1,2)]);
set(handles.r,'linewidth',4,'edgecolor','g')
handles.anchor = plot(pt1(1,1),pt1(1,2),'rs');
set(handles.anchor,'markerfacecolor','r', ...
'markersize',12, ...
'buttondownfcn',@anchbdfcn)
set(obj,'windowbuttondownfcn','');
guidata(obj,handles);
mR = meanROI;
disp(mR);
function wbmfcn(obj,event)
handles = guidata(obj);
pt = get(gca,'CurrentPoint');
set(handles.anchor,'xdata',pt(1,1),'ydata',pt(1,2));
pos = get(handles.r,'position');
set(handles.r,'position',[pt(1,1:2) pos(3:4)])
handles.ROI = round([pt(1,2) pt(1,1) pt(1,2)+pos(4) pt(1,1)+pos(3)]);
guidata(obj,handles);
function wbufcn(obj,event)
handles = guidata(obj);
set(obj,'windowbuttonmotionfcn','',...
'windowbuttonupfcn','',...
'pointer','arrow');
mR = meanROI;
disp(mR);
function anchbdfcn(obj,event)
set(gcbf,'pointer','fleur', ...
'windowbuttonmotionfcn',@wbmfcn,...
'windowbuttonupfcn',@wbufcn);
function mR = meanROI
handles = guidata(gcbf);
ROI = handles.X(handles.ROI(1):handles.ROI(3),handles.ROI(2):handles.ROI(4));
mR = mean(ROI(:)); |
Partager