general-discussion > mincresample or niak_read_minc problem ?
Showing 1-2 of 2 posts
Oct 11, 2012 02:10 PM | Alexis Machado
mincresample or niak_read_minc problem ?
Hi
After segmentation of my T1 MRI ( INSECT Louis Collins lab) into 12 tissue types, I got a 001_labels.mnc file containing values from 0 to 12 ( integer values) coded as unsigned byte
>>mincinfo 001_labels.mnc
file: 001_labels.mnc
image: unsigned byte 0 to 12
image dimensions: xspace zspace yspace
dimension name length step start
-------------- ------ ---- -----
xspace 192 1 -91.7514
zspace 256 1 -127
yspace 256 1 -100.539
Then i used mincresample -like N3_S001.mnc 001_labels.mnc 001_labels_r.mnc to get the same step than my anatomy N3_S001.mnc >> !mincinfo N3_S001.mnc
>>mincinfo N3_S001.mnc
file: N3_S001.mnc
image: unsigned short 0 to 4095
image dimensions: xspace zspace yspace
dimension name length step start
-------------- ------ ---- -----
xspace 192 1 -91.7514
zspace 256 -1 128
yspace 256 -1 154.461
>>mincinfo 001_labels_r.mnc
file: 001_labels_r.mnc
image: unsigned byte 0 to 12
image dimensions: xspace zspace yspace
dimension name length step start
-------------- ------ ---- -----
xspace 192 1 -91.7514
zspace 256 -1 128
yspace 256 -1 154.461
I checked using anatomist that values are still integers values between 0 and 12
PROBLEMS:
I tried to extract the file 001_labels_r.mnc into matlab using
>> [hdr,vol] = niak_read_minc(001_labels_r.mnc ); % version 6.4.1
1))
Unfortunately the values inside the vol variable were not integer values anymore ( e.g i get 7.33,...), so i started to look into the code for solving the issue.
More surprising, i am not able to reproduce the problem when i extract the original 001_labels.mnc ( In this case all is fine, output values are integers values ( double type) )
2))
I tried to use the precision variable: [hdr,vol] = niak_read_minc(001_labels_r.mnc,'unsigned');
but i got error with fread because 'unsigned' is not recognised by fread
I got the solution without calling niak_read_minc.m
hdr = niak_read_hdr_minc(filename);
[flag,str_info] = system(cat(2,'minctoraw -','unsigned',' -normalize ',filename,' > ','./tmp/001_labels_r.dat'));
hf = fopen('./tmp/001_labels_r.dat','r');
vol = fread(hf,prod(hdr.info.dimensions));
vol = reshape(vol,hdr.info.dimensions);
vol is now a double type matrix containing values between 0 and 12 ( integer values)
The problem in the function niak_read_minc.m is that the precision variable is the same for the call to minctoraw and fread
which can lead to bugs it could be unrecognised in many case by fread. am I right ??
am
3)) In all the case i cannot figure out why after using mincresample ( i used nearest neighbour opt but same thing) this kind of behavior happens.
If you have any idea ?
thank you very much
Best regards
Alexis
After segmentation of my T1 MRI ( INSECT Louis Collins lab) into 12 tissue types, I got a 001_labels.mnc file containing values from 0 to 12 ( integer values) coded as unsigned byte
>>mincinfo 001_labels.mnc
file: 001_labels.mnc
image: unsigned byte 0 to 12
image dimensions: xspace zspace yspace
dimension name length step start
-------------- ------ ---- -----
xspace 192 1 -91.7514
zspace 256 1 -127
yspace 256 1 -100.539
Then i used mincresample -like N3_S001.mnc 001_labels.mnc 001_labels_r.mnc to get the same step than my anatomy N3_S001.mnc >> !mincinfo N3_S001.mnc
>>mincinfo N3_S001.mnc
file: N3_S001.mnc
image: unsigned short 0 to 4095
image dimensions: xspace zspace yspace
dimension name length step start
-------------- ------ ---- -----
xspace 192 1 -91.7514
zspace 256 -1 128
yspace 256 -1 154.461
>>mincinfo 001_labels_r.mnc
file: 001_labels_r.mnc
image: unsigned byte 0 to 12
image dimensions: xspace zspace yspace
dimension name length step start
-------------- ------ ---- -----
xspace 192 1 -91.7514
zspace 256 -1 128
yspace 256 -1 154.461
I checked using anatomist that values are still integers values between 0 and 12
PROBLEMS:
I tried to extract the file 001_labels_r.mnc into matlab using
>> [hdr,vol] = niak_read_minc(001_labels_r.mnc ); % version 6.4.1
1))
Unfortunately the values inside the vol variable were not integer values anymore ( e.g i get 7.33,...), so i started to look into the code for solving the issue.
More surprising, i am not able to reproduce the problem when i extract the original 001_labels.mnc ( In this case all is fine, output values are integers values ( double type) )
2))
I tried to use the precision variable: [hdr,vol] = niak_read_minc(001_labels_r.mnc,'unsigned');
but i got error with fread because 'unsigned' is not recognised by fread
I got the solution without calling niak_read_minc.m
hdr = niak_read_hdr_minc(filename);
[flag,str_info] = system(cat(2,'minctoraw -','unsigned',' -normalize ',filename,' > ','./tmp/001_labels_r.dat'));
hf = fopen('./tmp/001_labels_r.dat','r');
vol = fread(hf,prod(hdr.info.dimensions));
vol = reshape(vol,hdr.info.dimensions);
vol is now a double type matrix containing values between 0 and 12 ( integer values)
The problem in the function niak_read_minc.m is that the precision variable is the same for the call to minctoraw and fread
which can lead to bugs it could be unrecognised in many case by fread. am I right ??
am
3)) In all the case i cannot figure out why after using mincresample ( i used nearest neighbour opt but same thing) this kind of behavior happens.
If you have any idea ?
thank you very much
Best regards
Alexis
Oct 11, 2012 03:10 PM | Alexis Machado
RE: mincresample or niak_read_minc problem ?
Ok I got the final solution
i should have resampled my data with more options
mincresample -keep_real_range -unsigned -clobber -like N3_S001.mnc 001_labels.mnc 001_labels_r.mnc
In this case niak_read_minc works as expected :). I am sorry if i created confusion among users !
I have still one question:
It is possible we get a error if we use the precision input variable ?
e.g: [hdr,vol] = niak_read_minc(001_labels_r.mnc,'unsigned') because 'unsigned' is not recognised by fread
i should have resampled my data with more options
mincresample -keep_real_range -unsigned -clobber -like N3_S001.mnc 001_labels.mnc 001_labels_r.mnc
In this case niak_read_minc works as expected :). I am sorry if i created confusion among users !
I have still one question:
It is possible we get a error if we use the precision input variable ?
e.g: [hdr,vol] = niak_read_minc(001_labels_r.mnc,'unsigned') because 'unsigned' is not recognised by fread
