Summary of methods for saving images in MATLAB

Source: Internet
Author: User

Thanks to the summary of the conscientious.

Reprint: http://blog.csdn.net/holybin/article/details/39502077

1. Using the Imwrite function

If the image is IMG, you can use Imwrite (img, ' result.jpg '); This method saves the image size and displays the same size. The following method does not get the same size as the original image:

2. Save directly as

In figure, use the menu file->saveas-> to select the Save form (which can be saved in the format fig,eps,jpeg,gif,png,bmp, etc.). The disadvantage of this is that there is a great sacrifice for the image sharpness that is saved.

3. Copy and paste

Using the menu edit->copyfigure in figure, the image is copied to the Clipboard. Note that you want to select "Bitmap" in the "copy Options".

4, with the SaveAs command

MATLAB provides a direct SaveAs function to save the image in a specified figure or a block diagram in Simulink. The SaveAs format is: SaveAs (GCA, filename, FileFormat), with three parameters:

(1) GCA: Graphic handle, if the graphics window title bar is "Figure 3", then the handle is 3; You can also get the current window handle directly from the GCF.

(2) FileName: Single quote string, specifying file name

(3) FileFormat: Single quote string, specifying storage format

Example:

[Plain] View plain copy SaveAs (GCF, ' save.jpg ');     % Save the image of the current window in SaveAs (2, ' save.jpg '); % Save Figure 2 window image 5, print function

The print function operates the printer using the plot function followed by the print function to save the image. Print is in the format: print (Figure_handle,fileformat,filename) with three parameters:

(1) Figure_handle: Graphic handle, if the graphics window title bar is "Figure 3", then the handle is 3; You can also get the current window handle directly from the GCF

(2) FileFormat: Single quote string, specifying storage format:

PNG format: '-dpng '

JPEG format: '-djpeg ',

TIFF format: '-dtiff '

BMP format: '-dbitmap '

GIF format: '-dgif '

EMF lossless format: '-dmeta '

(3) FileName: file name

Example 1: Displaying an image and saving

[Plain] View plain copy x=-pi:2*pi/1000:pi;   Y=cos (x); Plot (x, y);p rint (GCF, '-djpeg ', ' abc.jpg ')% draw the image and save it in JPG format

Example 2: Save directly without displaying an image

[Plain] View plain copy x=-pi:2*pi/1000:pi;   Set (figure (1), ' visible ', ' off '); Plot (X,sin (x)); Print (GCF, '-dpng ', ' abc.png ')% does not display images directly saved to PNG format

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.