Dynamic grid of images in MATLAB

断了今生、忘了曾经 提交于 2019-12-24 06:58:30

问题


I'm working on creating a GUI in matlab using GUIDE. However, i'm not exactly sure how to do the following, and was looking for some tips/advice.

Problem

I want to open a directory and display all the images in that directory in the GUI interface when if it's selected. However, since I will never know exactly how many images there are I am not entirely sure how to do this in the GUI.

Essentially, I want to open the directory and all the images to be displayed in a grid on the GUI similar to that in iphoto.

Current code

Currently, I can open a directory fine, and get all the required information as follows:

directory = uigetdir(pwd, 'Directory Selector');
files = dir(fullfile(directory, '*.jpg'));  
strcat(strcat(directory, '/') , files.name) %outputs each file's location

I'm just not sure how to translate this information into the GUI without writing numerous handles.axes1. I understand that since I know this info I could loop over them, but would I not have to create the axes to begin with?


回答1:


You probably don't want to do this with individual controls - the reason is that MATLAB will have to render each and every one, which will be slow if the directory has a lot of images. Clearly, you can only display a certain number of images on screen at once. You would also have to write your own scrolling code (or some kind of pagination control).

If you have MATLAB > R2008, you can put images in uitable cells using HTML:

% Example for a control with a 'String' property
set(handles.myControl, 'String', '<html><b>Logo</b>: <img src="http://UndocumentedMatlab.com/images/logo_68x60.png"/></html>');

See also this post and this Undocumented MATLAB page.

A different option would be to use the Windows common controls ListView.

A simpler way of doing this would be to have a single image and a listbox of files; an example is here




回答2:


You can add components to a GUI pprogrammatically. There's more information here.

Each new axes can be added with something like this:

ah = axes('Parent',hObject,'Position',[left bottom width height]);

where left, bottom, width and height define the size and position of the axes. You'll need to change the position for each axes you create and keep track of the axes handles.



来源:https://stackoverflow.com/questions/16288941/dynamic-grid-of-images-in-matlab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!