How to read .hdr files in Matlab?

14 views (last 30 days)
Jab
Jab on 20 Sep 2015
Commented: Walter Roberson on 20 Sep 2015
All the volumes(image 3D) location are stored in a variable called Fulfilename as
Fulfilename 178*1 cell
'D:\Oasis\Database\disc1\OAS1_0001_MR1\PROCESSED\MPRAGE\T88_111\OAS1_0001_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr '
'D:\Oasis\Database\disc1\OAS1_0003_MR1\PROCESSED\MPRAGE\T88_111\OAS1_0003_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr '
'D:\Oasis\Database\disc1\OAS1_0010_MR1\PROCESSED\MPRAGE\T88_111\OAS1_0010_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr '
'D:\Oasis\Database\disc1\OAS1_0013_MR1\PROCESSED\MPRAGE\T88_111\OAS1_0013_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr ' etc
I need to read all the images in Matlab. I tired with some code. It doesnt help me. Any help is appreciated. My code is the following:-
load Fulfilename;
for p=1:178
V= hdr_read_volume('Fulfilename{p}');
end

Accepted Answer

Walter Roberson
Walter Roberson on 20 Sep 2015
load Fulfilename;
for p = 1 : length(Fulfilename)
V{p} = hdr_read_volume(Fulfilename{p});
end
  2 Comments
Jab
Jab on 20 Sep 2015
Edited: Walter Roberson on 20 Sep 2015
Thanks for the help Walter. I am getting the error like the following
Error using analyze75open (line 17)
Invalid format ".hdr ". Valid formats include "hdr" and "img".
Error in isanalyze75 (line 26)
fid = analyze75open(filename, 'hdr', 'r');
Error in analyze75info>parseInputs (line 440)
if ~isanalyze75(filename)
Error in analyze75info (line 138)
[args, userSupplied] = parseInputs(filename, varargin{:});
Error in hdr_read_header (line 15)
info=analyze75info(filename);
Error in hdr_read_volume (line 13)
if(~isstruct(info)), info=hdr_read_header(info); end
Error in main (line 68)
V{p} = hdr_read_volume(Fullfilename{p});
Could you please clarify this?
Walter Roberson
Walter Roberson on 20 Sep 2015
Your filename list has trailing blanks on each of the strings. Code that accounts for that is
load Fulfilename;
Fulfilename = strtrim(Fulfilename);
for p = 1 : length(Fulfilename)
V{p} = hdr_read_volume(Fulfilename{p});
end

Sign in to comment.

More Answers (1)

Image Analyst
Image Analyst on 20 Sep 2015
Fulfilename{p} is already a string. So then you're surrounding a string with quotes, but this actually does not evaluate Fulfilename{p} but just puts Fulfilename{p} into the string as a literal. So 'Fulfilename{p}' will be laterally that -- it will not be 'D:\Oasis\Database\disc1\OAS1_0001_MR1\PROCESSED\MPRAGE\T88_111\OAS1_0001_MR1_mpr_n4_anon_111_t88_masked_gfc.hdr'
There you will find out how to use braces and parentheses and quotes. You'd learn that you're supposed to do
V = hdr_read_volume(Fulfilename{p});
because Fulfilename{p} is already a string and you should not put it into quotes.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!