Skip to content

Commit

Permalink
Merge pull request #40 from andypotatohy/gavin
Browse files Browse the repository at this point in the history
upgrade the sliceshow function by Gavin
  • Loading branch information
andypotatohy authored May 21, 2024
2 parents 5e493ea + 47efc9c commit cbfea4b
Show file tree
Hide file tree
Showing 5 changed files with 229 additions and 70 deletions.
15 changes: 15 additions & 0 deletions brainCrop.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
% Crops the image to the brain using segmentation
% Returns the upper and lower bounds of the brain in each direction
% column 1 = R/L, column 2 = A/P, column 3 = S/I
% (c) 2024 Gavin Hsu and Andrew Birnbaum

function bbox = brainCrop(subj)
[dirname,baseFilename] = fileparts(subj);
seg = [dirname filesep baseFilename,'_masks.nii'];
data = load_untouch_nii(seg);
wm = data.img == 1;
thresh = [0,0,100];
[bbox(1,1),bbox(2,1)]=bounds(find(sum(sum(wm,2),3)>thresh(1)));
[bbox(1,2),bbox(2,2)]=bounds(find(sum(sum(wm,1),3)>thresh(2)));
[bbox(1,3),bbox(2,3)]=bounds(find(sum(sum(wm,1),2)>thresh(3)));
end
2 changes: 2 additions & 0 deletions releasingNotes.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Added a function to set the headers of the MRI and segmentation masks so that th

Added code to handle MRIs with nonzero qform in their header.

Upgraded the sliceshow() function for better visualization of slices in a 3D volume.


ROAST V3.0 (codename: Hell's Kitchen) -- 2019/09/02:

Expand Down
15 changes: 12 additions & 3 deletions reviewRes.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ function reviewRes(subj,simTag,tissue,fastRender,tarTag)
% (c) MultiPriors segmentation developed by Lukas Hirsch, and integrated into
% ROAST by Andrew Birnbaum
% April 2024
%
% (c) May 2024, sliceshow improved by Gavin Hsu and Andrew Birnbaum

fprintf('\n\n');
disp('=============================================================')
Expand Down Expand Up @@ -517,6 +519,13 @@ function reviewRes(subj,simTag,tissue,fastRender,tarTag)
nan_mask(find(mask)) = 1;

cm = colormap(jet(2^11)); cm = [1 1 1;cm];
if strcmp(tissue,'white') || strcmp(tissue,'gray') || strcmp(tissue,'brain')
bbox = brainCrop(subjRasRSPDSeg);
pos = round(mean(bbox));
else
bbox = [];
pos = [];
end

if isRoast

Expand All @@ -528,13 +537,13 @@ function reviewRes(subj,simTag,tissue,fastRender,tarTag)
end

figName = ['Voltage in Simulation: ' simTag];
sliceshow(vol_all.*nan_mask,[],cm,[],'Voltage (mV)',[figName '. Click anywhere to navigate.'],[],mri2mni); drawnow
sliceshow(vol_all.*nan_mask,pos,cm,[],'Voltage (mV)',[figName '. Click anywhere to navigate.'],[],mri2mni,bbox); drawnow

figName = ['Electric field in Simulation: ' simTag];
for i=1:size(ef_all,4), ef_all(:,:,:,i) = ef_all(:,:,:,i).*nan_mask; end
ef_mag = ef_mag.*nan_mask;
dataShowVal = ef_mag(~isnan(ef_mag(:)));
sliceshow(ef_mag,[],cm,[min(dataShowVal) prctile(dataShowVal,95)],'Electric field (V/m)',[figName '. Click anywhere to navigate.'],ef_all,mri2mni); drawnow
sliceshow(ef_mag,pos,cm,[min(dataShowVal) prctile(dataShowVal,95)],'Electric field (V/m)',[figName '. Click anywhere to navigate.'],ef_all,mri2mni,bbox); drawnow

else

Expand All @@ -543,6 +552,6 @@ function reviewRes(subj,simTag,tissue,fastRender,tarTag)
dataShowVal = r.ef_mag(~isnan(r.ef_mag(:)));
for i=1:size(r.targetCoord,1)
figName = ['Electric field at Target ' num2str(i) ' in Targeting: ' tarTag];
sliceshow(r.ef_mag,r.targetCoord(i,:),cm,[min(dataShowVal) prctile(dataShowVal,95)],'Electric field (V/m)',[figName '. Click anywhere to navigate.'],r.ef_all,mri2mni); drawnow
sliceshow(r.ef_mag,r.targetCoord(i,:),cm,[min(dataShowVal) prctile(dataShowVal,95)],'Electric field (V/m)',[figName '. Click anywhere to navigate.'],r.ef_all,mri2mni,bbox); drawnow
end
end
Loading

0 comments on commit cbfea4b

Please sign in to comment.