MATLAB:如何使用 faceAlpha 保存 geoshow 图?

MATLAB: how to save a geoshow figure with faceAlpha?

我正在尝试在 Matlab R2014a 中保存一个图形,我想在其中绘制图像上的数据。这是代码:

[Singapore, R] = geotiffread(file);
s = size(Singapore);
matrix = rand(s(1),s(2));
geoshow(Singapore(:,:,1:3), R)
hold on
geoshow(matrix, R, 'DisplayType', 'texturemap','facealpha',.2);
xlim([103.605,104.04])
ylim([1.2,1.475])

这是完美的情节:

而我正在打印图

print(gcf, '-dpng',     fullfile(FileF, 'test.png')) 

图像全白

根据 mathworks 的建议,使用 mapshow 应该可以解决您的问题。以下对我有用:

[boston, R] = geotiffread('boston.tif');
figure
mapshow(boston, R);
axis image off
S = size(boston);
matrix=rand(S(1),S(2));
hold on
mapshow(matrix, R,'DisplayType','texturemap','facealpha',0.2);
print(gcf, '-dpng','test.png') ;

非常感谢图片 link! 我已经尝试了您的代码(适用于您提供的“Singapore.tif”文件和适当的输出文件)并且它在我的系统(Matlab 2013b,Linux 64 位)上按预期工作。这是输出文件:

很抱歉,您的代码没有任何问题,这可能与 windows 上的 'png' 驱动程序或您的特定安装有关。您是否尝试过打印到不同的驱动程序? (例如 jpg 或 pdf?)。如果您从图形的图形菜单中执行此操作,它是否真的有效,即 File->Save As;或通过具有适当属性的 File->Export Setup->Export


我能想到的唯一可能使您的系统感到困惑的另一件事是尝试打印 uint8 rgb 图像(您的新加坡图像) 叠加的双灰度图像。您可以通过更改以下内容来查看是否将您的新加坡图像转换为双图像可以解决此问题:

geoshow(Singapore(:,:,1:3), R)

geoshow(mat2gray(Singapore(:,:,1:3)), R)


也可能值得尝试 手动绘制数据 并查看打印是否有效,例如:

[Singapore, R] = geotiffread('Singapore.tif');
SingaporeXYImage = cat(3, flipud(Singapore(:,:,1)), ...
                          flipud(Singapore(:,:,2)), ...
                          flipud(Singapore(:,:,3)));
s = size(Singapore);
matrix3D = repmat( rand(s(1),s(2)), [1,1,3]);
imagesc(R.LongitudeLimits, R.LatitudeLimits, mat2gray(SingaporeXYImage));
hold on;
imagesc(R.LongitudeLimits, R.LatitudeLimits, matrix3D, 'alphadata', .2);
hold off;
axis xy equal tight;
xlim([103.605,104.04])
ylim([1.2,1.475])
print(gcf, '-dpng', 'test.png');


作为奖励,如果您有兴趣,这里是您可以如何在 Octave 中执行相同的操作(我发现 Octave 的打印图看起来更好,尤其是在字体方面!):

pkg load mapping;
pkg load image;
[SingaporeStruct, R] = rasterread('Singapore.tif');
SingaporeImage = cat(3, SingaporeStruct(1:3).data); % note this is a matrix of 
                                                    % "doubles" in range [0,255]
SingaporeImage = mat2gray(SingaporeImage); % Convert to appropriate [0,1] range 
                                           % for "doubles" rgb images!
s = size (SingaporeImage);
matrix3D = repmat (rand (s(1), s(2)), [1, 1, 3]);
imagesc (R.bbox(:,1), R.bbox(:,2), ...
         SingaporeImage .* 0.8 + matrix3D .* 0.2); % manually create
                                                   % transparency effect
axis xy equal tight
xlim([103.605,104.04])
ylim([1.2,1.475])
print (gcf, '-dpng', 'test.png');


另外,不要不尊重我的同事和他/她为他/她的回答所付出的努力,但我会注意到你收到的另一个答案基本上是完全错误的,你应该收回你的marked accepted,不管他/她的主张如何并警告撤回标记的答案是多么粗鲁。 mapshow 专门用于使用 MapCellsReference 格式的图像:boston.tif 图像就是这样一种图像。 您的 图片使用的是 GeographicCellsReference 格式。 mapshow用于前者,geoshow用于后者; geoshow 会因 boston.tif 而失败,就像 mapshow 会因 Singapore.tif 而失败一样。很明显,您的图像是 "Geo" 变体,因为您的行 geoshow(Singapore(:,:,1:3), R) 没有抛出错误。因此,使用 mapshow 的建议不是您问题的正确答案,并且具有误导性。更不用说它与您关于为什么 print 命令不从其图形句柄产生预期结果的实际问题完全无关,理论上这应该与图形最初的产生方式无关。我会毫不犹豫地收回你的 "accepted" 标记。尤其是因为该站点可以作为许多其他观众的参考;仅仅因为你被欺负而接受了它就将用户引导到错误的答案是没有意义的。