MATLAB显示多幅图像 [英] MATLAB Display Multiple Images

查看:326
本文介绍了MATLAB显示多幅图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计一个图形用户界面中,用户将preSS一个按钮来选择图像,然后在我所创建的轴显示出来。

Hi I am designing a gui in which the user will press a button to select images and then display them in the axes I have created.

我不知道如何在一个特定的轴显示一个图像,但我怎么能选择和显示一个以上?

I do know how to display one image on a specific axes but how could I select and display more than one ?

感谢

推荐答案

如果该文件是在同一文件夹,你可以使用:

if the files are in the same folder you can use:

[filename, pathname, filterindex] = uigetfile( {file_types_to_display}, 'Window_Title', 'MultiSelect', 'on');

这将产生与所选择的文件名称以及路径的细胞。那么你可以使用的strcat或类似的生产文件的完整路径,然后使用负载,以便将它们添加到工作区。

this will produce a cell with the selected file name as well as the paths. you can then use strcat or similar to produce the full path of the files to then use load in order to add them to the workspace.

uigetfile不与在多个文件夹中的文件。

uigetfile doesn't work with files in multiple folders.

另一个选择是做某种递归搜索,列出根据文件扩展名或名称的文件夹中的所有文件,然后进行加载你想要的。这样,你就必须在文件夹和子文件中的所有文件,所以你可以在多个文件夹中使用的图像。搜索MATLAB交易所递归搜索文件code。

another option is to do some sort of recursive search to list all files in the folder based on file extension or name and then proceed to load the ones you want. this way you would have all files in the folder and subfolder so you can use images in multiple folders. search MATLAB Exchange for recursive file search code.

修改1
通过使用uigetfile显示所选的图片,你需要把code选择和引导产生的按钮下方回调的显示图像。

EDIT 1: to display the selected images by using uigetfile, you need to put the code to select and display the images beneath the push-button callback generated by guide.

function pushbutton1_Callback(hObject, eventdata, handles)
%multi-file selection
[filename, pathname, ~] = uigetfile({  '*.jpg'}, 'Pick 3 files',...
'MultiSelect', 'on');

%generation of strings containing the full path to the selected images.
img1 = strcat(pathname, filename{1});
img2 = strcat(pathname, filename{2});
img3 = strcat(pathname, filename{3});

%assign an axes handle to preced imshow and use imshow to display the images
% in individual axes.
axes(handles.axes1);
imshow(img1);
axes(handles.axes2);
imshow(img2);
axes(handles.axes3);
imshow(img3);

以上code,您可以从文件夹中选择任意数量的图像,但它只能说明在产生的细胞文件名第3图像。要能够选择尽可能多的图像,只要你想,然后滚动查看你需要的前锋两个按钮回调和当年..

the above code lets you select any number of images from a folder however it only shows the first 3 images in the generated cell 'filename'. to be able to select as many images as you want then scroll through them you need two more push-button callbacks for forward and back then..

function pushbutton1_Callback(hObject, eventdata, handles)
%assign global variable so the other pushbuttons can access the values
global k num_imgs pathname filename

%uigetfile in multiselect mode to select multiple files
[filename, pathname, ~] = uigetfile({'*.jpg'},...
    'Pick 3 files',...
    'MultiSelect', 'on');
%initialisation for which image to display after selection is made.
k = 1;
%dicern the number of images that where selected
num_imgs = length(filename);
%create string of full path to first image in selection and display
%the image
img1 = strcat(pathname, filename{k});
axes(handles.axes1);
imshow(img1);

function pushbutton2_Callback(hObject, eventdata, handles)
global k num_imgs pathname filename
%using global values of k create if statement to stop scrolling beyond the
%number of available images.
if k > num_imgs
    %if the index value of the image to be displayed is greater than the
    %number available default to the last image in the list
    k = num_imgs;
else
    %iterate upwards with each click of pushbutton2 to display the next
    %image in the series.
    k = k + 1;
    img1 = strcat(pathname, filename{k});
    axes(handles.axes1);
    imshow(img1);
end

function pushbutton3_Callback(hObject, eventdata, handles)
global k num_imgs pathname filename
if k < 1
    %if the index value of the image to be displayed is less than 1
    %default to the first image in the list
    k = 1;
else
    k = k - 1;
    img1 = strcat(pathname, filename{k});
    axes(handles.axes1);
    imshow(img1);
end

EDIT2 :@ user3755632我不知道我明白了。 filename是一个字符串,可以喂到字符串作为imshow只要该字符串包括文件名和路径,如果它位于工作目录之外的显示图像。你不使用uigetfile选择的影像? (不能上的问题,由于缺乏信誉评论)

EDIT2: @user3755632 i'm not sure i understand. filename is a string and you can feed strings into imshow to display the image as long as the string includes the file name and the path if it is located outside the working directory. are you not using uigetfile to select the images? (can't comment on question due to lack of reputation)

这篇关于MATLAB显示多幅图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆