0

次のように、ウィンドウの中央に「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

よくわかりませんが、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でのプロット関数のように、少し奇妙な関数です。他のプロット関数に基づいて期待される多くの動作には実際には従いません。

画像のオンラインドキュメントから(以下の強調は私のものです):

image関数には2つの形式があります。

newplotを呼び出して、グラフィックスオブジェクトを描画する場所を決定し、次のAxesプロパティを設定する高レベルの関数:

画像を囲むXLimとYLim

目盛りとグリッド線の前に画像を配置するには、上に重ねます

反転するYDir

[090]を表示

newplotを呼び出さずに現在の軸に画像を追加する低レベルの関数。低レベルの関数の引数リストには、プロパティ名とプロパティ値のペアのみを含めることができます。

つまり、既存の軸のセットに画像を追加する場合は、プロパティと値のペアのみを使用する必要があります。 関数の他の形式はすべてnewplotを呼び出します。

作成した軸に何かをプロットするには、次のフォームを使用します。

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

y方向、制限、目盛りなどの設定なども行う必要があることに注意してください。これは、高レベルの関数がそれを処理しなくなったためです。

于 2012-06-01T02:48:47.967 に答える