Creating a movie sequence from rgb images
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Nora
el 27 de Ag. de 2011
Comentada: Walter Roberson
el 17 de Ag. de 2017
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 comentarios
Respuesta aceptada
Chaowei Chen
el 27 de Ag. de 2011
Editada: Walter Roberson
el 17 de Ag. de 2017
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 comentarios
noam Y
el 17 de Ag. de 2017
is it possible to simply write the RGB image to the rgbf array without code lines 2-5?
Walter Roberson
el 17 de Ag. de 2017
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]);
Más respuestas (0)
Ver también
Categorías
Más información sobre Convert Image Type en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!