To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016
I am trying to create an ROI mask that will read in multiple image files that were taken over time, average all those files into a single array, create an ROI mask from the average image, then use that mask to go back to each individual image and analyze the image using only the ROI created from the average mask. Here is what I have so far:
NUM=0; for i=1:13 img(:,:,i)=read_LUM2; Lmask=mean(img,3); Lmask(Lmask<415)=0; Lmask(Lmask~=0)=1; Lmask=logical(Lmask); NUM=NUM+1; L(NUM)=mean2(imgL(Lmask)); end avgL=L(1:13)'
The problem is that I can't figure out how to get Lmask to wait until all files have been read to average, and then still use Lmask in each iteration. Any suggestions?
But your "average" mask is only up through image #i, not over all 13. Why is that? Also I don't know how read_LUM2 gives you a different image each time but I guess I'll just assume it does (like maybe there are persistent variables inside the function that remember that last value). Since the average image is only up to and including image #i, I'm not sure why you threshold each "average" image at 415. And these three lines:
Lmask(Lmask<415)=0; Lmask(Lmask~=0)=1; Lmask=logical(Lmask);
could be done with one single line
LMask = LMask >= 415;
Next, imgL(Lmask) is not a 2D matrix. It's a 1D list of all the pixels in the mask, so you can use mean() instead of mean2().
Finally, you don't need NUM at all. Just use i everywhere you use NUM.
But to do what you say, you need two loops. The first one to go over all the images and find the mean image. Then create the mask. Then have another loop to process all the images with the mask.