📄 imui.m
字号:
imui('::::UpdateImage', CX)
end
case '::::mnucb_Desaturate'
h = waitfig('Desaturating');
CX = get(ud.ImageHandle, 'UserData');
CX = rgb2gray(CX);
CX = cat(3, CX, CX, CX);
imui('::::UpdateImage', CX)
delete(h)
case '::::mnucb_ChannelMixer'
CX = get(ud.ImageHandle, 'UserData');
CX = imuichmix(CX);
if CX ~= -1
imui('::::UpdateImage', CX)
end
case '::::mnucb_Convolution'
CX = get(ud.ImageHandle, 'UserData');
CX = imuiconv(CX);
if CX ~= -1
imui('::::UpdateImage', CX)
end
case '::::mnucb_Equalizer'
CX = get(ud.ImageHandle, 'UserData');
CX = imuieq(CX);
if CX ~= -1
imui('::::UpdateImage', CX)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% FILTER menu callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case '::::mnucb_FilterChild'
mnuud = get(gcbo, 'UserData');
CX = get(ud.ImageHandle, 'UserData');
CX = imuifilter(CX, mnuud.CustomData);
if CX ~= -1
imui('::::UpdateImage', CX)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% VIEW menu callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case '::::mnucb_HideMenu'
if isempty(findobj(ud.FigureHandle, ...
'Type', 'uimenu', 'Visible', 'on', 'Parent', ud.FigureHandle))
set(findall(ud.FigureHandle, 'Type', 'uimenu', 'Parent', ud.FigureHandle), ...
'visible', 'on')
else
set(findall(ud.FigureHandle, 'Type', 'uimenu', 'Parent', ud.FigureHandle), ...
'visible', 'off')
end
case '::::mnucb_Zoom'
ud.ZoomState = umtoggle(ud.MenuHandles.Zoom);
UpdateGUIState(ud)
case '::::mnucb_Grid'
ud.GridState = umtoggle(ud.MenuHandles.Grid);
UpdateGUIState(ud)
case '::::mnucb_ZoomIn'
zoom(2)
UpdateImageDisplayRatio(ud)
case '::::mnucb_ZoomOut'
zoom(0.5)
UpdateImageDisplayRatio(ud)
case '::::mnucb_ZoomFit'
sz = get(0, 'ScreenSize');
set(ud.FigureHandle, 'Position', [0 0 sz(3) * 0.8 sz(4) * 0.8])
movegui(ud.FigureHandle, 'center')
UpdateImageDisplayRatio(ud)
case '::::mnucb_ZoomFig'
zoom('out')
UpdateImageDisplayRatio(ud)
case '::::mnucb_ZoomTrue'
zoom('out')
truesize
UpdateImageDisplayRatio(ud)
case '::::mnucb_GridColor'
set(allchild(ud.MenuHandles.GridClr), 'Checked', 'off');
umtoggle(gcbo);
udmnu = get(gcbo, 'UserData');
if ~isempty(udmnu.CustomData)
ud.GridColor = udmnu.CustomData;
else
ud.GridColor = uisetcolor(ud.GridColor);
end
UpdateGUIState(ud)
case '::::mnucb_FigureColor'
set(allchild(ud.MenuHandles.FigureClr), 'Checked', 'off');
umtoggle(gcbo);
udmnu = get(gcbo, 'UserData');
if ~isempty(udmnu.CustomData)
ud.FigureColor = udmnu.CustomData;
else
ud.FigureColor = uisetcolor(ud.FigureColor);
end
UpdateGUIState(ud)
case '::::mnucb_GridLineStyle'
set(allchild(ud.MenuHandles.GridStyle), 'Checked', 'off');
umtoggle(gcbo);
udmnu = get(gcbo, 'UserData');
ud.GridLineStyle = udmnu.CustomData;
UpdateGUIState(ud)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% WINDOW menu callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case '::::mnucb_Window'
imuiFigures = sort(getImuiFigureHandles);
hsubmenu = allchild( ud.MenuHandles.Window );
uimenu( ud.MenuHandles.Window, ...
'Label', 'Center &screen', ...
'Callback', 'movegui(gcf, ''center'')');
uimenu( ud.MenuHandles.Window, ...
'Label', '&Re-arrange', ...
'UserData', imuiFigures, ...
'Callback', 'imui(''::::mnucb_Window_ReArrange'')');
uimenu( ud.MenuHandles.Window, ...
'Label', '&Close all', ...
'UserData', imuiFigures, ...
'Callback', 'close(get(gcbo, ''UserData''))');
for i = 1 : length(imuiFigures)
udfig = get(imuiFigures(i), 'UserData');
h = uimenu( ud.MenuHandles.Window, ...
'Label', ['&', num2str(i - 1), ' - ', udfig.ImageTitle], ...
'UserData', imuiFigures(i), ...
'Callback', 'figure(get(gcbo,''UserData''))');
if i == 1
set(h, 'Separator', 'on')
end
if imuiFigures(i) == ud.FigureHandle
set(h, 'Checked', 'on')
end
end
delete(hsubmenu)
case '::::mnucb_Window_ReArrange'
imuiFigures = get(gcbo, 'UserData');
for i = 1 : length(imuiFigures)
figure(imuiFigures(i))
movegui(imuiFigures(i), [i ,-i] * 24)
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%% ABOUT menu callbacks
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
case '::::mnucb_About'
AboutString = sprintf([ ...
'Thank you very much for trying IMUI !\n', ...
'\n', ...
'If you have suggestions, please write to\n', ...
'kotaimen_c@citiz.net\n', ...
'\n', ...
'Concept, GUI Design, M Programming, DIP Tech...\n', ...
'All by Kotaimen.C\n', ...
'\n', ...
'Special Thanks to:\n', ...
'Xavier\n', ...
'\n', ...
'version 0.9.5\n', ...
'' ...
]);
h = dialog( ...
'Name', 'About IMUI', ...
'Position', [0 0 546 275], ...
'Color', 'k', ...
'HandleVisibility', 'on', ...
'Visible', 'off');
axes( ...
'Units', 'pixel', ...
'Position', [10 10 256 256]);
logoimg = fullfile(MyLocation, 'private', 'imuilogo.jpg');
imshow(logoimg, 'notruesize')
uicontrol( ...
'Style', 'text', ...
'BackgroundColor', 'k', ...
'ForegroundColor', [0.8 0.8 0.8], ...
'Units', 'pixel', ...
'Position', [276 50 256 256 - 45], ...
'String', AboutString);
uicontrol( ...
'Style', 'pushbutton', ...
'BackgroundColor', 'k', ...
'ForegroundColor', [0.8 0.8 0.8], ...
'Units', 'pixel', ...
'Position', [367 15 74 24], ...
'String', 'Close', ...
'Callback', 'close(gcf)');
movegui(h, 'center')
set(h, 'Visible', 'on')
otherwise
warning(['Inavid action "', Action, '".'])
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% UpdateGUIState - update gui state
function UpdateGUIState(ud)
%%%%Update figure userdata
set(ud.FigureHandle, 'UserData', ud)
%%%%Update Title
hdlMenu = ud.MenuHandles;
switch ud.ImageType
% cImgType
% [Reserved, Binary, Indexed, Gray, RGB]
case 'Binary'
strTitle = ['IMUI - [', ud.ImageTitle, '] - Binary, '];
cImgType = [-1, 1, -1, -1, -1];
case 'Gray'
strTitle = ['IMUI - [', ud.ImageTitle, '] - Grayscale, '];
cImgType = [-1, -1, -1, 1, -1];
case 'RGB'
strTitle = ['IMUI - [', ud.ImageTitle, '] - RGB Color, '];
cImgType = [-1, -1, -1, -1, 1];
otherwise
error('Unknown ImageType')
end
strTitle = [strTitle, sprintf('%d*%d, ', ud.ImageSize), ...
upper(ud.ImageClass), ' @'];
set(ud.FigureHandle, ...
'Name', strTitle)
%%%%Update Menu
temp = struct2cell(ud.MenuHandles);
allMenuHandles = cat(2, temp{:});
for hmnu = allMenuHandles
udmnu = get(hmnu, 'UserData');
if any(cImgType == udmnu.AvailableImageType)
set(hmnu, 'Enable', 'on')
else
set(hmnu, 'Enable', 'off')
end
end
%%%%Update ImageClass
switch ud.ImageClass
case 'uint8'
set(ud.MenuHandles.ToUINT8, 'Enable', 'off')
case 'uint16'
set(ud.MenuHandles.ToUINT16, 'Enable', 'off')
case 'double'
set(ud.MenuHandles.ToDOUBLE, 'Enable', 'off')
end
%%%%Update Fade menu
if ud.HistoryCount == 1
set(ud.MenuHandles.Fade, 'Enable', 'off')
end
%%%%Update zoom state
if ud.ZoomState
setptr(ud.FigureHandle, 'glass')
set(ud.MenuHandles.Crop, 'Enable', 'off')
set(ud.MenuHandles.impixel, 'Enable', 'off')
set(ud.MenuHandles.improfile, 'Enable', 'off')
zoom('on');
else
setptr(ud.FigureHandle, 'arrow')
zoom('off');
end
%%%%Update figure state
set(ud.FigureHandle, ...
'Color', ud.FigureColor);
%%%%Update Gridline state
if ud.GridState
set(ud.AxesHandle, ...
'Visible', 'on', ...
'Color', ud.FigureColor, ...
'Position', [0.1 0.1 0.8 0.8], ...
'XColor', ud.GridColor, ...
'YColor', ud.GridColor, ...
'GridLineStyle',ud.GridLineStyle)
set(ud.TextHandle, ...
'Visible', 'on', ...
'BackgroundColor', ud.FigureColor, ...
'ForegroundColor', ud.GridColor, ...
'String', '')
% set(ud.FigureHandle, ...
% 'WindowButtonMotionFcn', 'imui( ''::::ButtonMotion'') ')
else
set(ud.AxesHandle, ...
'Visible', 'off', ...
'Position', [0 0 1 1])
set(ud.TextHandle, ...
'Visible', 'off')
% set(ud.FigureHandle, ...
% 'WindowButtonMotionFcn', ' ')
end
UpdateImageDisplayRatio(ud)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% imuiFigHdl -returns handles of imui figure
function imuiFigHdl = getImuiFigureHandles
imuiFigHdl =( findobj(allchild(0), 'tag', '::::imuiFigure', 'Visible', 'on') )';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function UpdateImageDisplayRatio(ud)
oldname = get(ud.FigureHandle, 'Name');
lastat = findstr(oldname, '@');
if ud.ZoomState
newname = [oldname(1 : lastat(end)-1), '@Zoom'];
else
figpos = get(ud.FigureHandle, 'Position');
axepos = get(ud.AxesHandle, 'Position');
axelimx = diff(get(ud.AxesHandle, 'Xlim'));
axelimy = diff(get(ud.AxesHandle, 'Ylim'));
temp = figpos .* axepos;
axex = temp(3);
axey = temp(4);
if axex > axey
ZoomRatio = axex / axelimx;
else
ZoomRatio = axey / axelimy;
end
newname = [oldname(1 : lastat(end)-1), sprintf('@%.1f%%', ZoomRatio * 100)];
end
set(ud.FigureHandle, 'Name', newname)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function DisableAllMenus(ud)
temp = struct2cell(ud.MenuHandles);
allMenuHandles = cat(2, temp{:});
set(allMenuHandles, 'Enable', 'off')
set(ud.FigureHandle, ...
'KeyPressFcn', ' ', ...
'CloseRequestFcn', ' ', ...
'WindowButtonMotionFcn', ' ')
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function EnableAllMenus(ud)
set(ud.FigureHandle, ...
'KeyPressFcn', ' imui( ''::::KeyPress'' ) ', ...
'CloseRequestFcn', ' imui( ''::::CloseRequest'' ) ', ...
'WindowButtonMotionFcn', 'imui( ''::::ButtonMotion'') ')
UpdateGUIState(ud)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% MyLoaction - returns directory where imui.m locates
function R = MyLocation()
W = which('imui.m');
R = W(1 : strfind(W, 'imui.m') - 1);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function DisplayFunction(hdlImg)
CIMG = get(hdlImg, 'UserData');
CIMG = im2uint8(CIMG);
if isbw(CIMG)
CIMG = grayxform(CIMG, [0, ones(1, 255)]);
set(hdlImg, 'CData', CIMG)
return
end
if isrgb(CIMG)
set(hdlImg, 'CData', CIMG)
return
end
if isgray(CIMG)
set(hdlImg, 'CData', CIMG)
return
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function AppendToHistory(ud, ActionName)
newHistoryCount = ud.HistoryCount + 1;
newHistoryIndex = newHistoryCount;
hmnu = uimenu(ud.MenuHandles.History, ...
'Label', ['&', num2str(newHistoryCount), ' - ', ...
ActionName], ...
'UserData', newHistoryCount, ...
'Callback', 'imui(''::::mnucb_History_ChildCbFCN'')');
set(allchild(ud.MenuHandles.History), 'Checked', 'off')
set(hmnu, 'Checked', 'on')
if newHistoryIndex ~= ud.HistoryIndex + 1;
set(hmnu, 'Separator', 'on')
end
ud.LastHistoryIndex = ud.HistoryIndex;
ud.HistoryCount = newHistoryCount;
ud.HistoryIndex = newHistoryIndex;
ud.HistoryData(newHistoryCount).ActionName = [num2str(newHistoryCount), ' - ', ActionName];
TempFileName = tempname;
ud.HistoryData(newHistoryCount).FileName = TempFileName;
set(ud.FigureHandle, 'UserData', ud)
assignin('caller', 'ud', ud)
CX = get(ud.ImageHandle, 'UserData');
save(TempFileName, 'CX');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -