Selecting smaller grid from a grid to create a video

6 vues (au cours des 30 derniers jours)
Andrew
Andrew le 19 Sep 2025
Commenté : Mathieu NOE le 19 Sep 2025
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

Réponse acceptée

Mathieu NOE
Mathieu NOE le 19 Sep 2025
Modifié(e) : Mathieu NOE le 19 Sep 2025
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 commentaires
Andrew
Andrew le 19 Sep 2025
Déplacé(e) : Mathieu NOE le 19 Sep 2025
Thank you very much. I will have a go.
Mathieu NOE
Mathieu NOE le 19 Sep 2025
as always , my pleasure

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by