Save image in specific resolution in Matlab

后端 未结 2 1730
温柔的废话
温柔的废话 2020-12-17 05:31

I\'m trying for hours to simply output a certain plot in a specific resolution (320x240).

  xmax = 320; ymax = 240;
  xmin = 0; ymin = 0;
  figure;
  set(gcf         


        
2条回答
  •  执笔经年
    2020-12-17 06:13

    Possible solution is converting figure to image, and use imresize.

    Fixing the figure position to match 320x240 resolution is possible, but using imresize is simpler (I think).

    The following code sample, convert figure to image, and use imrezie to set resolution to 320x240:

    figure;
    % xmax = 320; ymax = 240;
    % xmin = 0; ymin = 0;  
    % set(gcf,'position',[1060 860 320 240]);
    % axis([xmin,xmax,ymin,ymax]);
    
    plot(sin(-pi:0.01:pi)); %Example figure
    I = frame2im(getframe(gcf)); %Convert plot to image (true color RGB matrix).
    J = imresize(I, [240, 320], 'bicubic'); %Resize image to resolution 320x240
    imwrite(J, 'J.jpg'); %Save image to file
    

提交回复
热议问题