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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| function MouseDraw_app(action)
global InitialX InitialY FigHandle imSize = 200; if nargin == 0 action = 'start'; end
switch(action) case 'start' index = 0;InputImage = ones(imSize); save('input.mat','index','InputImage'); FigHandle = figure('WindowButtonDownFcn','MouseDraw_app down;'); set(0,'units','centimeters') cm_ss=get(0,'screensize'); W=cm_ss(3);H=cm_ss(4);L=10; set(gcf,'units','normalized','position',... [(W-L)/2/W,(H-L)/2/H,L/W,L/H]); set(gca,'XTick',zeros(1,0),'YTick',zeros(1,0)); axis([1 imSize 1 imSize]); axis on;grid off;box on; title('\rm{鼠标左键}\bf{输入} \rm{鼠标右键}\bf{确认}',... 'FontSize',14); dlmwrite('IXT.txt', -10, 'delimiter', '\t', 'precision', 6); dlmwrite('IYT.txt', -10, 'delimiter', '\t', 'precision', 6); case 'down' if strcmp(get(FigHandle, 'SelectionType'), 'normal') set(FigHandle,'pointer','hand'); CurPiont = get(gca, 'CurrentPoint'); InitialX = CurPiont(1,1); InitialY = CurPiont(1,2); dlmwrite('IXT.txt', InitialX, '-append', ... 'delimiter', '\t', 'precision', 6); dlmwrite('IYT.txt', InitialY, '-append', ... 'delimiter', '\t', 'precision', 6); set(gcf, 'WindowButtonMotionFcn', 'MouseDraw_app move;'); set(gcf, 'WindowButtonUpFcn', 'MouseDraw_app up;'); elseif strcmp(get(FigHandle, 'SelectionType'), 'alt') set(FigHandle, 'Pointer', 'arrow'); set(FigHandle, 'WindowButtonMotionFcn', ''); set(FigHandle, 'WindowButtonUpFcn', ''); close(FigHandle); ImageX = importdata('IXT.txt'); ImageY = importdata('IYT.txt'); InputImage = ones(imSize); roundX = round(ImageX); roundY = round(ImageY); for k = 1:size(ImageX,1) if 0<roundX(k) && roundX(k)<imSize && ... 0<roundY(k) && roundY(k)<imSize InputImage(roundX(k)-1:roundX(k)+2,... roundY(k)-1:roundY(k)+2) = 0; end end InputImage = imrotate(InputImage,90); index = 1; save('input.mat','index','InputImage'); end case 'move' CurPiont = get(gca, 'CurrentPoint'); X = CurPiont(1,1); Y = CurPiont(1,2); x_gap = 0.1; y_gap = 0.1; if X > InitialX step_x = x_gap; else step_x = -x_gap; end if Y > InitialY step_y = y_gap; else step_y = -y_gap; end if abs(X-InitialX) < 0.01 iy = InitialY:step_y:Y; ix = X.*ones(1,size(iy,2)); else ix = InitialX:step_x:X ; iy = (Y-InitialY)/(X-InitialX).*(ix-InitialX)+InitialY; end ImageX = [ix, X]; ImageY = cat(2, iy, Y); line(ImageX,ImageY, 'marker', '.', 'markerSize',28, ... 'LineStyle', '-', 'LineWidth', 4, 'Color', 'Blue'); dlmwrite('IXT.txt', ImageX, '-append', ... 'delimiter', '\t', 'precision', 6); dlmwrite('IYT.txt', ImageY, '-append', ... 'delimiter', '\t', 'precision', 6); InitialX = X; InitialY = Y; case 'up' set(gcf, 'WindowButtonMotionFcn', ''); set(gcf, 'WindowButtonUpFcn', ''); end
end
|