This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.


Display Open Image dialog box


  • [filename,user_canceled] = imgetfile
  • [filename,user_canceled] = imgetfile(Name,Value)



[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.


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


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 =



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 =



Input Arguments

collapse all

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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

collapse all

Folder displayed when the Open Image dialog box opens, specified as a 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 a Boolean scalar or the character vector 'on' or ‘off'. 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.

Introduced before R2006a

Was this topic helpful?