MATLAB:如何使用faceAlpha保存地理显示图? [英] MATLAB: how to save a geoshow figure with faceAlpha?

查看:486
本文介绍了MATLAB:如何使用faceAlpha保存地理显示图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Matlab R2014a中保存一个图形,以便在该图形上绘制数据。这是代码:

  [新加坡,R] = geotiffread(file); 
s = size(新加坡);
matrix = rand(s(1),s(2));
geoshow(新加坡(:,:,1:3),R)
保持
geoshow(矩阵,R,'DisplayType','texturemap','facealpha',。2) ;
xlim([103.605,104.04])
ylim([1.2,1.475])

这是一个可以完美工作的情节:



当我打印图形时

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

图像是完全白色的

解决方案

非常感谢您提供的图片链接!
我已经尝试过您的代码(适用于您提供的 Singapore.tif文件和适当的输出文件),并且可以在我的系统上正常运行(Matlab 2013b,Linux 64位)。这是输出文件:






另外,也不要无视我的同事以及他/她对他/她的回答所做的努力,但是我会注意到,您收到的其他回答基本上是完全错误的,您应该收回标记为接受的不管他/她的主张和警告,关于撤回带标记的答案有多么粗鲁。 mapshow 特别用于使用 MapCellsReference 格式的图像: boston.tif 您的图像使用 GeographicCellsReference 格式。 mapshow 用于前者, geoshow 用于后者; geoshow 对于 boston.tif 失败,就像 mapshow Singapore.tif 中失败。显然,您的图片是 Geo变体,因为您的 geoshow(Singapore(:,:,1:3),R)行有效而不会引发错误。因此,使用 mapshow 的建议不是您问题的正确答案,并且具有误导性。更不用说这与您关于 print 命令为什么不能从其图形句柄产生预期结果的实际问题完全无关,从理论上讲,这应该与如何处理无关该图最初是制作的。对于从中撤回您的已接受标记,我不会有任何疑虑。尤其是因为该站点可以为许多其他观众提供参考;仅仅因为您被欺负而接受了,将用户引导到错误答案是没有意义的。


I am trying to save a figure in Matlab R2014a in which I want to plot data over an Image. This is the code:

[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])

This one is the plot that works perfectly:

While when I am printing the figure

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

the image is completely white

解决方案

Many thanks for the image link! I have tried your code (adapted for the `Singapore.tif' file you provided and an appropriate output file) and it works as expected on my system (Matlab 2013b, Linux 64-bit). This is the output file:

So I'm sorry to say that there's nothing wrong with your code, and it's probably something to do with the 'png' driver on windows or your particular installation. Have you tried printing to a different driver? (e.g. jpg or pdf?). Does it actually work if you do this from the figure's graphical menu, i.e. File->Save As; or via File->Export Setup->Export with appropriate properties?


The only other thing I can think of which may be confusing your system is the attempt to print a uint8 rgb image (your Singapore image) and an overlayed double grayscale image. You can see if converting your Singapore image to double solves this by changing:

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

to

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


Might also be worth trying to plot the data manually and see if printing that works, e.g.:

[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');


As a bonus, here's how you might perform the same thing in Octave, in case you're interested (I find printed plots from Octave look much nicer, especially in terms of fonts!):

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');


Also, no disrespect to my colleague and the effort he / she put into his / her answer, but I will note that the other answer you received is essentially completely wrong and you should retract your marked accepted regardless of his / her claim and warnings about how rude it is to retract a marked answer. mapshow is specifically used for images using a MapCellsReference format: the boston.tif image is one such image. Your image however uses a GeographicCellsReference format. mapshow is used for the former, geoshow is used for the latter; geoshow would have failed for boston.tif, in the same way mapshow fails for Singapore.tif. It should have been obvious your image is a "Geo" variant because your line geoshow(Singapore(:,:,1:3), R) worked without throwing an error. Therefore the suggestion to use mapshow is not the correct answer to your question, and is misleading. Not to mention it is completely irrelevant to your actual question about why the print command does not produce the expected result from its figure handle, which should in theory have nothing to do with how the figure was produced in the first place. I would have no qualms about retracting your "accepted" mark from it. Not least because this site functions as a reference for many other viewers; it does not make sense to direct users to the wrong answer just because you got bullied into accepting it.

这篇关于MATLAB:如何使用faceAlpha保存地理显示图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆