This repository was archived by the owner on May 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcheckFileFormat.m
More file actions
66 lines (54 loc) · 1.9 KB
/
Copy pathcheckFileFormat.m
File metadata and controls
66 lines (54 loc) · 1.9 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
%-------------------------------------------------------------------------%
% This is a function which checks the format of the medical images in a given
% folder.
% Usage:
% fileFormat = checkFileFormat(filePath)
% Output: "fileFormat" is a string, can either be "DICOM", "NIFTI" or "Analyze"
% Input: "filePath" is the folder path, where the images are stored.
% Example:
% fileFormat = checkFileFormat('/Users/work/Documents/Git sync/CT to
% MR/Scripts/Helper functions');
% or
% filePath='/Users/work/Documents/Git sync/CT to MR/Scripts/Helper
% functions';
% fileFormat = checkFileFormat(filePath);
%
% Author - Lalith Kumar Shiyam Sundar, M.Sc.
% Date - 30-12-2017
% Mail - lalith.shiyamsundar@meduniwien.ac.at
%
%-------------------------------------------------------------------------%
% Program Start
%-------------------------------------------------------------------------%
function fileFormat = checkFileFormat(pathOfTheImages)
%% Input checks
if isempty(pathOfTheImages)
error('Input parameter is empty, please specify the file path!')
end
if ~ischar(pathOfTheImages)
error('Input parameter is probably not a filepath!');
end
%% Go to the file path
cd(pathOfTheImages);
checkIfAnalyze=dir('*.img');
checkIfNifti=dir('*.nii');
if isempty(checkIfAnalyze) && isempty(checkIfNifti)
fNames=dir;
fNames=fNames(arrayfun(@(x) x.name(1), fNames) ~= '.'); % read volunteer folders
CheckIfDicom=dicominfo(fNames(1).name); % if dicominfo can read the file, probably its dicom, lazy logic.
end
if ~isempty(checkIfAnalyze)
fileFormat='Analyze';
disp('Analyze files found...')
else
if ~isempty(checkIfNifti)
fileFormat='Nifti';
disp('Nifti files found...')
else
if ~isempty(CheckIfDicom)
fileFormat='Dicom';
disp('Dicom files found...')
end
end
end
end