store mask created from roipoly on scans running in for loop, in new variable
1 view (last 30 days)
Show older comments
Raheema Al Karim Damani
on 30 Oct 2019
Commented: Raheema Al Karim Damani
on 15 Nov 2019
I have a series of mri scans stored in a 256 x256 x 19 variable. Each scan in the series has a different ROI that I want to mask out using roipoly. Is there a way that I can turn this code into a for loop to mask out the roi and store the output mask eg. tumor1, tumor2, tumor3 for each scan in a separate variable after each iteration?
%%
[tumor2, x2, y2] = roipoly(segmentT2Flair(:,:,2));
%%
[tumor3, x3, y3] = roipoly(segmentT2Flair(:,:,3));
%%
[tumor4, x4, y4] = roipoly(segmentT2Flair(:,:,4));
%%
[tumor5, x5, y5] = roipoly(segmentT2Flair(:,:,5));
%%
% mask over tumor ROI
%segment_mask = poly2mask(xi, yi, 256, 256); %creates a mask based on dimensions
segment_mask = cat(3,tumor1, tumor2, tumor3, tumor4, tumor5, tumor6, tumor7, tumor8, tumo
%%
for i = numslices:-1:1
[tumor(i), xi, yi] = roipoly(SegmentT2Flair(:,:,i)); %when i run this it only saves the mask and dimensions of the last slice not the 18 before
end
for i: numslices:-1:1 %in this loop the images are outputted as jpg but not stored in matlab array and dimensions are not stored
[tumor] = roipoly(SegmentT2Flair(:,:,i))
filename = ['Segmented', num2str(i), '*.jpg']
saveas(1, filename);
hold off
0 Comments
Accepted Answer
KALYAN ACHARJYA
on 1 Nov 2019
Edited: KALYAN ACHARJYA
on 1 Nov 2019
You can store the mask in cell array and later call any mask as per requiremnets.
n=?? % define
mask=cell(1,n)
for i=1:n
%Mask generation, say mask_data
mask{i}=mask_data
end
Noy you can any mask as later say mask{1}, mask{2}, so on.....
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!