How to make ROI fit for function to avoid error with subscript indices?

2 views (last 30 days)
I keep getting the following error when trying to use another ROI than the one that was made when I wrote the function and script:
Subscript indices must either be real positive integers or logicals.
Error in getROIvals (line 10)
roi_vals(i) = mean(cur_img(ROI));
Error in roi_fit (line 12)
roi_vals = getROIvals(data,slice,ROI);
Can somebody please point out how to fix it? I originally used a ROI = roipoly(mat2gray(S0)) which has size 128x128, so I thought there would be no problem using another ROI-mask with same size and format (perhaps the problem is that it's not same size and format, allthough it is 128x128).
The function is:
function roi_vals = getROIvals(data,slice,ROI)
S = double(squeeze(data(:,:,slice,:))); %size 128x128x8
n = size(S,3);
roi_vals = zeros(n,1);
for i = 1:n
cur_img = S(:,:,i);
roi_vals(i) = mean(cur_img(ROI));
end
end
What does not work:
slice = 3; %the slice the mask is applied to
data = load4D('VOLUME_IMAGEb0',8,[0 50 100 150 400 500 600 800]);
%S0 = double(squeeze(data(:,:,slice,1))); % for the ROI = roipoly(mat2gray(S0)), which works..
ROI = mat2gray(BW); %BW is a 128x128 mask yielded from another script
imagesc(ROI);
save('ROI');
roi_vals = getROIvals(data,slice,ROI);

Accepted Answer

BME student, Copenhagen
BME student, Copenhagen on 16 Apr 2014
Actually, I looked at ROI created with the roipoly the first time, and it created 128x128 logical, so I solved it by setting ROI = logical(mat2gray(BW)) and now the little "blip" is fixed, so the whole machinery works and I can get som serious data output! Yay!

More Answers (0)

Community Treasure Hunt

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

Start Hunting!