store mask created from roipoly on scans running in for loop, in new variable

2 ビュー (過去 30 日間)
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

採用された回答

KALYAN ACHARJYA
KALYAN ACHARJYA 2019 年 11 月 1 日
編集済み: KALYAN ACHARJYA 2019 年 11 月 1 日
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.....
  1 件のコメント
Raheema Al Karim Damani
Raheema Al Karim Damani 2019 年 11 月 15 日
thank you I did figure it out. Appreciate your assistance.

サインインしてコメントする。

その他の回答 (0 件)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by