Home > vbmeg > demo > test_scripts > sbi > read_dicom.m

read_dicom

PURPOSE ^

SYNOPSIS ^

function d = read_dicom(filename)

DESCRIPTION ^



 rhayashi added encoding

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function d = read_dicom(filename)
0002 %
0003 %
0004 %
0005 % rhayashi added encoding
0006 %
0007 % Copyright (C) 2011, ATR All Rights Reserved.
0008 % License : New BSD License(see VBMEG_LICENSE.txt)
0009 fid = -1;
0010 if vb_matlab_version('>=', '7.2')
0011     fid = fopen(filename, 'r', 'ieee-le', 'US-ASCII');
0012 else
0013     fid = fopen(filename, 'r', 'ieee-le');
0014 end
0015 
0016 
0017 d = [];
0018 
0019 ix = create_index_dicom(fid);
0020 
0021 % STUDY DATE
0022 t = fread_dicom(fid, ix, '0008', '0020', 1, 'char');
0023 d = setfield(d, 'study_date', char(t'));
0024 
0025 % STUDY TIME
0026 t = fread_dicom(fid, ix, '0008', '0030', 1, 'char');
0027 d = setfield(d, 'study_time', char(t'));
0028 
0029 % PATIENTS NAME
0030 t = fread_dicom(fid, ix, '0010', '0010', 1, 'char');
0031 d = setfield(d, 'patients_name', char(t'));
0032 
0033 % PATIENT ID
0034 t = fread_dicom(fid, ix, '0010', '0020', 1, 'char');
0035 d = setfield(d, 'patient_id', char(t'));
0036 
0037 % PATIENT COMMENT
0038 t = fread_dicom(fid, ix, '0010', '4000', 1, 'char');
0039 d = setfield(d, 'patient_comments', char(t'));
0040 
0041 % SCANNING SEQUENCE
0042 t = fread_dicom(fid, ix, '0018', '0020', 1, 'char');
0043 d = setfield(d, 'scanning_sequence', char(t'));
0044 
0045 % SLICE THICKNESS
0046 t = fread_dicom(fid, ix, '0018', '0050', 1, 'char');
0047 d = setfield(d, 'slice_thickness', sscanf(char(t), '%f'));
0048 
0049 % REPETITION TIME
0050 t = fread_dicom(fid, ix, '0018', '0080', 1, 'char');
0051 d = setfield(d, 'repetition_time', sscanf(char(t), '%f'));
0052 
0053 % ECHO TIME
0054 t = fread_dicom(fid, ix, '0018', '0081', 1, 'char');
0055 d = setfield(d, 'echo_time', sscanf(char(t), '%f'));
0056 
0057 % SPACING BETWEEN SLICES
0058 t = fread_dicom(fid, ix, '0018', '0088', 1, 'char');
0059 x=t;
0060 d = setfield(d, 'spacing_between_slices', sscanf(char(t), '%f'));
0061 
0062 % RECIVING COIL
0063 t = fread_dicom(fid, ix, '0018', '1250', 1, 'char');
0064 d = setfield(d, 'recieving_coil', char(t'));
0065 
0066 % STUDY ID
0067 t = fread_dicom(fid, ix, '0020', '0010', 1, 'char');
0068 d = setfield(d, 'study_id', char(t'));
0069 
0070 % SERIES NUMBER
0071 t = fread_dicom(fid, ix, '0020', '0011', 1, 'char');
0072 d = setfield(d, 'series_number', sscanf(char(t), '%d'));
0073 
0074 % IMAGE NUMBER
0075 t = fread_dicom(fid, ix, '0020', '0013', 1, 'char');
0076 d = setfield(d, 'image_number', sscanf(char(t), '%d'));
0077 
0078 % IMAGE POSITION
0079 t = fread_dicom(fid, ix, '0020', '0032', 1, 'char');
0080 d = setfield(d, 'image_position', sscanf(char(t), '%f\\%f\\%f'));
0081 
0082 % IMAGE ORIENTATION
0083 t = fread_dicom(fid, ix, '0020', '0037', 1, 'char');
0084 d = setfield(d, 'image_orientation', sscanf(char(t),...
0085              '%f\\%f\\%f\\%f\\%f\\%f'));
0086 
0087 % SAMPLE PER PIXEL
0088 t = fread_dicom(fid, ix, '0028', '0002', 2, 'uint16');
0089 d = setfield(d, 'sample_per_pixel', t);
0090 
0091 % PHOTOMETRIC INTERPRETATION
0092 t = fread_dicom(fid, ix, '0028', '0004', 1, 'char');
0093 d = setfield(d, 'photometric_interpretation', char(t'));
0094 
0095 % ROWS
0096 t = fread_dicom(fid, ix, '0028', '0010', 2, 'uint16');
0097 d = setfield(d, 'rows', uint16(t));
0098 
0099 % COLUMNS
0100 t = fread_dicom(fid, ix, '0028', '0011', 2, 'uint16');
0101 d = setfield(d, 'columns', uint16(t));
0102 
0103 % PIXEL SPACEING
0104 t = fread_dicom(fid, ix, '0028', '0030', 1, 'char');
0105 d = setfield(d, 'pixel_spacing', sscanf(char(t), '%f\\%f'));
0106 
0107 % BITS ALLOCATED
0108 t = fread_dicom(fid, ix, '0028', '0100', 2, 'uint16');
0109 d = setfield(d, 'bits_allocated', t);
0110 
0111 % BITS STORED
0112 t = fread_dicom(fid, ix, '0028', '0101', 2, 'uint16');
0113 d = setfield(d, 'bits_stored', t);
0114 
0115 % HIGH BIT
0116 t = fread_dicom(fid, ix, '0028', '0102', 2, 'uint16');
0117 d = setfield(d, 'high_bit', t);
0118 
0119 % PIXEL REPRESENTATION
0120 t = fread_dicom(fid, ix, '0028', '0103', 2, 'uint16');
0121 d = setfield(d, 'pixel_representation', t);
0122 
0123 % WINDOW CENTER
0124 t = fread_dicom(fid, ix, '0028', '1050', 1, 'char');
0125 d = setfield(d, 'window_center', sscanf(char(t), '%f'));
0126 
0127 % WINDOW WIDTH
0128 t = fread_dicom(fid, ix, '0028', '1051', 1, 'char');
0129 d = setfield(d, 'window_width', sscanf(char(t), '%f'));
0130 
0131 % RESCALE INTERCEPT
0132 t = fread_dicom(fid, ix, '0028', '1052', 1, 'char');
0133 d = setfield(d, 'rescale_intercept', sscanf(char(t), '%f'));
0134 
0135 % RESCALE SLOPE
0136 t = fread_dicom(fid, ix, '0028', '1053', 1, 'char');
0137 d = setfield(d, 'rescale_slope', sscanf(char(t), '%f'));
0138 
0139 % PIXEL DATA
0140 t = fread_dicom(fid, ix, '7FE0', '0010', 2, 'uint16');
0141 d = setfield(d, 'pixel_data', reshape(t, d.rows, d.columns)');
0142 
0143 
0144 fclose(fid);
0145 
0146 
0147 %---
0148 function dt = fread_dicom(fid, ix, grp, elm, sz, tp)
0149 [pos, len] = index_dicom(ix, grp, elm);
0150 fseek(fid, pos, 'bof');
0151 dt = fread(fid, len/sz, tp);

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005