How to read .hdr files in Matlab?
15 views (last 30 days)
Show older comments
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
0 Comments
Accepted Answer
Walter Roberson
on 20 Sep 2015
load Fulfilename;
for p = 1 : length(Fulfilename)
V{p} = hdr_read_volume(Fulfilename{p});
end
2 Comments
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
More Answers (1)
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.
0 Comments
See Also
Categories
Find more on Import, Export, and Conversion in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!