Selecting smaller grid from a grid to create a video

조회 수: 6 (최근 30일)
Andrew
Andrew 2025년 9월 19일
댓글: Mathieu NOE 2025년 9월 19일
Hi,
I would like to be able to pick different sections of a X by X grid to create a video.
My attempts are useless.
I generated some code using Gemini and I got the borders I needed.
I use the borders to dampen out a wave. I create a SPICE netlist and
I need some code that allows me to ignore the border area when creating a video (the no damping part)
from the SPICE data output file. For example if I have a 150 by 150 grid, I would like to use only a 100 by 100 grid
for the video.
Thanks

채택된 답변

Mathieu NOE
Mathieu NOE 2025년 9월 19일
편집: Mathieu NOE 2025년 9월 19일
hello Andrew
see this code demo to read the video , extratct each frame then crop the unwanted borders and save back to a video output file
% Create a VideoReader object for the (input) MP4 file
videoFile = '09-09-25 Exp100100.mp4 ';
videoObj = VideoReader(videoFile);
% Display video properties
disp(videoObj);
% Create a VideoWriter object for the output video file and open the object for writing.
v = VideoWriter("output_video.mp4");
open(v)
% define grid size (output frame size)
mt = 100;
nt = 100;
% Read , display , crop and save frames
while hasFrame(videoObj)
frame = readFrame(videoObj); % Read the next frame
% % display (optionnal)
% imshow(frame); % Display the frame
% pause(1/videoObj.FrameRate); % Pause to match the video frame rate
% crop frame
[m,n,p] = size(frame);
delta_m = floor((m-mt)/2);
delta_n = floor((n-nt)/2);
frame_out = frame(delta_m:m-delta_m-1,delta_n:n-delta_n-1,:);
% write video
writeVideo(v,frame_out);
end
% Close the VideoWriter object.
close(v)
  댓글 수: 2
Andrew
Andrew 2025년 9월 19일
이동: Mathieu NOE 2025년 9월 19일
Thank you very much. I will have a go.
Mathieu NOE
Mathieu NOE 2025년 9월 19일
as always , my pleasure

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by