-
Notifications
You must be signed in to change notification settings - Fork 1
/
DMisdicom.m
34 lines (32 loc) · 934 Bytes
/
DMisdicom.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function isDicom = DMisdicom(fileName)
% DMisdicom. Tests whether a file is in DICOM format
%
% Usage:
% isDicom = DMisdicom(fileName)
%
% fileName: path and filename of the file to test
%
% Returns:
% true if the file appears to be a Dicom file
%
%
%
% Licence
% -------
% Part of DicoMat. https://github.com/tomdoel/dicomat
% Author: Tom Doel, 2013. www.tomdoel.com
% Distributed under the BSD 3-Clause license. Please see the file LICENSE for details.
%
fileId = fopen(fileName);
if fileId <= 0
error('DMisdicom:OpenFileFailed', ['Unable to open file ' fileName]);
end
preamble = fread(fileId, 132, 'uint8');
if numel(preamble) < 132
isDicom = false;
return;
end
dicomChars = char(preamble(129:132)');
isDicom = strcmp(dicomChars, 'DICM');
fclose(fileId);
end