From ea17730b7c99b766d0e725e87cd20f59b4505cbd Mon Sep 17 00:00:00 2001 From: Andreas <27815260+adhusch@users.noreply.github.com> Date: Fri, 27 Apr 2018 17:11:13 +0200 Subject: [PATCH] Towards 0 failures.. --- src/Functions/extractBrainConvHull.m | 9 ++++++--- src/Functions/extractElectrodePointclouds.m | 2 +- src/PaCER.m | 2 +- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Functions/extractBrainConvHull.m b/src/Functions/extractBrainConvHull.m index 3d37437..cfb0b0c 100644 --- a/src/Functions/extractBrainConvHull.m +++ b/src/Functions/extractBrainConvHull.m @@ -29,7 +29,8 @@ ctIso = niiCT.img; % = downsampleImage(niiCT.img, niiCT.voxsize, niiCT.voxdim); % threshold -threImg = (ctIso > LOWER_CT_BRAIN_THRESHOLD & ctIso < UPPER_CT_BRAIN_THRESHOLD); +ctIsoMedFilt = medfilt3(ctIso); +threImg = (ctIsoMedFilt > LOWER_CT_BRAIN_THRESHOLD & ctIsoMedFilt < UPPER_CT_BRAIN_THRESHOLD); %threImg = reshape(threImg,niiCT.voxdim'); [xx,yy,zz] = ndgrid(-2:2); structEle = sqrt(xx.^2 + yy.^2 + zz.^2) <= 2.5 / sqrt(max(niiCT.voxsize)); @@ -38,10 +39,12 @@ %G = gpuArray(structure); % if we have CUDA.. % morphology +%threImg = medfilt3(threImg); morphImg = imopen(threImg,structEle); morphFaction = sum(morphImg(:)) / numel(morphImg); -if(morphFaction < 0.05 || morphFaction > 0.3) +if(morphFaction < 0.06 || morphFaction > 0.3) warning('Uncommon fraction of CT data in threshold range (15-60 HU). Trying to compensate. Make sure to use "soft tissue" reconstruction filters for the CT (e.g. J30 kernel) if this fails. ') + threImg = medfilt3(threImg); morphImg = imclose(threImg,structEle); %maybe we have a super noise brain tissue image, thus to CLOSE instead of open first morphImg = imerode(morphImg,structEle); % due to the closing all masks will enlarge, i.e. the brain mask might cover the ckull, thus we have to shrink it at the very end again end @@ -63,7 +66,7 @@ convHullBrainMask = false(size(roughBrainMask)); maskedCT = ctIso; maskedCT(~roughBrainMask) = NaN; %threshold the roughBrainMask again to make sure no skull is contained due to morphology -roughBrainMask = (maskedCT > LOWER_CT_BRAIN_THRESHOLD & maskedCT < UPPER_CT_BRAIN_THRESHOLD); +roughBrainMask = (maskedCT > LOWER_CT_BRAIN_THRESHOLD & maskedCT < UPPER_CT_BRAIN_THRESHOLD); %TODO check if removable for i=1:size(roughBrainMask,3) convHullBrainMask(:,:,i) = bwconvhull(roughBrainMask(:,:,i)); roughBrainMask(:,:,i) = imfill(roughBrainMask(:,:,i), 'holes'); diff --git a/src/Functions/extractElectrodePointclouds.m b/src/Functions/extractElectrodePointclouds.m index 173efb0..d044522 100644 --- a/src/Functions/extractElectrodePointclouds.m +++ b/src/Functions/extractElectrodePointclouds.m @@ -8,7 +8,7 @@ function [elecsPointcloudStruct, brainMask] = extractElectrodePointclouds(niiCT, varargin) % CONSTANTS - LAMBDA_1 = 30; % + LAMBDA_1 = 25; % elec latent space length [mm] %% Optional Arguments and Default Values argParser = inputParser(); diff --git a/src/PaCER.m b/src/PaCER.m index 1d67ff1..c01868b 100644 --- a/src/PaCER.m +++ b/src/PaCER.m @@ -32,7 +32,7 @@ args.contactDetectionMethod = 'contactAreaCenter'; end %% Checks -if(~isa(niiCT, 'NiftiMod')) +if(~isa(niiCT, 'NiftiMod') && ~isa(niiCT, 'NiftiModSPM') ) disp('First parameter is not a nifti object. Intrepretating as filename and tring to load a nifti file with that name from disk...'); niiCT = NiftiMod(niiCT); end