0

我正在尝试将图像:“我”放在窗口的中心,如下所示:

在此处输入图像描述

我在第一个回调函数中写道:

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

我不确定,但我认为我不需要axesH。此外,轴让当前轴:/

有人可以告诉我如何解决吗?

这是我的代码:

 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

感谢大家!:]]

4

1 回答 1

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 中的绘图函数一样 - 它并没有真正遵守您基于其他绘图函数所期望的很多行为。

来自图像的在线文档(以下重点是我的):

图像函数有两种形式:

调用 newplot 以确定在何处绘制图形对象并设置以下轴属性的高级函数:

XLim 和 YLim 包围图像

分层到顶部以将图像放置在刻度线和网格线的前面

YDir 反转

查看到 [0 90]

无需调用 newplot 即可将图像添加到当前坐标区的低级函数。低级函数参数列表只能包含属性名称/属性值对。

这意味着如果要将图像添加到预先存在的一组轴,则必须仅使用属性值对。 该函数的其他形式都调用newplot

要将某些内容绘制到您创建的轴上,请使用以下形式:

image('Parent', axesH, 'CData', Im); #% add other property-value pairs as needed

请注意,设置 y 方向、限制、刻度线等也必须完成,因为高级函数不再处理这些了。

于 2012-06-01T02:48:47.967 回答