Creating a movie sequence from rgb images

1 次查看(过去 30 天)
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

采纳的回答

Chaowei Chen
Chaowei Chen 2011-8-27
编辑:Walter Roberson 2017-8-17
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);
  2 个评论
noam Y
noam Y 2017-8-17
is it possible to simply write the RGB image to the rgbf array without code lines 2-5?
Walter Roberson
Walter Roberson 2017-8-17
The original question involved having a sequence of masks that needed to be overlayed into the frames. Do you have that requirement as well? If not then you could use
rbgf = dataset(:, :, start_frame : end_frame );
rgbf = repmat( permute(rgbf, [1 2 4 3]), 1, 1, 3, 1);
This code assumes you are moving from grayscale frames to RGB with equal R, G, and B components, for further processing. If you are only intending to write the frames as movies from there, then you would be better off leaving it as grayscale:
rgbf = permute(dataset(:, :, start_frame : end_frame ), [1 2 4 3]);

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Convert Image Type 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by