File Exchange Pick of the Week

Our best user submissions

Structure Display

Posted by Sean de Wolski,

Sean's pick this week is Structure Display by Thomas Deneux.

Contents

Structures in MATLAB

A structure in MATLAB is a container for heterogenous data that you reference by a name. Let's take a look at a simple structure: we will reference two fields of S named A and B (I don't win too many awards for creativity!).

S.A = 'Hello World';
S.B = pi;
disp(S)
    A: 'Hello World'
    B: 3.1416

This level of display is sufficient for a simple structure. But what about a more complex structure with possibly nested structures inside of it?

S.C = S; % insert S into one field of S, structure inception?
disp(S)
    A: 'Hello World'
    B: 3.1416
    C: [1x1 struct]

The built in display of the structure shows the high-level summary of the fields it contains, not the detailed version which could be complex. Sometimes this additional information is useful, especially for debugging.

Here's the display with fn_structdisp

fn_structdisp(S);
S:
    A: 'Hello World'
    B: 3.1416
    C: [1x1 struct]
S.B:
    3.1416
S.C:
    A: 'Hello World'
    B: 3.1416
S.C.B:
    3.1416

Metadata

One of the places this type of display is really useful is when looking at metadata for files where the meta data can be logically grouped in an array of nested structures.

I have the images from a CT scan of my left ankle that I had taken after a wakeboarding accident a couple of summers ago. We'll read the metadata into MATLAB using dicominfo. Even though I likely trust any human reading this blog, I'm still going to anonymize the file to hide my personal information like name, birthdate etc:

% Anonymize
fn = 'CT000000';
anonfn = [fn '_anon'];
dicomanon(fn,anonfn);

% Read in info:
info = dicominfo(anonfn);

Now let's look at the simple display and the complex display using Thomas' fn_structdisp. You'll be able to see how fn_structdisp unrolls the nested structures to reveal their contents.

Regular Display

disp(info)
                          Filename: 'C:\Documents\MATLAB\potw\StructDisp\C...'
                       FileModDate: '08-Apr-2015 22:35:13'
                          FileSize: 559084
                            Format: 'DICOM'
                     FormatVersion: 3
                             Width: 512
                            Height: 512
                          BitDepth: 16
                         ColorType: 'grayscale'
    FileMetaInformationGroupLength: 222
        FileMetaInformationVersion: [2x1 uint8]
           MediaStorageSOPClassUID: '1.2.840.10008.5.1.4.1.1.2'
        MediaStorageSOPInstanceUID: '1.3.6.1.4.1.9590.100.1.2.515513049128...'
                 TransferSyntaxUID: '1.2.840.10008.1.2.1'
            ImplementationClassUID: '1.3.6.1.4.1.9590.100.1.3.100.7.1'
         ImplementationVersionName: 'MATLAB IPT 7.1'
      SourceApplicationEntityTitle: 'DCF'
              SpecificCharacterSet: 'ISO_IR 100'
                         ImageType: 'DERIVED\SECONDARY\OTHER\CSA MPR THICK...'
                       SOPClassUID: '1.2.840.10008.5.1.4.1.1.2'
                    SOPInstanceUID: '1.3.6.1.4.1.9590.100.1.2.515513049128...'
                         StudyDate: '20131007'
                        SeriesDate: '20131007'
                   AcquisitionDate: '20131007'
                       ContentDate: '20131007'
                         StudyTime: '184618.640000'
                        SeriesTime: '184046.156000'
                   AcquisitionTime: '184905.956783'
                       ContentTime: '184046.171000'
                   AccessionNumber: ''
                          Modality: 'CT'
                      Manufacturer: 'SIEMENS'
                   InstitutionName: ''
            ReferringPhysicianName: [1x1 struct]
             ManufacturerModelName: 'Sensation 64'
           ReferencedImageSequence: [1x1 struct]
                       PatientName: [1x1 struct]
                         PatientID: ''
                  PatientBirthDate: ''
                        PatientSex: ''
            PatientIdentityRemoved: 'YES'
            DeidentificationMethod: 'DICOMANON (rev R2010a) - PS 3.15-2008...'
                  BodyPartExamined: 'EXTREMITY'
                    SliceThickness: 2
                               KVP: 120
                   SoftwareVersion: 'syngo CT 2009E'
          DistanceSourceToDetector: 1040
           DistanceSourceToPatient: 570
                GantryDetectorTilt: 0
                       TableHeight: 179
                 RotationDirection: 'CW'
                        FilterType: '0'
                    GeneratorPower: 10
                         FocalSpot: 1.2000
             DateOfLastCalibration: '20131007'
             TimeOfLastCalibration: '061322.000000'
                 ConvolutionKernel: 'B60s'
                   PatientPosition: 'FFS'
                  StudyInstanceUID: '1.3.6.1.4.1.9590.100.1.2.328077616812...'
                 SeriesInstanceUID: '1.3.6.1.4.1.9590.100.1.2.237595359611...'
                           StudyID: ''
                      SeriesNumber: 505
                 AcquisitionNumber: 3
                    InstanceNumber: 1
              ImagePositionPatient: [3x1 double]
           ImageOrientationPatient: [6x1 double]
               FrameOfReferenceUID: '1.3.6.1.4.1.9590.100.1.2.396775851196...'
        PositionReferenceIndicator: ''
                   SamplesPerPixel: 1
         PhotometricInterpretation: 'MONOCHROME2'
                              Rows: 512
                           Columns: 512
                      PixelSpacing: [2x1 double]
                     BitsAllocated: 16
                        BitsStored: 16
                           HighBit: 15
               PixelRepresentation: 0
           SmallestImagePixelValue: 0
            LargestImagePixelValue: 2802
                      WindowCenter: 240
                       WindowWidth: 1200
                  RescaleIntercept: -1024
                      RescaleSlope: 1
      WindowCenterWidthExplanation: 'WINDOW1\WINDOW2'
             LossyImageCompression: '00'
               RequestingPhysician: [1x1 struct]
     RequestedProcedureDescription: 'CT LOWER EXTREMITY C-'
                     OverlayRows_0: 512
                  OverlayColumns_0: 512
         NumberOfFramesInOverlay_0: 1
              OverlayDescription_0: 'Siemens MedCom Object Graphics'
                     OverlayType_0: 'G'
                   OverlayOrigin_0: [2x1 int16]
                ImageFrameOrigin_0: 1
            OverlayBitsAllocated_0: 1
              OverlayBitPosition_0: 0
                     OverlayData_0: [512x512 logical]

fn_structdisp Display

fn_structdisp(info);
info:
                          Filename: 'C:\Documents\MATLAB\potw\StructDisp\C...'
                       FileModDate: '08-Apr-2015 22:35:13'
                          FileSize: 559084
                            Format: 'DICOM'
                     FormatVersion: 3
                             Width: 512
                            Height: 512
                          BitDepth: 16
                         ColorType: 'grayscale'
    FileMetaInformationGroupLength: 222
        FileMetaInformationVersion: [2x1 uint8]
           MediaStorageSOPClassUID: '1.2.840.10008.5.1.4.1.1.2'
        MediaStorageSOPInstanceUID: '1.3.6.1.4.1.9590.100.1.2.515513049128...'
                 TransferSyntaxUID: '1.2.840.10008.1.2.1'
            ImplementationClassUID: '1.3.6.1.4.1.9590.100.1.3.100.7.1'
         ImplementationVersionName: 'MATLAB IPT 7.1'
      SourceApplicationEntityTitle: 'DCF'
              SpecificCharacterSet: 'ISO_IR 100'
                         ImageType: 'DERIVED\SECONDARY\OTHER\CSA MPR THICK...'
                       SOPClassUID: '1.2.840.10008.5.1.4.1.1.2'
                    SOPInstanceUID: '1.3.6.1.4.1.9590.100.1.2.515513049128...'
                         StudyDate: '20131007'
                        SeriesDate: '20131007'
                   AcquisitionDate: '20131007'
                       ContentDate: '20131007'
                         StudyTime: '184618.640000'
                        SeriesTime: '184046.156000'
                   AcquisitionTime: '184905.956783'
                       ContentTime: '184046.171000'
                   AccessionNumber: ''
                          Modality: 'CT'
                      Manufacturer: 'SIEMENS'
                   InstitutionName: ''
            ReferringPhysicianName: [1x1 struct]
             ManufacturerModelName: 'Sensation 64'
           ReferencedImageSequence: [1x1 struct]
                       PatientName: [1x1 struct]
                         PatientID: ''
                  PatientBirthDate: ''
                        PatientSex: ''
            PatientIdentityRemoved: 'YES'
            DeidentificationMethod: 'DICOMANON (rev R2010a) - PS 3.15-2008...'
                  BodyPartExamined: 'EXTREMITY'
                    SliceThickness: 2
                               KVP: 120
                   SoftwareVersion: 'syngo CT 2009E'
          DistanceSourceToDetector: 1040
           DistanceSourceToPatient: 570
                GantryDetectorTilt: 0
                       TableHeight: 179
                 RotationDirection: 'CW'
                        FilterType: '0'
                    GeneratorPower: 10
                         FocalSpot: 1.2000
             DateOfLastCalibration: '20131007'
             TimeOfLastCalibration: '061322.000000'
                 ConvolutionKernel: 'B60s'
                   PatientPosition: 'FFS'
                  StudyInstanceUID: '1.3.6.1.4.1.9590.100.1.2.328077616812...'
                 SeriesInstanceUID: '1.3.6.1.4.1.9590.100.1.2.237595359611...'
                           StudyID: ''
                      SeriesNumber: 505
                 AcquisitionNumber: 3
                    InstanceNumber: 1
              ImagePositionPatient: [3x1 double]
           ImageOrientationPatient: [6x1 double]
               FrameOfReferenceUID: '1.3.6.1.4.1.9590.100.1.2.396775851196...'
        PositionReferenceIndicator: ''
                   SamplesPerPixel: 1
         PhotometricInterpretation: 'MONOCHROME2'
                              Rows: 512
                           Columns: 512
                      PixelSpacing: [2x1 double]
                     BitsAllocated: 16
                        BitsStored: 16
                           HighBit: 15
               PixelRepresentation: 0
           SmallestImagePixelValue: 0
            LargestImagePixelValue: 2802
                      WindowCenter: 240
                       WindowWidth: 1200
                  RescaleIntercept: -1024
                      RescaleSlope: 1
      WindowCenterWidthExplanation: 'WINDOW1\WINDOW2'
             LossyImageCompression: '00'
               RequestingPhysician: [1x1 struct]
     RequestedProcedureDescription: 'CT LOWER EXTREMITY C-'
                     OverlayRows_0: 512
                  OverlayColumns_0: 512
         NumberOfFramesInOverlay_0: 1
              OverlayDescription_0: 'Siemens MedCom Object Graphics'
                     OverlayType_0: 'G'
                   OverlayOrigin_0: [2x1 int16]
                ImageFrameOrigin_0: 1
            OverlayBitsAllocated_0: 1
              OverlayBitPosition_0: 0
                     OverlayData_0: [512x512 logical]
info.FileSize:
      559084
info.Format:
DICOM
info.FormatVersion:
     3
info.Width:
    512
info.Height:
    512
info.BitDepth:
     16
info.ColorType:
grayscale
info.FileMetaInformationGroupLength:
         222
info.FileMetaInformationVersion:
    0
    1
info.SourceApplicationEntityTitle:
DCF
info.SpecificCharacterSet:
ISO_IR 100
info.StudyDate:
20131007
info.SeriesDate:
20131007
info.AcquisitionDate:
20131007
info.ContentDate:
20131007
info.AccessionNumber:
info.Modality:
CT
info.Manufacturer:
SIEMENS
info.InstitutionName:
info.ReferringPhysicianName:
    FamilyName: ''
     GivenName: ''
    MiddleName: ''
    NamePrefix: ''
    NameSuffix: ''
info.ReferringPhysicianName.FamilyName:
info.ReferringPhysicianName.GivenName:
info.ReferringPhysicianName.MiddleName:
info.ReferringPhysicianName.NamePrefix:
info.ReferringPhysicianName.NameSuffix:
info.ReferencedImageSequence:
    Item_1: [1x1 struct]
info.ReferencedImageSequence.Item_1:
       ReferencedSOPClassUID: '1.2.840.10008.5.1.4.1.1.2'
    ReferencedSOPInstanceUID: '1.3.12.2.1107.5.99.2.9567.30000013100710203...'
info.PatientName:
    FamilyName: ''
     GivenName: ''
    MiddleName: ''
    NamePrefix: ''
    NameSuffix: ''
info.PatientName.FamilyName:
info.PatientName.GivenName:
info.PatientName.MiddleName:
info.PatientName.NamePrefix:
info.PatientName.NameSuffix:
info.PatientID:
info.PatientBirthDate:
info.PatientSex:
info.PatientIdentityRemoved:
YES
info.BodyPartExamined:
EXTREMITY
info.SliceThickness:
     2
info.KVP:
   120
info.DistanceSourceToDetector:
        1040
info.DistanceSourceToPatient:
   570
info.GantryDetectorTilt:
     0
info.TableHeight:
   179
info.RotationDirection:
CW
info.FilterType:
0
info.GeneratorPower:
    10
info.FocalSpot:
    1.2000
info.DateOfLastCalibration:
20131007
info.ConvolutionKernel:
B60s
info.PatientPosition:
FFS
info.StudyID:
info.SeriesNumber:
   505
info.AcquisitionNumber:
     3
info.InstanceNumber:
     1
info.ImagePositionPatient:
   -2.3311
 -228.0754
  222.8133
info.ImageOrientationPatient:
    1.0000
   -0.0000
    0.0000
    0.0000
    0.0572
   -0.9984
info.PositionReferenceIndicator:
info.SamplesPerPixel:
      1
info.Rows:
    512
info.Columns:
    512
info.PixelSpacing:
    0.3379
    0.3379
info.BitsAllocated:
     16
info.BitsStored:
     16
info.HighBit:
     15
info.PixelRepresentation:
      0
info.SmallestImagePixelValue:
      0
info.LargestImagePixelValue:
   2802
info.WindowCenter:
   240
info.WindowWidth:
        1200
info.RescaleIntercept:
       -1024
info.RescaleSlope:
     1
info.LossyImageCompression:
00
info.RequestingPhysician:
    FamilyName: 'TARQUINIO'
     GivenName: 'THOM A.'
info.RequestingPhysician.FamilyName:
TARQUINIO
info.RequestingPhysician.GivenName:
THOM A.
info.OverlayRows_0:
    512
info.OverlayColumns_0:
    512
info.NumberOfFramesInOverlay_0:
     1
info.OverlayType_0:
G
info.OverlayOrigin_0:
      1
      1
info.ImageFrameOrigin_0:
      1
info.OverlayBitsAllocated_0:
      1
info.OverlayBitPosition_0:
      0

And if you're curious what a CT scan of a really bad looking ankle looks like, here's a downsized animated gif created from the full DICOM stack.

Comments

Give it a try and let us know what you think here or leave a comment for Thomas.


Get the MATLAB code

Published with MATLAB® R2015a

Note

Comments are closed.