Main Content

imputfile

Display Save Image dialog box to set filename of image file

Description

filename = imputfile opens the Save Image dialog box, which enables you to interactively specify the full name of an image file including the file path and extension. Using the dialog box, you can navigate to folders in a file system and select a particular file or specify the name of a new file.

After you have specified the filename, you can save an image file with that filename by using functions such as imwrite.

Note

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

example

[filename,ext] = imputfile also returns the file extension, ext.

[filename,ext,user_canceled] = imputfile also returns a logical flag that indicates whether the operation was canceled.

Examples

collapse all

Open the Save Image dialog box.

filename = imputfile

Save Image dialog box

To view only images in Portable Network Graphics (PNG) format, select the format from the Save as type menu. imputfile limits the types of files displayed in the dialog box to the image file format selected in the Save as type menu.

Save as type dropdown menu within the Save Image dialog box. The Portable Network Graphics (*.png) option is selected from a list of common graphics file formats.

Specify a new file name and click Save. imputfile returns the full path of the filename you specified, the file extension, and the logical value false, meaning that you did not click Cancel. Note that imputfile automatically adds the file extension of the format you selected to the file name.

File name menu within the Save Image dialog box. A sample filename "mytest" is entered without a file extension.

filename =

  1×37 char array

    '\\home$\Documents\MATLAB\mytest.png'

Read an image, perform a simple image processing operation, then save the result to the location specified by filename.

im = imread("peppers.png");
gray = rgb2gray(im);
imwrite(gray,filename)

Output Arguments

collapse all

Name of file, returned as a character array.

If you click Cancel or close the Save Image dialog box, then imputfile returns filename as an empty character vector ('').

File extension of a supported file format, returned as a character array.

If you click Cancel or close the Save Image dialog box, then imputfile returns ext as an empty character vector ('').

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

Data Types: logical

Version History

Introduced in R2007b