此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.2)
Import/Export 导入/导出 格式

JPEG (.jpg, .jpeg)

MIME type: image/jpeg
JPEG raster image and compression format.
Commonly used for photographic images by digital cameras and on the web.
JPEG is an acronym for Joint Photographic Experts Group.
Stores images as bitmaps at a resolution of 8 bits per color channel.
Binary format.
Uses a lossy compression method based on an 8×8 block-sized discrete cosine transform.
Supports different compression levels.
  • Import also supports parts of the Exif 2.2 metadata standard.
  • Import["file.jpg"] imports a JPEG file and returns an image.
  • Export["file.jpg", expr] exports an image, graphics or any other expression as a raster image to JPEG.
  • When exporting Mathematica graphics or arbitrary expressions to JPEG, the resulting image has the same raster size as its displayed form.
  • Image objects are by default exported at their raster size.
  • Because JPEG is a raster image format, all fonts are rasterized on export.
  • Import["file.jpg", elem] imports the specified element from a JPEG file.
  • Import["file.jpg", {elem, suba, subb, ...}] imports a subelement.
  • Import["file.jpg", {{elem1, elem2, ...}}] imports multiple elements.
  • The import format can be specified with Import["file", "JPEG"] or Import["file", {"JPEG", elem, ...}].
  • Export["file.jpg", expr, elem] creates a JPEG file by treating expr as specifying element elem.
  • Export["file.jpg", {expr1, expr2, ...}, {{elem1, elem2, ...}}] treats each expri as specifying the corresponding elemi.
  • Export["file.jpg", expr, opt1->val1, ...] exports expr with the specified option elements taken to have the specified values.
  • Export["file.jpg", {elem1->expr1, elem2->expr2, ...}, "Rules"] uses rules to specify the elements to be exported.
  • See the reference pages for full general information on Import and Export.
  • In the notebook front end, InsertPicture and the Open menu allow the import of a JPEG file into a cell.
"Elements" list of elements and options available in this file
"Rules"full list of rules for each element and option
"Options"list of rules for options, properties, and settings
  • Data representation elements:
"ColorMap"color reduction palette created on import
"Data"array of color values taken
"Graphics"Graphics object representing an image
"Image"raster image, given as an Image object
"GrayLevels"array of normalized gray-level values
"RGBColorArray"array of RGBColor objects
"RawData"array of indexed colors
  • Import and Export by default use the "Image" element for the JPEG format.
"BitDepth"bits used to represent each color channel in the file
"ColorSpace"color encoding used in the file
"ImageSize"raster dimensions
  • Individual Exif tags (available for Import):
"FocalLength"focal length in millimeters
"CameraTopOrientation"orientation of the camera when the picture was taken
"Manufacturer"maker of the camera or input device
"Model"model specification of the camera or input device
"Exposure"photographic exposure time in seconds
"Date"date and time the original picture was taken, given as a DateList specification
"Aperture"aperture setting at which the picture was taken, given in APEX units
"ISOSpeed"ISO 12232 speed rating of the camera or input device
  • General option:
ImageSizeAutomaticoverall image size
"ImageTopOrientation"Toporientation of the image as stored in the file
"ImageTopOrientation"Toporientation of the exported image
"Smoothing"0the JPEG smoothing parameter, given as a number in the range 0 to 1
  • When exporting a raster image to JPEG, no smoothing filter is applied by default.
  • Detailed properties and settings:
"ColorSpace"RGBColorcolor space of the image
"CompressionLevel"0.25sets the JPEG compression parameter
"Progressive"Falsewhether to store the image in a way that allows progressive display while the file is being loaded
  • "CompressionLevel" can be set to values in the range from 0 to 1, with larger values resulting in smaller file sizes.
  • Since JPEG uses a lossy compression method, higher compression levels correspond to lower-quality encodings.
Import a JPEG image as an image:
In[1]:=
Click for copyable input
Out[1]=
Get the pixel dimensions of this photo:
In[2]:=
Click for copyable input
Out[2]=
Show all Import elements available in the file:
In[3]:=
Click for copyable input
Out[3]=
Import metadata elements:
In[4]:=
Click for copyable input
Out[4]=
 
Read raw color data from the file and extract the first few pixels:
In[1]:=
Click for copyable input
Out[1]=
 
Export an image to JPEG:
In[1]:=
Click for copyable input
Out[1]=