How can you take a maximum intensity projection (MIP) of an image stack?

14 views (last 30 days)
So I'm pulling an image stack from a filepath (all jpegs) and combining them to form a an image stack. I then process the stack through the a grayscale protocol (basically rgb2gray for multiple images at the same time). I then run the graystack through the max command down each column along the Z-axis. I convert the result X x Y matrix into a 8 bit image with uint8 command. However, my resulting image is not an MIP. It's overly saturated (filled with white pixels), especially in comparison to the MIP I acquire when I run the stack through ImageJ. I believe my computational method for MIP is incorrect and may very well over-simplify what an MIP mathematically does. I was wondering if you had any suggestions? Many many thanks!
for k=1:9
jpgFileName=strcat('Image0090_01000',num2str(k),'.jpg');
if exist(jpgFileName,'file')
imageData=imread(jpgFileName);
for i=1:b
for j=1:b
Stack(i,j,1,k)=imageData(i,j,1);
Stack(i,j,2,k)=imageData(i,j,2); %populate Stack with RGB intensity values
Stack(i,j,3,k)=imageData(i,j,3);
end
end
else
fprintf('File %s does not exist.\n',jpgFileName);
end
end
for k=10:99
jpgFileName=strcat('Image0090_0100',num2str(k),'.jpg');
if exist(jpgFileName, 'file')
imageData=imread(jpgFileName);
for i=1:b
for j=1:b
Stack(i,j,1,k)=imageData(i,j,1);
Stack(i,j,2,k)=imageData(i,j,2);
Stack(i,j,3,k)=imageData(i,j,3);
end
end
else
fprintf('File %s does not exist.\n',jpgFileName);
end
end
for k=100:a
jpgFileName=strcat('Image0090_010',num2str(k),'.jpg');
if exist(jpgFileName, 'file')
imageData=imread(jpgFileName);
for i=1:b
for j=1:b
Stack(i,j,1,k)=imageData(i,j,1);
Stack(i,j,2,k)=imageData(i,j,2);
Stack(i,j,3,k)=imageData(i,j,3);
end
end
else
fprintf('File %s does not exist.\n',jpgFileName);
end
end
grayStack = squeeze( 0.2989 * Stack(:,:,1,:) + 0.5870 * Stack(:,:,2,:) + 0.1140 * Stack(:,:,3,:) ); %X, Y, Z after squeeze--this is the RGB2gray test=int8(max(grayStack,[],3)); %%I feel like this bit conversion might be where my calculations be incorrect imshow(test);

Answers (1)

Image Analyst
Image Analyst on 4 Aug 2014
You don't need loops over i and j, just operate on the whole 3D image with the max() function. Also, you need only one loop over k if you just get the filenames before the k loop with the dir command. After you get the max RGB image, you can convert to grayscale if you want to.
  2 Comments
Harsh Patolia
Harsh Patolia on 5 Aug 2014
Thank you so much for your help. The only way I can construct the image stack, however, is with my for loops with i and j. MATLAB does not import images directly as image stacks does it? I was under the impression it only does so as sequences, and the user is required to program a code to construct an image stack from these sequences? Thank you, once again!
Image Analyst
Image Analyst on 5 Aug 2014
It can create a stack from a sequence of files. And, like I said you don't need loops over i and j, you only need k. Also, do you want your max to be color or gray scale?

Sign in to comment.

Categories

Find more on Display Image in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!