⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dicom_vr.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function vr = dicom_vr(vrtype)
% dicom_vr  - resolve VR values
%
% FORMAT:       vr = dicom_vr(vrtype)
%   - OR -      vrlist = dicom_vr
%
% Input fields:
%
%       vrtype      if given, must be a valid 2-char VR
%
% Output fields:
%
%       vr          1x1 struct with fields
%         .tag      1x2 char, VR tag name
%         .chars    1xN list of valid chars
%         .deblank  false|true (remove leading/trailing spaces/zero bytes)
%         .length   1x2 double describing min/max length
%         .datatype one of 'char', 'int16', 'single', 'uint32', etc.
%
%       vrlist      1x1 struct with VR names as fields and substructs

% Version:  v0.5c
% Build:    6120415
% Date:     Dec-04 2006, 3:15 PM CET
% Author:   Jochen Weber, Brain Innovation, B.V., Maastricht, NL
% URL/Info: http://wiki.brainvoyager.com/BVQXtools

% persistent variable
persistent dcm_vr dcm_vr_back;
if isempty(dcm_vr)

    % prepare chars values
    notapplic = '';
    maxchars  = char( 0:255 );
    escchars  = char([27:32:91, 93:255]);
    allchars  = char( 32:126 );
    extchars  = char([32:91, 93:255]);
    defchars  = char([32:91, 93:126]);
    decchars  = char([32, 43, 45:46, 48:57, 69, 101]);
    dtchars   = char([32, 43, 45:46, 48:57]);
    intchars  = char([32, 43, 45, 48:57]);
    codechars = char([32, 48:57, 65:90, 95]);
    datechars = char([46, 48:57]);
    maxlen    = 2^31 - 1;

    % build back
    dcm_vr_back = cell2struct({ ...
        'AE', defchars,               true, [0, 16], 'char'; ...
        'AS', '0123456789DMWYdmwy',  false, [4,  4], 'char'; ...
        'AT', notapplic,             false, [4,  4], 'uint32'; ...
        'CS', codechars,              true, [0, 16], 'char'; ...
        'DA', datechars,             false, [8, 10], 'char'; ...
        'DL', notapplic,             false, [0,  0], 'delim'; ...
        'DS', decchars,               true, [0, 16], 'char'; ...
        'DT', dtchars,                true, [0, 26], 'char'; ...
        'FD', notapplic,             false, [8,  8], 'double'; ...
        'FL', notapplic,             false, [4,  4], 'single'; ...
        'IS', intchars,               true, [0, 12], 'char'; ...
        'LO', allchars,               true, [0, 64], 'char'; ...
        'LT', maxchars,               true, [0, 10240], 'char'; ...
        'OB', notapplic,             false, [0, maxlen], 'uint8'; ...
        'OF', notapplic,             false, [0, maxlen], 'single'; ...
        'OW', notapplic,             false, [0, maxlen], 'uint16'; ...
        'OX', notapplic,             false, [0, maxlen], 'uint8'; ...
        'PN', extchars,               true, [0, 324], 'char'; ...
        'SH', escchars,               true, [0, 16], 'char'; ...
        'SL', notapplic,             false, [4, 4], 'int32'; ...
        'SQ', notapplic,             false, [0, maxlen], 'sequence'; ...
        'SS', notapplic,             false, [0, 2], 'int16'; ...
        'ST', maxchars,               true, [0, 1024], 'char'; ...
        'TM', datechars,              true, [0, 16], 'char'; ...
        'UI', datechars,              true, [0, 64], 'char'; ...
        'UL', notapplic,             false, [4, 4], 'uint32'; ...
        'UN', notapplic,             false, [0, maxlen], 'uint8'; ...
        'US', notapplic,             false, [2, 2], 'uint16'; ...
        'UT', notapplic,             false, [0, maxlen], 'uint8'}, ...
        {'tag', 'chars', 'deblank', 'length', 'datatype'}, 2)';

    % fill structure
    dcm_vr = struct;
    for tc = 1:length(dcm_vr_back)
        dcm_vr.(dcm_vr_back(tc).tag) = dcm_vr_back(tc);
    end
end

% what to return
if nargin < 1
    vr = dcm_vr;
elseif ischar(vrtype) && ...
   ~isempty(vrtype) && ...
    isfield(dcm_vr, upper(vrtype(:)'))
    vr = dcm_vr.(upper(vrtype(:)'));
else
    error( ...
        'BVQXtools:BadArgument', ...
        'Invalid DICOM VR argument specified.' ...
    );
end

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -