接口:
dicominfo - 获取.dcm的信息
dicominfo
Read metadata from DICOM message
Syntax
info = dicominfo(filename)
info = dicominfo(filename, 'dictionary', D)
Description
info = dicominfo(filename) reads the metadata from the compliant Digital Imaging and Communications in Medicine (DICOM) file specified in the string filename.
info = dicominfo(filename, 'dictionary', D) uses the data dictionary file given in the string D to read the DICOM message. The file in D must be on the MATLAB search path. The default file is dicom-dict.mat.
Examples
info = dicominfo('CT-MONO2-16-ankle.dcm')
info =
Filename: [1x62 char]
FileModDate: '18-Dec-2000 11:06:43'
FileSize: 525436
Format: 'DICOM'
FormatVersion: 3
Width: 512
Height: 512
BitDepth: 16
ColorType: 'grayscale'
SelectedFrames: []
FileStruct: [1x1 struct]
StartOfPixelData: 1140
FileMetaInformationGroupLength: 192
FileMetaInformationVersion: [2x1 uint8]
MediaStorageSOPClassUID: '1.2.840.10008.5.1.4.1.1.7'
dicomread - 读.dcm
dicomread
Read DICOM image
Syntax
X = dicomread(filename)
X = dicomread(info)
[X,map] = dicomread(...)
[X,map,alpha] = dicomread(...)
[X,map,alpha,overlays] = dicomread(...)
[...] = dicomread(filename, 'frames', v)
Description
X = dicomread(filename) reads the image data from the compliant Digital Imaging and Communications in Medicine (DICOM) file filename. For single-frame grayscale images, X is an M-by-N array. For single-frame true-color images, X is an M-by-N-by-3 array. Multiframe images are always 4-D arrays.
X = dicomread(info) reads the image data from the message referenced in the DICOM metadata structure info. The info structure is produced by the dicominfo function.
[X,map] = dicomread(...) returns the image X and the colormap map. If X is a grayscale or true-color image, map is empty.
[X,map,alpha] = dicomread(...) returns the image X, the colormap map, and an alpha channel matrix for X. The values of alpha are 0 if the pixel is opaque; otherwise they are row indices into map. The RGB value in map should be substituted for the value in X to use alpha. alpha has the same height and width as X and is 4-D for a multiframe image.
[X,map,alpha,overlays] = dicomread(...) returns the image X, the colormap map, an alpha channel matrix for X, and any overlays from the DICOM file. Each overlay is a 1-bit black and white image with the same height and width as X. If multiple overlays are present in the file, overlays is a 4-D multiframe image. If no overlays are in the file, overlays is empty.
[...] = dicomread(filename, 'frames', v) reads only the frames in the vector v from the image. v must be an integer scalar, a vector of integers, or the string 'all'. The default value is 'all'.
Tips
The dicomread function supports both reversible (lossless) and irreversible (lossy) JPEG-2000 compression in DICOM files.
Class Support
X can be uint8, int8, uint16, or int16. map must be double. alpha has the same size and type as X. overlays is a logical array.
Examples
Use dicomread to retrieve the data array, X, and colormap matrix, map, needed to create a montage.
[X, map] = dicomread('US-PAL-8-10x-echo.dcm');
montage(X, map, 'Size', [2 5]);
Call dicomread with the information retrieved from the DICOM file using dicominfo and display the image using imshow. Adjust the contrast of the image using imcontrast.
info = dicominfo('CT-MONO2-16-ankle.dcm');
Y = dicomread(info);
figure, imshow(Y);
imcontrast;
dicomwrite - 写.dcm
dicomwrite
Write images as DICOM files
Syntax
dicomwrite(X, filename)
dicomwrite(X, map, filename)
dicomwrite(..., param1, value1, param2, value2, ...)
dicomwrite(..., 'ObjectType', IOD,...)
dicomwrite(..., 'SOPClassUID', UID,...)
dicomwrite(..., meta_struct,...)
dicomwrite(..., info,...)
status = dicomwrite(...)
Description
dicomwrite(X, filename) writes the binary, grayscale, or truecolor image X to the file filename, where filename is a string specifying the name of the Digital Imaging and Communications in Medicine (DICOM) file to create.
dicomwrite(X, map, filename) writes the indexed image X with colormap map.
dicomwrite(..., param1, value1, param2, value2, ...) specifies optional metadata to write to the DICOM file or parameters that affect how the file is written. param1 is a string containing the metadata attribute name or a dicomwrite-specific option. value1 is the corresponding value for the attribute or option.
To find a list of the DICOM attributes that you can specify, see the data dictionary file, dicom-dict.txt, included with the Image Processing Toolbox software. The following table lists the options that you can specify, in alphabetical order. Default values are enclosed in braces ({}).
dicomwrite(..., 'ObjectType', IOD,...) writes a file containing the necessary metadata for a particular type of DICOM Information Object (IOD). Supported IODs are
'Secondary Capture Image Storage' (default)
'CT Image Storage'
'MR Image Storage'
dicomwrite(..., 'SOPClassUID', UID,...) provides an alternate method for specifying the IOD to create. UID is the DICOM unique identifier corresponding to one of the IODs listed above.
dicomwrite(..., meta_struct,...) specifies optional metadata or file options in structure meta_struct. The names of fields in meta_struct must be the names of DICOM file attributes or options. The value of a field is the value you want to assign to the attribute or option.
dicomwrite(..., info,...) specifies metadata in the metadata structure info, which is produced by the dicominfo function. For more information about this structure, see dicominfo.
status = dicomwrite(...) returns information about the metadata and the descriptions used to generate the DICOM file. This syntax can be useful when you specify an info structure that was created by dicominfo to the dicomwrite function. An info structure can contain many fields. If no metadata was specified, dicomwrite returns an empty matrix ([]).
The structure returned by dicomwrite contains these fields:
Tips
The DICOM format specification lists several Information Object Definitions (IODs) that can be created. These IODs correspond to images and metadata produced by different real-world modalities (e.g., MR, X-ray, Ultrasound, etc.). For each type of IOD, the DICOM specification defines the set of metadata that must be present and possible values for other metadata.
dicomwrite fully implements a limited number of these IODs, listed above in the ObjectType syntax. For these IODs, dicomwrite verifies that all required metadata attributes are present, creates missing attributes if necessary, and specifies default values where possible. Using these supported IODs is the best way to ensure that the files you create conform to the DICOM specification. This is dicomwrite default behavior and corresponds to the CreateMode option value of 'Create'.
To write DICOM files for IODs that dicomwrite doesn't implement, use the 'Copy' value for the CreateMode option. In this mode, dicomwrite writes the image data to a file including the metadata that you specify as a parameter, shown above in the info syntax. The purpose of this option is to take metadata from an existing file of the same modality or IOD and use it to create a new DICOM file with different image pixel data.
Note :Because dicomwrite copies metadata to the file without verification in 'copy' mode, it is possible to create a DICOM file that does not conform to the DICOM standard. For example, the file may be missing required metadata, contain superfluous metadata, or the metadata may no longer correspond to the modality settings used to generate the original image. When using 'Copy' mode, make sure that the metadata you use is from the same modality and IOD. If the copy you make is unrelated to the original image, use dicomuid to create new unique identifiers for series and study metadata. See the IOD descriptions in Part 3 of the DICOM specification for more information on appropriate IOD values.
Examples
Read a CT image from the sample DICOM file included with the toolbox and then write the CT image to a file, creating a secondary capture image.
X = dicomread('CT-MONO2-16-ankle.dcm');
dicomwrite(X, 'sc_file.dcm');
Write the CT image, X, to a DICOM file along with its metadata. Use the dicominfo function to retrieve metadata from a DICOM file.
metadata = dicominfo('CT-MONO2-16-ankle.dcm');
dicomwrite(X, 'ct_file.dcm', metadata);
Copy all metadata from one file to another. In this mode, dicomwrite does not verify the metadata written to the file.
dicomwrite(X, 'ct_copy.dcm', metadata, 'CreateMode', 'copy');
dicominfo返回的结果:
实例:
metadata = dicominfo('1.dcm');
img = dicomread(metadata);
img1 = proc(img);
dicomwrite(img1,'2.dcm', 'CreateMode','Copy',metadata);
通过修改metadata的值,可以自定义输出.dcm的属性