how to increase getframe dimensions and quality ?

148 views (last 30 days)
hi.
I have a code that plots data and moving it.
and I used getframe to save the plots for making a movie later from it.
the problem is that the output movie comes with very low quality and dimensions of 700x525.
what I have to change in my script code to get HD Quality 1280x720?
by the way this is my code, and I will attach the function raafabdshm1 and the script so you can run it on your computer.
f=figure;plotLocation=axes(f);
hold(plotLocation,'on')
counter=0;
fixedAxisOfRotation=[0,0];
linkLength=5;
startingEndingAngularPositions=[0,pi];
periodicTime=3;
exponentialDecay=0.6;
pathStatus=true;
instantaneousAngularPosition=zeros(25,1);
instantaneousAngularVelocity=zeros(25,1);
instantaneousAngularAcceleration=zeros(25,1);
M = struct('cdata',cell(25,1),'colormap',cell(25,1));
for instantaneousTime=0:0.04:0.96
counter=counter+1;
[instantaneousAngularPosition(counter),...
instantaneousAngularVelocity(counter),...
instantaneousAngularAcceleration(counter)]=...
raafabdshm1(fixedAxisOfRotation,linkLength,...
startingEndingAngularPositions,periodicTime,exponentialDecay,...
pathStatus,instantaneousTime,plotLocation);
axis(plotLocation,[-20,20,-10,10])
pbaspect(plotLocation,[2,1,1])
M(counter)=getframe(f);
cla(plotLocation)
end
myVideo=VideoWriter('animationVideo');
myVideo.FrameRate=25;
open(myVideo)
writeVideo(myVideo,M)
close(myVideo)
close(f)

Answers (2)

darova
darova on 22 Apr 2020
Try this madness
clc,clear,cla
wobj = VideoWriter('test1.avi');
wobj.FrameRate = 10; % frames per second (video speed)
open(wobj); % open file
t = linspace(0,2*pi);
[x,y] = pol2cart(t,1); % simpe circle
plot(x,y)
axis equal
mkdir('test')
set(0,'defaultlinelinesmoothing')
for i = 1:1:length(x)-1
line(x(i:i+1),y(i:i+1),'linew',2) % add line
fname = ['test\test' num2str(i)]; % full name of image
print('-djpeg','-r200',fname) % save image with '-r200' resolution
I = imread([fname '.jpg']); % read saved image
frame = im2frame(I); % convert image to frame
writeVideo(wobj,frame); % save frame into video
end
close(wobj); % close file
  8 Comments
Adnan
Adnan on 1 Jun 2023
Edited: Adnan on 1 Jun 2023
Changing the for loop to the following also works:
for i = 1:1:length(x)-1
line(x(i:i+1),y(i:i+1),'linew',2) % add line
cdata = print('-RGBImage','-r600','-noui'); % increased dpi to 600 (beware)
frame = im2frame(cdata); % convert image to frame
writeVideo(wobj,frame); % save frame into video
end

Sign in to comment.


Image Analyst
Image Analyst on 22 Apr 2020
Edited: darova on 22 Apr 2020
Since getframe() essentially gets a screenshot bitmap of what's in your display adapter, the resolution is whatever it is when it's displayed on your scree. To get that as high as possible, you need to maximize your figure window and use 'tight' option if you use imshow:
hFig = figure; % Bring up new figure
imshow('board.tif','Border','tight') % The axes will fill up the entire figure as much as possible without changing aspect ratio.
hFig.WindowState = 'maximized'; % Maximize the figure to your whole screen.
thisFrame = getframe(); % This is as large as you can get.
  2 Comments
Osama Alkurdi
Osama Alkurdi on 22 Apr 2020
I don't know how this will resolve my problem and how I would implement it in my code, are you shure you read my question well? can you explain more clearly please?

Sign in to comment.

Categories

Find more on Convert Image Type in Help Center and File Exchange

Products


Release

R2018a

Community Treasure Hunt

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

Start Hunting!