general-discussion > Major Niak Write Minc flaw for single slices
Showing 1-4 of 4 posts
Display:
Results per page:
Feb 19, 2014  12:02 PM | Mathieu Boudreau
Major Niak Write Minc flaw for single slices
Hi,

I've had major problems with reading/writing single slice Minc images with Niak (both 0.6.3 and 0.7.1-ammo) on both Minc1 and Minc2 files for the past year, have found work arounds, but this week hit a hard roadblock.

Essentially, if reading a single slice image (with one of the dimension size 1) in Niak, and immediatly writing it out, the third dimensions (with size 1) gets completely omitted in the Minc file. I suspect this is because in Matlab when loading a single slice image with niak the matrix volume ends up being 2D, but I am not familiar enough with Niak to fix this. 
As a workaround to this problem, I would using Minc scripts read in the header information for the missing dimensions and modify the file to add it, but it is quite a pain and I feel as though niak_write_minc should know the difference between a 2D file (2 dimensions) and a single slice (3 dimensions with the 3rd dimension bein 1).

This worked fine with the older version of Minc1 installation which I had been using on my Macbook pro, as well as Minc 2.1.10 that we're using on our PCs at the BIC at the MNI.

HOWEVER, recently I've installed Minc 2.3.0 on my Macbook through the  minc-toolkit installation by Vlad at the BIC (minc-toolkit-1.0.01-20131211-Darwin-x86_64.dmg installation) and a major error occurs now when writting out single slices Minc files. This is the output:

EDU>> niak_write_minc(a,b);
104 info_default.voxel_size = [1 1 1];
micreate_group_variable: MINC package entry point
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: H5Adeprec.c line 214 in H5Aopen_name(): can't open attribute: 'length'
major: Attribute
minor: Can't open object
#001: H5A.c line 876 in H5A_open_by_name(): unable to load attribute info from object header
major: Attribute
minor: Unable to initialize object
#002: H5Oattribute.c line 537 in H5O_attr_open_by_name(): can't locate attribute: 'length'
major: Attribute
minor: Object not found
(from miopen): Should not happen!
minc_modify_header temp1_1.mnc -dinsert acquisition:echo_time=0.003640000000000 -dinsert acquisition:num_phase_enc_steps=64.000000000000000 -sinsert acquisition:scanning_sequence='fl3d1 ' -dinsert acquisition:percent_phase_fov=100.000000000000000 -sinsert acquisition:phase_enc_dir='COL ' -sinsert acquisition:acquisition_id='35' -sinsert acquisition:vartype='group________' -sinsert acquisition:protocol='anonym' -dinsert acquisition:slice_thickness=3.000000000000000 -dinsert acquisition:num_slices=1.000000000000000 -dinsert acquisition:echo_number=1.000000000000000 -dinsert acquisition:imaging_frequency=123254177.000000000000000 -sinsert acquisition:slice_order='interleaved' -dinsert acquisition:window_width=855.000000000000000 -sinsert acquisition:series_time='012210.937000 ' -sinsert acquisition:mr_acq_type='3D' -dinsert acquisition:num_dyn_scans=2.000000000000000 -dinsert acquisition:percent_sampling=100.000000000000000 -dinsert acquisition:SAR=0.112915967146970 -sinsert acquisition:series_description='anonym' -dinsert acquisition:echo_train_length=1.000000000000000 -dinsert acquisition:pixel_bandwidth=260.000000000000000 -dinsert acquisition:repetition_time=0.020000000000000 -dinsert acquisition:delay_in_TR=0.000000000000000 -sinsert acquisition:acquisition_time='011818.717500 ' -sinsert acquisition:image_time='012210.937000 ' -dinsert acquisition:num_averages=1.000000000000000 -sinsert acquisition:imaged_nucleus='1H' -sinsert acquisition:transmit_coil='Body' -dinsert acquisition:flip_angle=60.000000000000000 -sinsert acquisition:varid='MINC standard variable' -sinsert acquisition:image_type='ORIGINAL\\\\PRIMARY\\\\M\\\\ND\\\\NORM' -sinsert acquisition:start_time='20140124 174819.937000 ' -dinsert acquisition:window_center=425.000000000000000 -sinsert acquisition:receive_coil='32Ch_Headad\\' -sinsert acquisition:version='MINC Version 1.0': Signal 127
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: H5Adeprec.c line 214 in H5Aopen_name(): can't open attribute: 'length'
major: Attribute
minor: Can't open object
#001: H5A.c line 876 in H5A_open_by_name(): unable to load attribute info from object header
major: Attribute
minor: Unable to initialize object
#002: H5Oattribute.c line 537 in H5O_attr_open_by_name(): can't locate attribute: 'length'
major: Attribute
minor: Object not found
(from miopen): Should not happen!
minc_modify_header temp1_1.mnc -sinsert patient:varid='MINC standard variable' -sinsert patient:full_name='anonym' -sinsert patient:vartype='group________' -sinsert patient:age='anonym' -dinsert patient:weight=80.000000000000000 -sinsert patient:birthdate='anonym' -sinsert patient:position='HFS ' -sinsert patient:sex='other_' -sinsert patient:identification='14.01.24-17:47:38-STD-1.3.12.2.1107.5.2.32.35056' -sinsert patient:version='MINC Version 1.0': Signal 127
HDF5-DIAG: Error detected in HDF5 (1.8.11) thread 0:
#000: H5Adeprec.c line 214 in H5Aopen_name(): can't open attribute: 'length'
major: Attribute
minor: Can't open object
#001: H5A.c line 876 in H5A_open_by_name(): unable to load attribute info from object header
major: Attribute
minor: Unable to initialize object
#002: H5Oattribute.c line 537 in H5O_attr_open_by_name(): can't locate attribute: 'length'
major: Attribute
minor: Object not found
(from miopen): Should not happen!
minc_modify_header temp1_1.mnc -sinsert study:start_time='174819.937000 ' -sinsert study:procedure='anonym' -sinsert study:station_id='MRC35056' -sinsert study:study_id='20140124.174819' -sinsert study:software_version='syngo MR B17' -sinsert study:version='MINC Version 1.0' -sinsert study:vartype='group________' -sinsert study:institution='Mc Gill University' -sinsert study:modality='MRI__' -sinsert study:start_date='20140124' -sinsert study:device_model='TrioTim ' -dinsert study:field_value=3.000000000000000 -sinsert study:varid='MINC standard variable' -sinsert study:manufacturer='SIEMENS ' -sinsert study:operator='lm' -sinsert study:serial_no='35056 ': Signal 127

Also note the details of this installation of minc:

mathieuboudreau$ mincinfo -version
program: 2.3.00
libminc: 2.3.00
netcdf : 4.3.0 of Dec 6 2013 00:57:28 $
HDF5 : 1.8.11

Using Niak 0.7.1-ammo, the output file corrupts on (or near) line 317 during the loop of the dimension of size 1, but the output file is completely fine up until this point.

Can an easy fix for Niak be made so that an inputted file of say dimensions (128,128,1) be written out as such instead of (128,128) - this may solve this major error. Even though the image volume is a 2D matrix, the dimensions should be checked and handled through the header, no?

Thanks,

Mathieu
Feb 20, 2014  01:02 PM | Mathieu Boudreau
RE: Major Niak Write Minc flaw for single slices
Update: I made a quick fix for my need in niak_write_minc.m, it was simpler than I initially thought.

Note that I noticed that this problem only occurs if the dimension with dimension 1 is the third dimensions (e.g. this problem occurs for 128x128x1 but not 128x1x128 or 1x128x128 due to how Matlab handles matrices).

Modification 1

At the top of the section "Setting up "rawtominc" arguments", I added

if ndims(vol)==2 && size(hdr.info.dimension_order,2)==3
ndimsVol=3;
else
ndimsVol=ndims(vol);
end

And replaced ndims(vol) everywhere in the file with ndimsVol.

Modification 2

After this section of code:

if ~isempty(file_name)
str_raw = [str_raw '-input ' file_tmp ' ' file_name]; % read the temporary raw file and write it in minc format
else
error('niak:write: hdr.file_name is empty !')
end

I added:

if ndims(vol)==2 && size(hdr.info.dimension_order,2)==3
sizeVol = [size(vol) 1];
else
sizeVol = size(vol);
end


And replaced size(vol) everywhere in the file with sizeVol.

These two fixes seem to have resolved the bug for me, hopefully this can be improved in future versions of Niak, and that this thread helps any other people who have this problem.

Cheers,

Mathieu
Feb 21, 2014  11:02 AM | Pierre Bellec
RE: Major Niak Write Minc flaw for single slices
Dear Mathieu,

Thanks a lot for the bug report and suggested fix. I'll try to apply the suggested changes for the next release. Note that I have been working for a while on a pure matlab reader/writer that does not depend on minc tools:
http://code.google.com/p/mominc/

It's not currently functional, but it is on my list to do in the coming months to finally wrap up this project. The NIAK reader/writer really are for 3D MRI and fMRI and I don't test them as general-purpose minc reader/writer. The mominc project on another hand is targeted to support any kind of minc file.

Best,

Pierre
Feb 21, 2014  12:02 PM | Mathieu Boudreau
RE: Major Niak Write Minc flaw for single slices
A pure matlab reader/writer that does not depend on minc tools would be fantastic! Thanks for sharing the project link, I'll keep an eye on it.

Cheers,

Mathieu