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
댓글 수: 0
채택된 답변
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
2017년 8월 17일
is it possible to simply write the RGB image to the rgbf array without code lines 2-5?
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 Exchange에서 Convert Image Type에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!