如何在 Octave 中使用按钮在轴上显示图像?

How to display image on axis using pushbutton in Octave?

我正在使用 GNU Octave 4.2.1。在 Linux Debian 上。我正在尝试制作一个按钮(在 Octave 中称为 pushbutton)来打开像 jpeg 文件这样的图像并显示到轴上。到目前为止,我的代码如下所示:

%image preview
cmdOpenImage = uicontrol(
  mainForm = "style", "pushbutton", "string", "OPEN THE IMAGE",
  "position", [100,630, 100, 30]
)

按钮还在制作中,进度如下图:

%image preview
cmdOpenImage = uicontrol(
  mainFrm =  "style", "pushbutton", 
              "string", "OPEN THE IMAGE",
              "position", [100,630, 100, 30],
              "ButtonDownFcn", {@previewImage, "1"}
)

function previewImage(h, e, a1)
  i = imread('donuts.jpg');
imshow(i);  
endfunction

我之前在MATLAB中进行图像处理的应用如下所示:

function cmdOpenImage_Callback(hObject, eventdata, handles)
[a, b] = uigetfile();
i = imread([a, b]);
guidata(hobject, handles);
axes(handles.PreviewImage);
imshow(i);

关于 MATLAB 图像处理的上一个应用程序图片:


单击时按钮在轴上显示图像。

你的代码有语法错误,逻辑有点混乱,但足以让你明白你要做什么。这是一个工作版本:

%% In file 'imageViewer.m'
function imageViewer ()
  MainFrm = figure ( ...
    'position', [100, 100, 250, 350]); 

  TitleFrm = axes ( ... 
    'position', [0, 0.8, 1, 0.2], ... 
    'color',    [0.9, 0.95, 1], ...
    'xtick',    [], ... 
    'ytick',    [], ...  
    'xlim',     [0, 1], ... 
    'ylim',     [0, 1] );

  Title = text (0.05, 0.5, 'Preview Image', 'fontsize', 30);

  ImgFrm = axes ( ...
    'position', [0, 0.2, 1, 0.6], ... 
    'xtick',    [], ... 
    'ytick',    [], ...
    'xlim',     [0, 1], ... 
    'ylim',     [0, 1]);

  ButtonFrm = uicontrol (MainFrm, ...
    'style',    'pushbutton', ... 
    'string',   'OPEN THE IMAGE', ...
    'units',    'normalized', ...
    'position', [0, 0, 1, 0.2], ...
    'callback', { @previewImage, ImgFrm });
end

%% callback subfunction (in same file)
function previewImage (hObject, eventdata, ImageFrame)
  [fname, fpath] = uigetfile();
  Img = imread (fullfile(fpath, fname));
  axes(ImageFrame);
  imshow(Img, []);
  axis image off
end

然后从您的终端 运行 imageViewer()

---------->