[Nirfast] NIRFASTSLicer_2.0_major_bugs_report+solutions

Stanislaw Wojtkiewicz s.wojtkiewicz at cs.bham.ac.uk
Mon May 14 18:16:00 EDT 2018


Hi All

 

I want to report bugs in NIRFASTSlicer_v.2.0 mesh generation module.

I also deliver solutions (attached).

 

Major problems: 

-        translation of coordinates from patient space to x-y-z space ->
crushes the module

-        unfinished implementation of fiducial coordinates processing (since
NIRFASTSlicer v1.0) -> fiducials useless

 

The 'Create Mesh' crush and fiducials problems can be reproduced using my
head model (generated from MRI with SPM and saved with NIRFASTSlicer2.0).

(Please mail me for the segmentation '*.nrrd' file. It's only 632KB.
However, Nirfast mailing list email size limit is 300KB.)

The command:

cd('C:/Program Files/NIRFASTSlicer
2.0.0/lib/NIRFASTSlicer-2.0/matlab-modules');

Image2Mesh(cli_argsread({'--nirfastDir','D:/PROGRAMS/nirfast8/toolbox','--la
belmap','C:/Users/wojtkies/AppData/Local/Temp/NIRFASTSlicer/EICE_vtkMRMLLabe
lMapVolumeNodeC.nrrd','--fiducials','34.7404,71.4787,25.567','--fiducials','
0.909979,77.0329,25.567','--fiducials','-29.8908,69.9639,25.567','--meshdir'
,'D:/DOCUMENTS/GRANTY/BITMAP/Warsaw_meeting_05.2018/TEST/mesh_test','--meshn
ame','nirfast_mesh','--meshtype','Standard','--cell_size','3.5','--cellradiu
sedge','3','--facet_size','3.5','--facetangle','25','--facetdistance','3'}))
;

 

(Win 10, Matlab R2016a, NIRFASTSLicer2.0 - pure as download, NIRFAST9.0 -
pure as download)

 

DETAILS of the two major problems + other minor/major bugs repairs:

 

#1

Coordinates translation

The current implementation (Image2Mesh.m) assumes only one possible
orientation of object in the patient space. All images are processed as
oriented 'LPS' . The MRI structure I use was saved in
'right-anterior-superior' ('RAS') orientation.

My spacedir matrix (rotation/scale matrix from patient to xyz space) is as
follows (I have 1mm voxels spacing, thus ones in the matrix):

     0     0     1

    -1     0     0

     0     1     0

However, the code assumes nonzero diagonal values (as it is true for 'LPS'
patient space orientations). Thus, the following lines:

% param.TransformMatrix(1,1) = param.TransformMatrix(1,1) /
abs(spacedir(1,1));

% param.TransformMatrix(2,2) = param.TransformMatrix(2,2) /
abs(spacedir(2,2));

% param.TransformMatrix(3,3) = param.TransformMatrix(3,3) /
abs(spacedir(3,3));

produce NaNs at the diagonal of the transformation matrix. We divide 0 by 0.
This leads to a big crush.

 

I think, that the best solution is to use affine transform
(param.TransformMatrix = img.ijkToLpsTransform;). This affine matrix is
called 'ijkToLpsTransform' but Slicer puts there correct values no matter
what is the patient space orientation (i.e. it does not have to be LPS). 

The rotation and translation of the model are handled separately despite a
ready to use affine matrix. Is there any reason to not trust this matrix? I
checked it for different DICOMS (a neck and heads carried out by different
hospitals) and this affine transform matrix was always good (for different
patient orientations!). I am not sure if I fully understand the terminology
LPS etc. and what exactly is passed from Slicer (I just tried to reverse
engineer this problem). However, it looks like the proposed solution works.

 

Briefly, my changes to the Image2Mesh.m file:

-        the affine transform instead of rotation and translation

The rotation was carried out inside 'Image2Mesh.m' file, the translation was
carried out inside 'RunCGALMeshGenerator.m' file. The affine transform does
all at once. I have moved the affine operation into 'Image2Mesh.m' as this
file is closely related to the Slicer which generates the affine
transformation matrix. And it might be more clear to keep the transformation
as close as possible to the transformation matrix.

-        with the affine transform, there is no need of the hard/hand-coded
repairs of the rotation matrix (is this to match the fiducials coordinates?
I do not understand this rotations around 0X and 0Y axes.):

% param.TransformMatrix(1,1) = -1 * param.TransformMatrix(1,1);

% param.TransformMatrix(2,2) = -1 * param.TransformMatrix(2,2);

-        removed redundancies

-        code polishing, etc.

 

The fix requires changes in two files: RunCGALMeshGenerator.m (NIRFAST
package) and Image2Mesh.m (Slicer package). Fixed files attached.

 

#2

Unfinished fiducials business

Fiducials coordinates are translated internally by the Slicer (by the same
vector as in the affine transform in #1). However, they are not rotated.

Fiducials look like they are always in the same patient space, no matter
what is the data patient orientation. Thus, to convert the fiducials to the
x-y-z coordinates a following rotation matrix should be used:

    -1     0     0

     0    -1     0

     0     0     1

 

I have added the following to the 'Image2Mesh.m' file:

sdcoords = ([-1 0 0;0 -1 0; 0 0 1]*sdcoords')';

This and affine transform of the model brings the model and fiducials to the
same space.

 

BTW: The fiducials coordinates passed to the 'Image2Mesh.m' function and
saved as a *.csv file are different..

 

#3

Reading fiducials fails if there is only one fiducial.

sdcoords = cell2mat(fiducials)';

For one fiducial, the 'fiducials' is not a cell and the command fails
returning error. 

 

Problem solved in the attached file.

 

#4

Can you repair/swap  RunCGALMeshGenerator.m and Image2Mesh.m files in the
packages to download?

I am going to run a training session 'from MRI to FEM model' for PhD
students soon (in 2 weeks). The very first thing I will have to do is to ask
everybody to repair tools by replacing files here and there (or use my
Matlab meshing implementation directly on SPM files, which I developed to
test the errors).

I have to work on DICOM files that confuses NIRFASTSlicer. So, I have no
choice but distribute NIRFASTSlicer with my repaired files.

 

#5

'Image2Mesh (Matlab)' module? A testing leftover? It has inactive
settings/parameters. These parameters are loaded from the 'Create Mesh'
module. There is no easy way to guess that. I propose to delete this
redundant module. Or repair the inactive options and leave it as backward
compatibility for meshing 'LabelMaps' not 'Segmentations' as in the new
'Create Mesh' module. Or add option of meshing a 'LabelMap' to the 'Create
Mesh' module?

 

 

Regards

Stanislaw Wojtkiewicz, PhD

 

---

School of Computer Science

University of Birmingham

B15 2TT

 

 



---
This email has been checked for viruses by Avast antivirus software.
https://www.avast.com/antivirus
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://public.kitware.com/pipermail/nirfast/attachments/20180514/824ab84a/attachment-0001.html>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: RunCGALMeshGenerator.m
URL: <https://public.kitware.com/pipermail/nirfast/attachments/20180514/824ab84a/attachment-0002.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: Image2Mesh.m
URL: <https://public.kitware.com/pipermail/nirfast/attachments/20180514/824ab84a/attachment-0003.ksh>


More information about the Nirfast mailing list