Main Content


Get pixel data of DICOM file

Since R2023a



    pixelData = getPixelData(dFile) gets the pixel data pixelData of the DICOM file specified by the dicomFile object dFile.


    pixelData = getPixelData(dFile,Rescale=rescale) specifies whether to rescale the pixel data. By default, the function rescales the pixel data.


    collapse all

    Import a DICOM file into the workspace. The DICOM file is part of a data set containing three CT volumes. The size of the entire data set is approximately 81 MB. Download the data set from the MathWorks® website, then unzip the folder.

    zipFile = matlab.internal.examples.downloadSupportFile("medical","");
    filepath = fileparts(zipFile);
    datapath = fullfile(filepath,"MedicalVolumeDICOMData/LungCT01/CT000000.dcm");
    dFile = dicomFile(datapath);

    Get the raw pixel data of the DICOM file.

    rawPixelData = getPixelData(dFile,Rescale=false);

    Visualize the raw pixel data.


    Get the rescaled pixel data of the DICOM file.

    rescaledPixelData = getPixelData(dFile);

    Visualize the rescaled pixel data.


    Observe that rescaling changes the range of the pixel data.

    [min(rawPixelData,[],"all") max(rawPixelData,[],"all")]
    ans = 1×2 int16 row vector
       -2000    2520
    [min(rescaledPixelData,[],"all") max(rescaledPixelData,[],"all")]
    ans = 1×2 int16 row vector
       -3024    1496

    Input Arguments

    collapse all

    DICOM file from which to retrieve the pixel data, specified as a dicomFile object.

    Rescale pixel data, specified as a logical 1 (true) or 0 (false). If rescale is true, the getPixelData function rescales the pixel data using the rescaleSlope and rescaleIntercept attributes of the DICOM file. Rescaling linearly transforms the on-disk representation of the pixel data to its in-memory representation. For example, for CT images, rescaling transforms the on-disk representation of intensity values to the standard Hounsfield units in the in-memory representation. If the rescaleSlope and rescaleIntercept attributes are not present in the DICOM file or if you specify this argument as false, the function returns the raw pixel data. You can choose to get the raw pixel data if you want to modify the pixel data and write it to a new DICOM file, to prevent repeated rescaling when reading pixel data from the new DICOM file.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical

    Output Arguments

    collapse all

    Pixel data of the DICOM file, returned as a 2-D numeric matrix or 3-D numeric array.

    Version History

    Introduced in R2023a