我正在尝试将图像放置在窗口的中央:'Im',如下所示:
我在第一个回调函数中写道:
img = imread(files{k}); %# Read the data from your image file
hAxes = axes('Parent',hOptsGUI,'Units','pixels','Position',[362 242 424 359]); %# so the position is easy to define
image(img,'Parent',hAxes); %# Plot the image
set(hAxes,'Visible','off'); %# Turn the axes visibility off
我不确定,但我想我不需要axisH。此外,轴允许当前轴:/
有人可以告诉我如何解决它吗?
这是我的代码:
function data = mainGUI(options, files)
%# current options
j = 1;
ops = cellfun(@(c) c(1), options, 'Uniform',false);
data{j} = [ops{1:length(ops)}];
j = j + 1;
options = cellfun(@(c) c(2:1:end), options, 'Uniform',false);
clear ops;
ops = cellfun(@(c) c(1), options, 'Uniform',false);
opts = [ops{1:length(ops)}];
%# create main figure, with plot and options button
hFig = figure('Name','window 1','Visible','Off');
callback
%# options button callback function
function callback(o,e)
%# save current options (sharing data between the two GUIs)
setappdata(hFig, 'opts',opts);
%# display options dialog and wait for it
for k=1: length(files)
hOptsGUI = secondaryGUI(hFig, options);
img = imread(files{k}); %# Read the data from your image file
hAxes = axes('Parent',hOptsGUI,'Units','pixels','Position',[362 242 424 359]); %# so the position is easy to define
image(img,'Parent',hAxes); %# Plot the image
set(hAxes,'Visible','off'); %# Turn the axes visibility off
waitfor(hOptsGUI);
%# get new options, and update plot accordingly
opts = getappdata(hFig, 'opts');
data{j} = opts;
j = j + 1;
end
end
end
function hFig = secondaryGUI(hParentFig, options)
%# create figure
hFig = figure('Name','Simulation Plot Window','Menubar','none', 'Resize','off', ...
'WindowStyle','modal', 'Position',[300 300 1150 600]);
movegui(hFig, 'center');
options = cellfun(@(c) c(end:-1:1), options, 'Uniform',false);
num = length(options);
%# get saved settings
selected = getappdata(hParentFig, 'opts');
%# top/bottom panels
hPanBot = uipanel('Parent',hFig, 'BorderType','none', ...
'Units','normalized', 'Position',[0 0.0 1 0.2]);
hPanTop = uipanel('Parent',hFig, 'BorderType','none', ...
'Units','normalized', 'Position',[0 0.2 1 0.2]);
%# buttongroups in top panel
hBtnGrp = zeros(1,num);
width = 1/num;
for i=1:num
%# create button group
hBtnGrp(i) = uibuttongroup('Parent',hPanTop, ...
'Units','normalized', 'Position',[(i-1)*width 0 width 1]);
%# populate it with radio buttons
height = 1./numel(options{i});
for j=1:numel(options{i})
h = uicontrol('Parent',hBtnGrp(i), 'Style','Radio', ...
'Units','normalized', 'Position',[0.05 (j-1)*height 0.9 height], ...
'String',options{i}{j});
%# set initially selected values
if strcmp(selected{i},options{i}{j})
set(hBtnGrp(i), 'SelectedObject',h)
end
end
end
%# save button in bottom panel
uicontrol('Parent',hPanBot, 'Style','pushbutton', ...
'Units','normalized', 'Position',[0.3 0.2 0.4 0.2], ...
'String','start', 'Callback',@callback)
%# save button callback function
function callback(o,e)
%# get selected values
hObjs = get(hBtnGrp(:), 'SelectedObject');
vals = get(cell2mat(hObjs),{'String'});
%# update settings
setappdata(hParentFig, 'opts',vals);
%# close options dialog
close(hFig)
end
end
谢谢大家! :]]
答案 0 :(得分:1)
您目前正在执行此操作:
% show the images
Im = imread(files{k});
AxesH = axes('Units', 'pixels', 'position', [0.5, 10, 400, 260], 'Visible', 'off');
image(Im, 'Parent', AxesH);
image
是一个奇怪的函数,因为在MATLAB中绘制函数 - 它并没有真正服从你期望的基于其他绘图函数的许多行为。
来自online documentation for image(以下重点是我的):
图像功能有两种形式:
调用newplot以确定绘制位置的高级函数 图形对象并设置以下轴属性:
XLim和YLim包围图像
从顶层到顶层,将图像放在刻度线和网格前面 线
YDir反转
查看[0 90]
一个低级函数,可将图像添加到当前轴而不会 调用newplot。低级函数参数列表只能包含 属性名称/属性值对。
这意味着如果要将图像添加到预先存在的轴组中,必须仅使用属性 - 值对。该函数的其他形式全部调用{{3} }。
要在您创建的轴上绘制内容,请使用以下格式:
image('Parent', axesH, 'CData', Im); #% add other property-value pairs as needed
请注意,必须同样设置y方向,限制,刻度等等,因为高级功能不再处理此问题。