From b7c6ce618195cfb000c9a630901d1addf6907d11 Mon Sep 17 00:00:00 2001 From: Andreas <27815260+adhusch@users.noreply.github.com> Date: Thu, 31 Jan 2019 14:24:19 +0100 Subject: [PATCH 1/4] Matlab 2019b does not allow folders named "resources" to be on the path Warning: Adding folders named 'resources' to the path is not supported: --- {resources => res}/Deepbrain_7T.label | 0 {resources => res}/Deepbrain_7T_T1.label | 0 {resources => res}/Default_Region_Labels.label | 0 {resources => res}/electrodeGeometries.mat | Bin 4 files changed, 0 insertions(+), 0 deletions(-) rename {resources => res}/Deepbrain_7T.label (100%) rename {resources => res}/Deepbrain_7T_T1.label (100%) rename {resources => res}/Default_Region_Labels.label (100%) rename {resources => res}/electrodeGeometries.mat (100%) diff --git a/resources/Deepbrain_7T.label b/res/Deepbrain_7T.label similarity index 100% rename from resources/Deepbrain_7T.label rename to res/Deepbrain_7T.label diff --git a/resources/Deepbrain_7T_T1.label b/res/Deepbrain_7T_T1.label similarity index 100% rename from resources/Deepbrain_7T_T1.label rename to res/Deepbrain_7T_T1.label diff --git a/resources/Default_Region_Labels.label b/res/Default_Region_Labels.label similarity index 100% rename from resources/Default_Region_Labels.label rename to res/Default_Region_Labels.label diff --git a/resources/electrodeGeometries.mat b/res/electrodeGeometries.mat similarity index 100% rename from resources/electrodeGeometries.mat rename to res/electrodeGeometries.mat From 681cfa55c14f69716ecd8a503cb8ee9a0f7f3eaf Mon Sep 17 00:00:00 2001 From: Andreas <27815260+adhusch@users.noreply.github.com> Date: Thu, 31 Jan 2019 14:41:27 +0100 Subject: [PATCH 2/4] applyANTSTransformToPoints now can read path to ants from enviroment By evaluating exported environment variable ANTSPATH for example exported by DBSAR pipeline --- lib/ANTSTransforms/applyANTSTransformToPoints.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/ANTSTransforms/applyANTSTransformToPoints.m b/lib/ANTSTransforms/applyANTSTransformToPoints.m index 327f372..61d0c48 100644 --- a/lib/ANTSTransforms/applyANTSTransformToPoints.m +++ b/lib/ANTSTransforms/applyANTSTransformToPoints.m @@ -22,7 +22,15 @@ % (c) 2017 % mail@andreashusch.de, husch.andreas@chl.lu function transPoints = applyANTSTransformToPoints(points, antsTransformFileStrings) -applyTransformsToPointsCmd = '/Applications/ANTSGit/bin/antsApplyTransformsToPoints'; % FIXME: Make multi-os compatabile and find bins automatically +try +[~, t] = system('echo $ANTSPATH'); +antspath = t(1:end-1); % remove line ending +end +if(~isempty(t)) + applyTransformsToPointsCmd = [antspath 'antsApplyTransformsToPoints']; +else + applyTransformsToPointsCmd = 'antsApplyTransformsToPoints'; % FIXME: Make multi-os compatabile and find bins automatically +end tempFile = [tempname() '.csv']; tempFileOut = [tempname() '.csv']; From 347e558212abc535ceba4853172a5aad1a0a680c Mon Sep 17 00:00:00 2001 From: Andreas Husch <27815260+adhusch@users.noreply.github.com> Date: Thu, 21 Feb 2019 15:04:20 +0100 Subject: [PATCH 3/4] Improved Brain Mask Extraction - Erode mask slightly to fit LeadDBS provied masks which might be bit to large --- src/Functions/extractElectrodePointclouds.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Functions/extractElectrodePointclouds.m b/src/Functions/extractElectrodePointclouds.m index e084acd..03fa82b 100644 --- a/src/Functions/extractElectrodePointclouds.m +++ b/src/Functions/extractElectrodePointclouds.m @@ -50,9 +50,8 @@ disp(['Thresholding ' niiCT.filepath ' for metal with METAL_THRESHOLD = ' num2str(METAL_THRESHOLD) '...']); maskedImg = niiCT.img; - % [xx,yy,zz] = ndgrid(-10:10); - %structEle = sqrt(xx.^2 + yy.^2 + zz.^2) <= 2.5 / sqrt(max(niiCT.voxsize)); - %brainMask = imerode(imerode(brainMask,structEle),structEle); + structEle = strel('sphere', ceil(3 / max(niiCT.voxsize)) ); % make sure brain mask contains no skull + brainMask = imerode(brainMask,structEle); maskedImg(~(brainMask)) = NaN; threImg = (maskedImg > METAL_THRESHOLD); From 01bb5967da898a822dea2c94f8baba1bad355a74 Mon Sep 17 00:00:00 2001 From: Andreas Husch <27815260+adhusch@users.noreply.github.com> Date: Fri, 22 Feb 2019 11:36:17 +0100 Subject: [PATCH 4/4] Apply voxel intensity scaling to .nii loaded untouched NiftiMod is using load_untouch_nii for some time leavign the data untransformed. However the voxel intensities should be scaled --- lib/NiftiOOP/NiftiMod.m | 6 ++- lib/NiftiOOP/applyNiiIntensityScaling.m | 61 +++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 lib/NiftiOOP/applyNiiIntensityScaling.m diff --git a/lib/NiftiOOP/NiftiMod.m b/lib/NiftiOOP/NiftiMod.m index 0b7a2ce..5813c1a 100644 --- a/lib/NiftiOOP/NiftiMod.m +++ b/lib/NiftiOOP/NiftiMod.m @@ -85,8 +85,10 @@ function [image, header] = load(this) if( ~this.isLoaded && ~strcmp(this.filepath,'')) % it is not already isLoaded and we were not called with empty string (by Matlab callingn our get functions without command after initiating!) disp(['Loading ' this.filepath ' from disk...']); - % nifti = load_nii(this.filepath, [], [], [], [], [], 0.1, 'q'); % load with 0.1 tolerance, prefer the q-form over the sform! - nifti = load_untouch_nii(this.filepath); % load with 0.1 tolerance, prefer the q-form over the sform! + %nifti = load_nii(this.filepath, [], [], [], [], [], 0.1, 'q'); % load with 0.1 tolerance, prefer the q-form over the sform! + nifti = load_untouch_nii(this.filepath); % load untouched, i.e. keep orginial data orientation (dont apply any transform) + nifti = applyNiiIntensityScaling(nifti); %however, the voxel intesities should be scaled correctly now here (as they +%would by load_nii otherewise) this.header = nifti.hdr; % header should maybe kept all the time .. diff --git a/lib/NiftiOOP/applyNiiIntensityScaling.m b/lib/NiftiOOP/applyNiiIntensityScaling.m new file mode 100644 index 0000000..123b2c7 --- /dev/null +++ b/lib/NiftiOOP/applyNiiIntensityScaling.m @@ -0,0 +1,61 @@ +function nii = applyNiiIntensityScaling(nii) +% Code extracte from Jimmy Shen's (jimmy@rotman-baycrest.on.ca) xform_nii.m +% method, which is part of the nifti toolbox +% +% Andreas Husch, 2019 + + % if scl_slope field is nonzero, then each voxel value in the + % dataset should be scaled as: y = scl_slope * x + scl_inter + % I bring it here because hdr will be modified by change_hdr. + % + if nii.hdr.dime.scl_slope ~= 0 & ... + ismember(nii.hdr.dime.datatype, [2,4,8,16,64,256,512,768]) & ... + (nii.hdr.dime.scl_slope ~= 1 | nii.hdr.dime.scl_inter ~= 0) + + nii.img = ... + nii.hdr.dime.scl_slope * double(nii.img) + nii.hdr.dime.scl_inter; + + if nii.hdr.dime.datatype == 64 + + nii.hdr.dime.datatype = 64; + nii.hdr.dime.bitpix = 64; + else + nii.img = single(nii.img); + + nii.hdr.dime.datatype = 16; + nii.hdr.dime.bitpix = 32; + end + + nii.hdr.dime.glmax = max(double(nii.img(:))); + nii.hdr.dime.glmin = min(double(nii.img(:))); + + % set scale to non-use, because it is applied in xform_nii + % + nii.hdr.dime.scl_slope = 0; + + end + + % However, the scaling is to be ignored if datatype is DT_RGB24. + + % If datatype is a complex type, then the scaling is to be applied + % to both the real and imaginary parts. + % + if nii.hdr.dime.scl_slope ~= 0 & ... + ismember(nii.hdr.dime.datatype, [32,1792]) + + nii.img = ... + nii.hdr.dime.scl_slope * double(nii.img) + nii.hdr.dime.scl_inter; + + if nii.hdr.dime.datatype == 32 + nii.img = single(nii.img); + end + + nii.hdr.dime.glmax = max(double(nii.img(:))); + nii.hdr.dime.glmin = min(double(nii.img(:))); + + % set scale to non-use, because it is applied in xform_nii + % + nii.hdr.dime.scl_slope = 0; + + end +end \ No newline at end of file