Main Content

imsave

Save image using interactive dialog window

Description

Use the imsave function to save an image using an interactive dialog window. Navigate your file system to determine where to save the image file, and specify the name of the file. Choose the graphics file format you want to use from among the image file formats listed in the Files of Type menu. For more information about using the tool, see Tips.

Save Image tool showing the contents of the current directory with controls to change the directory and specify the filename and filetype.

imsave saves the image in the current figure using a Save Image dialog window.

example

imsave(h) saves the image in graphics container h using a Save Image dialog window. Use this syntax when you want to save an image whose parent is not the current figure.

filename = imsave(___) returns the full path to the file, filename.

[filename,user_canceled] = imsave(___) also indicates whether you canceled the save operation.

Examples

collapse all

Read a grayscale image into the workspace. Display the image.

I = imread('coins.png');
imshow(I)

Process the image. This example creates a binary mask in which the background is black and the coins are white.

bw = imbinarize(I);
bw = imfill(bw,'holes');
imshow(bw,[])

Save the binary image to file by using the Save Image tool. You can navigate to the desired directory and specify the file name and file format. This example saves the image to the Desktop with the file name myMaskImage in the JPEG file format.

imsave

Input Arguments

collapse all

Graphics object containing the image, specified as a Figure, Panel, Axes, or Image object. If h is an axes or figure, then imsave uses the first image returned by findobj(h,Type="image").

Output Arguments

collapse all

Full path to file, returned as a character vector. If you cancel the save operation, then filename is an empty character array, ''.

User canceled operation, returned as false or true. If you press the Cancel button or close the save window, then imsave sets user_canceled to true; otherwise, false.

Tips

  • In contrast to the Save as option in the figure File menu, the Save Image tool saves only the image displayed in the figure. The Save as option in the figure window File menu saves the entire figure window, not just the image.

  • imsave uses imwrite to save the image, using default options.

  • If you specify a filename that already exists, then imsave displays a warning message. Select Yes to use the filename or No to return to the dialog to select another file name. If you select Yes, then the Save Image tool attempts to overwrite the target file.

  • The Save Image tool blocks the MATLAB® command line until you save the image or cancel the operation.

Version History

Introduced in R2007b