MATLAB: Creating a movie sequence from rgb images

colormap truecolorimoverlaymovie

Dear All,
Given a 3D array of grayscale images (M by N by K – where k is the number of images), and a 3D array of binary masks; I would like first of all to produce a series of images where the boundary of each mask (i.e. boundary = edge(mask)) has been drawn on to the corresponding image in red; then I would like to create a new array of these truecolor images and display it as a movie.
The problem is in creating the new array of truecolor images. I tried this code:
new_sequence(:,:,3,frame_idx) = imoverlay(image, boundary, [1 0 0]);
but it produced a subscripted assignment dimension mismatch error.
So then I tried the following solution:
for frame_idx = start_frame:end_frame
image = dataset(:,:,frame_idx);
msk = mask_stack(:,:,frame_idx);
boundary = edge(msk, 'canny');
rgb = imoverlay(image, boundary, [1 0 0]);
[X(:,:,1,frame_idx), map] = rgb2ind(rgb, 3);
end
mov = immovie(X,map);
implay(mov);
But the resulting colormap of the movie was not what I expected; I would like the frames the movie to be grayscale (i.e. unchanged) with the boundaries drawn in red – however this code produces a movie with something like a grayscale colormap but the boundary also in gray.
If anyone can help – it would be much appreciated!
-n

Best Answer

for frame_idx = start_frame:end_frame
image = dataset(:,:,frame_idx);
msk = mask_stack(:,:,frame_idx);
boundary = edge(msk, 'canny');
rgb = repmat(image,[1 1 3]);
rgb(:,:,1)=max(boundary,image);
rgbf(:,:,:,frame_idx)=rgb;
end
mov = immovie(rgbf); implay(mov);