我正在构建一个Matlab GUI,让用户使用一些交互式工具进行图像处理(一个没有图形文件的mfile),
,例如使用imrotate
和角度参数旋转图像,并使用bwareaopen
和区域参数清除像素。
起初,我正在考虑使用我的mfile绘制工具,例如
function myGUI( grayI )
h_fig = figure;
h_ax = imshow( grayI );
title('Drag line and press button to rotate image');
ImgSize = size(grayI);
h_lev = imline(gca, [ 0.2*ImgSize(2), 0.1*ImgSize(1); ...
0.8*ImgSize(2) 0.1*ImgSize(1) ] );
h_lev.addNewPositionCallback( @LineUpdateFcn );
% text for the angle
h_txt = uicontrol('Style','text','String','Angle = []', 'unit', 'norm', ...
'pos',[0 0.9 .1 .05]);
%add rotate button
h_btn = uicontrol('unit','norm','pos',[0 0.95 .1 .05]);
set(h_btn,'string','Rotate','callback',@RotateImageWithLever);
% save the elements data in figure
setappdata(h_fig,'h_lev',h_lev);
setappdata(h_fig,'h_ax',h_ax);
setappdata(h_fig,'h_txt',h_txt);
% wait for user to close figure
waitfor( h_fig );
然后我在FileExchange Fireworks中遇到了工具栏的设计作为内置类,并且想到也许我错过了使用类设计我的工具栏并且内置{{1}的正确方法命令。
有关从单个mfile设计工具栏的任何建议吗?
答案 0 :(得分:1)
使用自定义工具栏可能是您描述的工具的一个很好的解决方案。使用UITOOLBAR创建工具栏,然后分别使用UIPUSHTOOL和UITOOGLETOOL添加推送或切换按钮。这可以在GUI m文件的初始化阶段轻松完成。
我在下面给出了一个简单的例子。一些警告:
这是:
function myGUI(grayI)
persistent grayICopy;
%# Keep a persistent copy of the image data to be used in the toolbar tool
%# callbacks. Other possibilities here are to not store this data
%# persistently and instead read it from the plotted values or restructure
%# this whole code as a class and store the raw image data in a class
%# property.
grayICopy = grayI;
%# Create the figure window and show the image.
hFigure = figure;
hAxes = axes('Parent', hFigure);
image(grayI, 'Parent', hAxes); %# I don't have the Image processing Toolbox
%# Create toolbar
hToolbar = uitoolbar('Parent', hFigure);
%# Add a toolbar button for 90deg clockwise rotation
uipushtool('Parent', hToolbar, ...
'ClickedCallback', @flipVertical, ...
'CData', ...
repmat([0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], [1 1 3]));
%# Add a toolbar toggle button for inverting image
uitoggletool('Parent', hToolbar, ...
'OnCallback', @toggleInverseOn, ...
'OffCallback', @toggleInverseOff, ...
'CData', ...
repmat([0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0; ...
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0], [1 1 3]));
function flipVertical(src, eventdata)
grayICopy = flipdim(grayICopy, 1);
image(grayICopy, 'Parent', hAxes);
end
function toggleInverseOn(src, eventdata)
image(1-grayICopy, 'Parent', hAxes);
end
function toggleInverseOff(src, eventdata)
image(grayICopy, 'Parent', hAxes);
end
end