|
直接运行改文件,界面,手写,点击【OK】即可保存图像:numpic.bmp
环境:64bit + win10 + matlab2019a
- function halcom_cn
- mIconCData = []; % The icon CData edited by this GUI of dimension
- % [mIconHeight, mIconWidth, 3]
- mIsEditingIcon = false; % Flag for indicating whether the current mouse
- % move is used for editing color or not
- % Variables for supporting custom property/value pairs
- mIconWidth = 28; % Use input property 'iconwidth' to initialize
- mIconHeight = 28; % Use input property 'iconheight' to initialize
- hMainFigure = figure(...
- 'Units','characters',...
- 'MenuBar','none',...
- 'Toolbar','none',...
- 'Position',[71.8 34.7 106 36.15],...
- 'WindowStyle', 'normal',...
- 'WindowButtonDownFcn', @hMainFigureWindowButtonDownFcn,...
- 'WindowButtonUpFcn', @hMainFigureWindowButtonUpFcn,...
- 'WindowButtonMotionFcn', @hMainFigureWindowButtonMotionFcn);
- hIconEditPanel = uipanel(...
- 'Parent',hMainFigure,...
- 'Units','characters',...
- 'Clipping','on',...
- 'Position',[1.8 4.3 68.2 27.77]);
- hIconEditAxes = axes(...
- 'Parent',hIconEditPanel,...
- 'vis','off',...
- 'Units','characters',...
- 'Position',[2 1.15 64 24.6]);
- hOKButton = uicontrol(...
- 'Parent',hMainFigure,...
- 'Units','characters',...
- 'Position',[65.8 0.62 17.8 2.38],...
- 'String','OK',...
- 'Callback',@hOKButtonCallback);
-
- mIconCData = ones(mIconHeight, mIconWidth, 3);
- localUpdateIconPlot();
- % localUpdateIconPlot();
- % Make the GUI on screen
- set(hMainFigure,'visible', 'on');
- movegui(hMainFigure,'onscreen');
- % Make the GUI blocking
- uiwait(hMainFigure);
- % Ip = preproc_image(mIconCData)';
- % save Ip.mat Ip
- % figure,
- % load('Ip.mat')
- % imshow(Ip,[])
- %------------------------------------------------------------------
- function hMainFigureWindowButtonDownFcn(hObject, eventdata)
- if (ancestor(gco,'axes') == hIconEditAxes)
- mIsEditingIcon = true;
- localEditColor();
- end
- end
- function hMainFigureWindowButtonUpFcn(hObject, eventdata)
- mIsEditingIcon = false;
- end
- function hMainFigureWindowButtonMotionFcn(hObject, eventdata)
- if (ancestor(gco,'axes') == hIconEditAxes)
- localEditColor();
- end
- end
- function localEditColor
- if mIsEditingIcon
- pt = get(hIconEditAxes,'currentpoint');
- x = max(1, min(ceil(pt(1,1)), mIconWidth));
- y = max(1, min(ceil(pt(1,2)), mIconHeight));
- % update color of the selected block
- m = get(gcf,'SelectionType');
- if m(1) == 'n', % left button pressed
- mIconCData(y, x,:) = 0;
- if y<mIconHeight, mIconCData(y+1,x,:) = .8*mIconCData(y+1,x,:); end
- if x<mIconWidth, mIconCData(y,x+1,:) = .8*mIconCData(y,x+1,:); end
- if y>1, mIconCData(y-1,x,:) = .8*mIconCData(y-1,x,:); end
- if x>1, mIconCData(y,x-1,:) = .8*mIconCData(y,x-1,:); end
- else
- mIconCData(y, x,:) = 1;
- end
- localUpdateIconPlot();
-
- end
- end
- %------------------------------------------------------------------
- function localUpdateIconPlot
- if isempty(mIconCData)
- mIconCData = nan(mIconHeight, mIconWidth, 3);
- end
-
- rows = size(mIconCData, 1);
- cols = size(mIconCData, 2);
-
- % update icon edit pane
- set(hIconEditPanel, 'Title',['Icon Edit Pane (', num2str(rows),' X ', num2str(cols),')']);
-
- s = findobj(hIconEditPanel,'type','surface');
- if isempty(s)
- gridColor = get(0, 'defaultuicontrolbackgroundcolor') - 0.2;
- gridColor(gridColor<0)=0;
- s=surface('edgecolor',gridColor,'parent',hIconEditAxes);
- end
- %set xdata, ydata, zdata in case the rows and/or cols change
- set(s,'xdata',0:cols,'ydata',0:rows,'zdata',zeros(rows+1,cols+1),'cdata',localGetIconCDataWithNaNs());
- set(hIconEditAxes,'drawmode','fast','xlim',[-.5 cols+.5],'ylim',[-.5 rows+.5]);
- axis(hIconEditAxes, 'ij', 'off');
- end
- %------------------------------------------------------------------
- function cdwithnan = localGetIconCDataWithNaNs()
- cdwithnan = mIconCData;
- cdwithnan(:,end+1,:) = NaN;
- cdwithnan(end+1,:,:) = NaN;
- end
-
- %------------------------------------------------------------------
- function hOKButtonCallback(hObject, eventdata)
- % Callback called when the OK button is pressed
- uiresume;
- number = preproc_image(mIconCData)';
- save number.mat number
- imwrite(number,'numpic.bmp','bmp')
- % delete(hMainFigure);
- end
- end
- function out = preproc_image(id)
- %Preprocess single image
- Inorm = id(:,:,1);
- Inorm(~isfinite(Inorm)) = 1;
- Inorm = abs(Inorm-1)';
- out = zeros(32);
- out(3:30,3:30) = Inorm;
- if sum(out(:))>0,
- out = reshape(mapstd(out(:)'), 32, 32);
- end
-
- end
复制代码
|
|