Project 3 grayscale images into a single RGB image, as done with "stack to RGB" in ImageJ
Show older comments
So, I have three different tiff stacks that are gray scale. I loop through each image of each stack, concatenating them together. I then want to something like "Stack to RGB in ImageJ, where these three grayscale images are converted into a single image that's color-coded according the the similarity between the three images. Ultimately, I will be writing a tiff stack that has the same number of frames as each of the three original grayscale tiff stacks, but colored to show differences in an animal's behavior across three conditions. My approach is below, showing how I loop through the number of frames in the tiff stacks, concatenate, and then attempt to write the RGB image.
for frame = 1:num_frames
if frame == 1 && exist([video_dir '\Peristim_RGB_mov.tif'])
display('Peristim_RGB_mov already exists. Delete in order to proceed.');
end
grey = [];
grey = cat(3,grey,imread([video_dir '\CS_shock_MovMean'],'tif',frame));
grey = cat(3,grey,imread([video_dir '\CS_neutral_MovMean'],'tif',frame));
grey = cat(3,grey,imread([video_dir '\CS_food_MovMean'],'tif',frame));
%rgb = repmat(double(grey)./255,1);
RGB_frame = mean(rgb,3);
try
imwrite(RGB_frame,'Peristim_RGB_mov.tif','WriteMode','append', ...
'Compression','none');
catch err
pause(0.1);
imwrite(RGB_frame,'Peristim_RGB_mov.tif','WriteMode','append', ...
'Compression','none');
end
end
4 Comments
Image Analyst
on 26 Aug 2014
What is a "stack"? Is it some number of gray scale images? If so, how many? Is it some number of color images, like a multi-page Tiff image? If so, how many color images are in the stack? And after all is done, how many image planes will be in grey? 3? 9? More?
Pavlov
on 26 Aug 2014
Image Analyst
on 26 Aug 2014
546 grayscale frames, or color frames? When you say "each frame of the three originals will be smooshed into a single RGB image" do you mean that each frame the 3 movies is a gray scale image that supposed to be one color channel of the output frame, so it takes one frame from each stack to create one frame of the RGB output movie?
Pavlov
on 26 Aug 2014
Answers (2)
Pavlov
on 4 Sep 2014
0 votes
Image Analyst
on 4 Sep 2014
0 votes
Read in images 1-3, concatenate them into an rgb image, and make a video frame. Then read in images 2-4 and do the same thing, then images 3-5, etc. Attached is a demo for how to create a movie from individual RGB images.
Categories
Find more on Convert Image Type in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!