원본 텍스트 Data plotted using VideoWriter and data saved as avi are different.
1 次查看(过去 30 天)
显示 更早的评论
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/669868/image.png)
However, when I opened the file saved as an avi file or mp4 file, a white background appeared unlike in Matlab.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/669873/image.jpeg)
I want to erase the border.
What code should I use?
I don't know how.
Please help me.
0 个评论
回答(1 个)
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;
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Audio and Video Data 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!