Creating a movie sequence from rgb images

6 ビュー (過去 30 日間)
Nora
Nora 2011 年 8 月 27 日
コメント済み: Walter Roberson 2017 年 8 月 17 日
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 Center および File ExchangeColor and Styling についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by