Borrar filtros
Borrar filtros

Subplot - linkaxes for 2 out of 3 images

1 visualización (últimos 30 días)
Avishay Assayag
Avishay Assayag el 26 de Mayo de 2021
Editada: Avishay Assayag el 6 de Jul. de 2021
Hi,
I have 3 images, each of different dimension. I'm plotting the 3 images side by side using subplot.
The above is done in a loop - in each iteration 3 similar images are dispayed and are saved to a movie.
I would like that the middle and the right image will be displayed accodring to the real size and proportions between both images, and that the left image will be shown with the same height as the middle image (maintaining the aspect ratio of this image)
I'm using the code below.
In the first iteration everything looks fine, though in the following iterations it does not dispalyed as expected.
See 2 example pictures below:
First Iteration:
Following Iterations:
VidObj = VideoWriter(fname, 'MPEG-4'); %set your file name and video compression
open(VidObj);
for k = 1:NumOfFrames
% 800x482
h1 = subplot(1, 3, 1);
imshow(Image1(:, :, k);
% 640x480
h2 = subplot(1, 3, 2);
imshow(Image2(:, :, k));
% 1280x720
h3 = subplot(1, 3, 3);
imshow(Image3(:, :, k));
%
linkaxes([h2,h3])
f = getframe(gcf);
writeVideo(VidObj, f);
end
  5 comentarios
Avishay Assayag
Avishay Assayag el 27 de Mayo de 2021
Thanks Jonas!
clf improved performance.
Running over 1460 frames took as follows:
Without close(gcf), runtime = 243sec
With close(gcf) ,runtime = 462sec
Without close(gcf), using clf('reset'), runtime = 288sec
Jonas
Jonas el 27 de Mayo de 2021
if you are satisfied by that 'solution' i would post it as answer under your question

Iniciar sesión para comentar.

Respuesta aceptada

Avishay Assayag
Avishay Assayag el 9 de Jun. de 2021
Editada: Avishay Assayag el 6 de Jul. de 2021
Hi,
I found a solution how to avoid the display problem while improving performance greatly.
The code below runs much faster, about 75sec, which is 1/3 of the time comparing to the previous code, without the original display problem.
VidObj = VideoWriter(fname, 'MPEG-4'); % Set your file name and video compression
open(VidObj);
%% Plot first image in all image arrays
subplot(1, 3, 1);
h1 = imshow(Image1(:, :, 1);
%
subplot(1, 3, 2);
h2 = imshow(Image2(:, :, 1));
%
subplot(1, 3, 3);
h3 = imshow(Image3(:, :, 1));
linkaxes([h2,h3])
%%
for k = 2:NumOfFrames
% 800x482
Image = Image1(:, :, k);
set(h1, 'CData', Image);
% 640x480
Image = Image2(:, :, k);
set(h2, 'CData', Image);
% 1280x720
Image = Image3(:, :, k);
set(h3, 'CData', Image);
%
f = getframe(gcf);
writeVideo(VidObj, f);
end

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by