Main Content


Display Open Image dialog box to get filename of image file



filename = imgetfile displays the Open Image dialog box. Use this dialog box to get the name of an image file that you want to open. The Open Image dialog box includes only files that use supported image file formats (listed in imformats) and DICOM files.

After you get the filename, you can read the image file by using functions such as imread.


The Open Image dialog box blocks the MATLAB® command line until you click Open or cancel the operation.


filename = imgetfile(Name=Value) uses name-value arguments that enable you to specify the initial path or to select multiple image files.

[filename,user_canceled] = imgetfile(___) also returns a logical flag that indicates whether the operation was canceled.


collapse all

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

dataDir = fullfile(matlabroot,"toolbox/images/imdata");
filename = imgetfile(InitialPath=dataDir)

Open Images dialog box with one file selected.

Select an image in the list, and click Open. imgetfile returns the full path of the image file selected as a character vector.

filename =

  'C:\Program Files\MATLAB\R2024a\toolbox\images\imdata\cameraman.tif'

Read the image into the workspace.

im = imread(filename);

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

filenames = imgetfile(InitialPath="C:\Temp\SampleImages", ...

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

Open Images dialog box with five files selected.

Click Open. imgetfile returns a cell array of character vectors that contain the full path of each image file.

filenames =

  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…'

Create an image datastore containing the files.

imds = imageDatastore(filenames);

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.

Example: filename = imgetfile(InitialPath="C:\temp") specifies the initial path as "C:\temp".

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: filename = imgetfile("InitialPath","C:\temp") specifies the initial path as "C:\temp".

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

Data Types: char | string

Multiple selection mode, specified as "on" or "off", or a logical true or false. The value true ("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 ("off") turns off multiple selection. If multiple selection is on, the output argument 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 you click Cancel or close the Open Image dialog box, then imgetfile returns filename as an empty character vector ('').

Operation was canceled, returned as true or false. If you click Cancel or close the Open Image dialog box, then imgetfile returns user_canceled as true (1). If you click Save, then imgetfile returns user_canceled as false (0).

Version History

Introduced before R2006a