Save an iterated 3D pixel sum as a vector? (Successful help -> I'll paypal the value of a beer!)
조회 수: 7 (최근 30일)
이전 댓글 표시
Hello,
I have written a program that extracts SPECT data from regions of interest (ROI) within an image set. Part of the program iterates a mask for the ROI over a 3D space to sum all the pixel values within that volume for the set of images.
What do I need to add to the code to successfully save the pixel sum as a vector and not scalar that's replaced each iteration? I've tried all the basics and keep getting different error messages.
Thank you for any help.
(This is part of a nested for loop iterated over a series of 29 images)
%Sum over heart
sumHeart=0;
heart = ImgBig.*uint16(heartmask);
for h=heightLower(CaseStudy,1):heightUpper(CaseStudy,1)
for w=widthLower(CaseStudy,1):widthUpper(CaseStudy,1)
for d=depthLower(CaseStudy,1):depthUpper(CaseStudy,1)
sumHeart = sumHeart + heart(h,w,d);
end
end
end
댓글 수: 3
답변 (2개)
Image Analyst
2012년 4월 26일
How about this:
counter = 1; % Before the loops start.
Then inside the loop, just make sumheart an array:
sumHeart(counter) = sumHeart(counter-1) + heart(h,w,d);
counter = counter + 1;
Is that what you want?
댓글 수: 9
Geoff
2012년 4월 29일
If it comes out as all zeros, then I'd be suspicious of the data in your 'heart' matrix... What is the original data? I assume it's ImgBig. Is that uint16? What is the value of max(uint16(heartmask(:)))?
I suspect you have values that are being rounded to zero in your initial array. And/or you may need to cast your values to double as you sum them.
Geoff
2012년 4월 26일
Just gonna chuck in my 2c worth...
h = heightLower(CaseStudy,1):heightUpper(CaseStudy,1);
w = widthLower(CaseStudy,1):widthUpper(CaseStudy,1);
d = depthLower(CaseStudy,1):depthUpper(CaseStudy,1);
H = permute( heart(h,w,d), [3 2 1] );
heartSum = cumsum(H(:));
참고 항목
카테고리
Help Center 및 File Exchange에서 Mathematics and Optimization에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!