필터 지우기
필터 지우기

원본 텍스트 Data plotted using VideoWriter and data saved as avi are different.

조회 수: 2 (최근 30일)
Byoungjoon Yu
Byoungjoon Yu 2021년 6월 30일
답변: Samay Sagar 2024년 2월 20일
clear all;close all;clc;
frame_dir = 'C:\Users\Admin\Desktop/saved_frame.mat';
load(frame_dir)
load('colormapsavefile1.mat');
% visualize
vidfile = VideoWriter('testmovie.avi','MPEG-4');
open(vidfile);
for time= 1:500
surf(frame(:,:,time));
view(0,90)
%colormap Winter;
colormap(myColormap);
writerObj.Height = 960;
writerObj.Width = 900;
axis off
shading interp
drawnow
% add code for save image
F(time) = getframe(gcf);
writeVideo(vidfile,F(time));
end
close all;clear all;clc;
If you apply the above code to plot, you will get the following result.
However, when I opened the file saved as an avi file or mp4 file, a white background appeared unlike in Matlab.
I want to erase the border.
What code should I use?
I don't know how.
Please help me.

답변 (1개)

Samay Sagar
Samay Sagar 2024년 2월 20일
To resolve the issue of the white background or borders appearing in your saved video file, you need to set the figure and axes properties to match the frame size, and capture the frame using “getframe” on the off screen figure.
Here’s how you can implement the required changes:
clear all; close all; clc;
frame_dir = 'saved_frame.mat';
load(frame_dir)
frameHeight = size(frames, 1);
frameWidth = size(frames, 2);
vidfile = VideoWriter('testmovie3.avi');
open(vidfile);
for time = 1:size(frames, 3) % Assuming third dimension is time
f = figure('visible', 'off');
ax = axes('Parent', f, 'Position', [0 0 1 1]);
surf(ax, frames(:,:,time), 'EdgeColor', 'none');
view(0,90);
% Remove axis and set shading
axis tight
shading interp
drawnow
% Adjust figure properties
set(f, 'Position', [0, 0, frameWidth, frameHeight]);
set(ax, 'Unit', 'normalized', 'Position', [0 0 1 1]);
% Capture the frame without border
F = getframe(f);
writeVideo(vidfile, F.cdata);
% Close the figure to avoid excessive memory use
close(f);
end
close(vidfile); % Make sure to close the video file to finish writing
clear all; clc;

카테고리

Help CenterFile Exchange에서 Audio and Video Data에 대해 자세히 알아보기

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by