how to increase getframe dimensions and quality ?

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)

Réponses (2)

darova
darova le 22 Avr 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 commentaires

I have to use getframe
You can resize the window then
set(gcf,'position',[10 10 1200 700])
when I resize it and implement the resizing value in the getframe function like this getframe(f,[10,10,1200,700]), it gives me an error
The specified rectangle is not fully contained within the figure. MATLAB no longer supports this capability.
darova
darova le 22 Avr 2020
Resire window using set function, not getframe
Osama Alkurdi
Osama Alkurdi le 22 Avr 2020
Modifié(e) : Osama Alkurdi le 22 Avr 2020
I resized it using the set function but, getframe still take poor quality snaps
the video still out with poor quality
darova
darova le 22 Avr 2020
Im sorry, i did my best. Is there something i can you help you with?
@darova
thank you :)
Adnan
Adnan le 1 Juin 2023
Modifié(e) : Adnan le 1 Juin 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

Connectez-vous pour commenter.

Image Analyst
Image Analyst le 22 Avr 2020
Modifié(e) : darova le 22 Avr 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 commentaires

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?
darova
darova le 22 Avr 2020
Osama Al-Kurdi carefully

Connectez-vous pour commenter.

Produits

Version

R2018a

Modifié(e) :

le 1 Juin 2023

Community Treasure Hunt

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

Start Hunting!

Translated by