【问题标题】:how to browse image and process it before it's displayed to axes in GUI matlab如何在 GUI matlab 中显示到轴之前浏览图像并对其进行处理
【发布时间】:2012-09-15 13:59:47
【问题描述】:

我想用 matlab 创建一个 GUI,浏览图像并在将其显示到某些轴之前对其进行处理。

我当前的程序无法浏览图片,我想显示的图片和之前的流程有关。是否可以通过一个按钮浏览所有处理过的图像并将其显示到轴上?有人可以帮我为这个示例程序创建 GUI 吗?

folder = 'D:\wildlife';
   baseFileName = 'page-6.png';
   fullFileName = fullfile(folder, baseFileName);
   % Get the full filename, with path prepended.
   fullFileName = fullfile(folder, baseFileName);
   if ~exist(fullFileName, 'file')
    % Didn't find it there.  Check the search path for it.
    fullFileName = baseFileName; % No path this time.
    if ~exist(fullFileName, 'file')
        % Still didn't find it.  Alert user.
        errorMessage = sprintf('Error: %Gambar tidak ditemukan.', fullFileName);
        uiwait(warndlg(errorMessage));
        return;
    end
end
rgbImage = imread(fullFileName);

% Get the dimensions of the image.  numberOfColorBands should be = .
[rows columns numberOfColorBands] = size(rgbImage);

% Display the original color image.
subplot(2, 3,  1);
imshow(rgbImage);
title('Gambar Asli', 'FontSize', fontSize);

% Enlarge figure to full screen.
set(gcf, 'units','normalized','outerposition',[0 0 1 1]);

%set the morphology
SE = strel ('square', 3);
 j=imerode (rgbImage, SE);
subplot(2, 3,  2);
imshow(j);
title('Penebalan Citra', 'FontSize', fontSize);

% Binarize to find black pixels
% Find where either red, green, or blue channel is dark.
thresholdValue = 55;
binaryImage = j(:,:, 1) < thresholdValue | j(:,:, 2) < thresholdValue | j(:,:, 3) < thresholdValue;

% Display the image.
subplot(2, 3,  3);
imshow(binaryImage);
title('Citra Biner', 'FontSize', fontSize);

% Fill the image
filledImage = imfill(binaryImage, 'holes');
% Display the image.
subplot(2, 3,  4);
imshow(filledImage);
title('Pengisian Citra Biner', 'FontSize', fontSize);
drawnow;

【问题讨论】:

    标签: image matlab user-interface processing axes


    【解决方案1】:

    要创建 GUI,Matlab 的 GUIDE 功能有很好的文档记录,并且相对易于使用和学习 (http://www.mathworks.com/help/matlab/gui-building-basics.html)。只需在 Matlab 提示符下键入“指南”即可调出快速启动菜单。

    创建新的空白 GUI 后,您可以添加一个按钮和任意数量的轴来显示各种图像(上面的示例代码为 4 个)。然后可以将浏览、处理和显示图像的代码放在按钮的回调中。要打开回调代码,请右键单击按钮并从菜单中选择“查看回调 -> 回调”。

    然后您可以使用类似以下的方式来浏览所需的图像:

    [baseFileName, folder, FilterIndex] = uigetfile('*.png');
    

    要在所需的轴上显示图像,请在调用 'imshow' 时将适当的轴句柄指定为 'Parent' 参数,而不是使用 'subplot':

    % Display the original color image.
    fullFileName = [folder baseFileName];
    rgbImage = imread(fullFileName);
    imshow(rgbImage, 'Parent', handles.axes1);
    

    【讨论】:

      猜你喜欢
      • 2015-07-26
      • 1970-01-01
      • 2016-10-04
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-10
      相关资源
      最近更新 更多