Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add merge ROIs feature #9

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/roi/createRoi.m
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,33 @@

mask = createRoiLabel(mask);

case 'merge'

roiImages = specification;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are still developping this but I suspect we'll want to have the same way to use specification for all "cases":

so that it will be something like :

specification(1).mask = roi_filenameA
specification(2).mask = roi_filenameB

not necessary to have now but just to let you know that the "API" and the type and name of arguments for this function are still a moving target. :-)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure if this replys to it but in a batch file you would have eg

roiImages = {fullfile(opt.ROI.roiDir, 'label-sphere5xMinus40yMinus50zMinus22_mask.nii'); ...
             fullfile(opt.ROI.roiDir, 'label-sphere5x36yMinus46zMinus17_mask.nii')};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More like this

specification(1).mask = fullfile(opt.ROI.roiDir, 'label-sphere5xMinus40yMinus50zMinus22_mask.nii');
specification(2).mask = fullfile(opt.ROI.roiDir, 'label-sphere5x36yMinus46zMinus17_mask.nii');


% loop through the ROIs to merge
for iRoi = 1:length(roiImages)
% load one ROI per time
maskToMerge = load_untouch_nii(roiImages{iRoi});
% take the first ROI as reference to add the others to it
if iRoi == 1
mask = maskToMerge;
% delete the fileprefix argument to be re-assigned with the new one
mask.fileprefix = [];
else
% sum up the ROI masks
mask.img = mask.img + maskToMerge.img;
end

end

% check that there are no >1s
mask.img(mask.img > 1) = 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am pretty sure that in this case you can just convert mask.img to a logical array:

mask.img = logical(mask.img);

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that using

      % merge the logical masks into one
      mask = any(mask, 4);

will save us from having values >1

although, maybe for the future, we would like to have different values for each single single ROI merged

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you mean having a single image that combines different masks has a different "label" for each ROI: I agree but I would have that as an entirely different function.
And I think that MarsBar must have some functions to do that.


% assign fileprefix (name to be save?)
% [ WIP ]
mask = createRoiLabel(mask);

case 'expand'

% Ugly hack
Expand Down