Main Content

imgetfile

Display Open Image dialog box

Description

example

[filename,user_canceled] = imgetfile displays 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 in imformats) and DICOM files. When the user selects a file and clicks Open, imgetfile returns the full path of the file in filename and sets the user_canceled return value to false. If the user clicks Cancel, imgetfile returns an empty character vector ('') in filename and sets the user_canceled return value to true.

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 click Open. imgetfile returns the full path of the image file selected as a character vector. The user_canceled return value is set to false.

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 system C: drive.

[filename,user_canceled] = imgetfile('InitialPath','C:\Temp\SampleImages','MultiSelect',true)

Select several images in the list using Shift+Click or Ctrl+Click.

Click Open. imgetfile returns a cell array of character vectors that contain the full path of each image file. The user_canceled return value is set to false.

filename =

  1×5 cell array

  Columns 1 through 3

    'C:\Temp\SampleIma…'    'C:\Temp\SampleIma…'    'C:\Temp\SampleIma…'

  Columns 4 through 5

    'C:\Temp\SampleIma…'    'C:\Temp\SampleIma…'


user_canceled =

  logical

   0

Input Arguments

collapse all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is 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 enclose Name in 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, imgetfile opens 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 value true or false. The value true or 'on' turns on multiple selection, enabling a user to select more than one image in the dialog box using Shift+click or Ctrl+click. The value false or 'off' turns off multiple selection. If multiple selection is on, the output parameter filename is a cell array of character vectors containing 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 clicked Cancel, filename is an empty character vector ('').

User clicked Cancel, returned as a Boolean scalar. The value is true if the user clicked Cancel or false if the user selected an image or images.

Version History

Introduced before R2006a