Main Content

imgetfile

Display Open Image dialog box

Description

example

[filename,user_canceled] = imgetfiledisplays the Open Image dialog box. Use this dialog box in imaging applications to get the name of the image file a user wants to open. The Open Image dialog box includes only files that use supported image file formats (listed inimformats) and DICOM files. When the user selects a file and clicksOpen,imgetfilereturns the full path of the file infilenameand sets theuser_canceledreturn value tofalse. If the user clicksCancel,imgetfilereturns an empty character vector ('') infilenameand sets theuser_canceledreturn value totrue.

Note

The Open Image dialog box is modal; it blocks the MATLAB®command line until the user responds.

example

[filename,user_canceled] = imgetfile(Name,Value)supports name-value parameter arguments that you can use to control aspects of its behavior.

Examples

collapse all

Open the Open Image dialog box, and show the folder that contains the Image Processing Toolbox™ sample images.

sample_image_folder = fullfile(matlabroot,'toolbox/images/imdata'); [filename,user_canceled] = imgetfile('InitialPath',sample_image_folder)

Select an image in the list, and clickOpen.imgetfilereturns the full path of the image file selected as a character vector. Theuser_canceledreturn value is set tofalse.

filename = C:\Program Files\MATLAB\R2016b\toolbox\images\imdata\cameraman.tif user_canceled = logical 0

Open the Open Image dialog box. This example assumes you have a folder that contains sample images on your systemC:drive.

[文件名,user_canceled] =我getfile('InitialPath','C:\Temp\SampleImages','MultiSelect',true)

Select several images in the list usingShift+ClickorCtrl+Click.

ClickOpen.imgetfilereturns a cell array of character vectors that contain the full path of each image file. Theuser_canceledreturn value is set tofalse.

filename = 1×5 cellarrayColumns1through3'C:\Temp\SampleIma…''C:\Temp\SampleIma…''C:\Temp\SampleIma…'Columns4through5'C:\Temp\SampleIma…''C:\Temp\SampleIma…'user_canceled = logical 0

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, whereNameis the argument name andValueis the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

Example:[fname,user_canc] = imgetfile('InitialPath','C:\temp')

Folder displayed when the Open Image dialog box opens, specified as a string scalar or character vector. If you do not specify an initial path,imgetfileopens the dialog box at the last location where an image was successfully selected.

Data Types:char

Selection mode, specified as'on'or'off', or a Boolean valuetrueorfalse. The valuetrueor'on'turns on multiple selection, enabling a user to select more than one image in the dialog box usingShift+clickorCtrl+click. The valuefalseor'off'turns off multiple selection. If multiple selection is on, the output parameterfilename是一个单元阵列特征向量包含the full paths to the selected files.

Data Types:logical|char

Output Arguments

collapse all

Full path of image or images selected by the user, returned as a character vector or cell array of character vectors. If the user clickedCancel,filenameis an empty character vector ('').

User clickedCancel, returned as a Boolean scalar. The value istrueif the user clickedCancelorfalseif the user selected an image or images.

Version History

Introduced before R2006a