【问题标题】:MATLAB Set image sizeMATLAB 设置图像大小
【发布时间】:2014-05-05 14:13:53
【问题描述】:

我有一个创建和捕获 jpg 文件的代码。但是,它往往会出现两种不同的图像尺寸。当我想将 jpg 文件制作成电影时,这会成为一个问题。我已经设置了PaperPosition 和其他一些东西,但它仍然有两种图像尺寸。图像大小的变化似乎是随机的,因为如果我运行两次代码,之前具有其中一种尺寸的图像现在可能具有另一种尺寸。

nFrames = 8797; % Number of frames. Number of days between 1/1/1990 and 1/31/2014
for k = 1:nFrames % 1/1/1990 to the number of days.
    % Map of conterminous US
    ax = figure(1);
    set(ax, 'visible', 'off', 'units','normalized','outerposition',[0 0 1 1]); %  Make window that shows up full sized, which makes saved figure clearer
    ax = usamap('conus');
    states = shaperead('usastatelo', 'UseGeoCoords', true,...
        'Selector',...
        {@(name) ~any(strcmp(name,{'Alaska','Hawaii'})), 'Name'});
    faceColors = makesymbolspec('Polygon',...
        {'INDEX', [1 numel(states)], 'FaceColor', 'none'}); % NOTE - colors are random
    geoshow(ax, states, 'DisplayType', 'polygon', ...
        'SymbolSpec', faceColors)
    framem off; gridm off; mlabel off; plabel off

    hold on

    % Plot data
    scatterm(ax,str2double(Lat_O3{k}), str2double(Lon_O3{k}), 40, str2double(data_O3{k})*1000, 'filled'); % Plot a dot at each Lat and Lon
    hold on

    % Colorbar
    caxis([10 90]);
    h = colorbar;
    ylabel(h,'ppb');

    % Title
    % date = datenum(2007, 04, 29) + k; % Convert t into serial numbers.
    title(['O3 MDA8 Concentration ', datestr(cell2mat(date_O3(k)), 'mmm dd yyyy')]); % Title changes every daytitle(str);

    % Capture the frame
    mov(k) = getframe(gcf); % Makes figure window pop up

    % Set size of image
    set(gcf,'Units','points')
    set(gcf,'PaperUnits','points')

    size = get(gcf,'Position');
    size = size(3:4);
    set(gcf,'PaperSize',size)

    set(gcf,'PaperPosition',[0,0,size(1),size(2)])

    % Save as jpg (just specify other format as necessary) - Must set 'facecolor' to 'none' or else color of states turn out black
    eval(['print -djpeg map_US_' datestr(cell2mat(date_O3(k)),'yyyy_mm_dd') '_O3_MDA8.jpg']);
    % saveas(gca, ['WI_' datestr(cell2mat(Date)) '_PM25.jpg']);
    clf

end

% Save as AVI file - Set 'facecolor' to 'white'. It looks better.
close(gcf)

如何设置图像大小(希望像我在set(ax, ...) 中尝试那样设置为全屏,这样当我保存 jpg 文件时,它们的大小都相同?

【问题讨论】:

  • 我已经使用subplot('position',[0 0 1 1]); 取得了一些成功,它基本上是“在整个窗口中”绘制的。此外 - 如果轴标签等的内容发生变化,大小可能会发生变化。您是否尝试在所有轴关闭的情况下进行绘图?
  • 你把subplot命令放在哪里了?我没有axes on 是吗?在哪里?
  • 我将subplot 放置在创建图形之后和创建绘图之前:figure; subplot('position',[0 0 1 1]); plot(X, Y); axes off;。我承认不熟悉地理绘图例程,因此这可能不适用于您的情况。没有图片或数据很难重现您的问题。

标签: image matlab plot image-size


【解决方案1】:

您可以简单地将图像大小调整为您想要的任何大小,因此您知道它将保持不变。

B = imresize(A, [numrows numcols])

如果您对此有其他特殊问题,请查看imresize 文档。

【讨论】:

  • 我不确定问题出在图像中数据点的数量上,还是出在屏幕上的显示方式上……
  • 我也不是,但是如果上面的代码实现了,它仍然会生成奇怪的图像大小,那么我们就知道不是这样。
  • 只是抛出一条线,看看有没有东西咬:)
  • 我认为 OP 正在使用scatterm,这是一种有趣的“地理散点图”。因此,我不确定A 在他的情况下会是什么。
  • @Floris True。但是可以做的是调整它输出的句柄的大小。也许像h = scatterm(..), set(h,'Position',[50,50,10,100])
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-25
  • 1970-01-01
  • 1970-01-01
  • 2020-08-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多