我在 Win 10 下使用便携式 Octave 5.1.0。
我的意思是写一个具有透明背景的 png 绘图。
免责声明:
这个问题与下面链接的两个问题类似。
我选择了提出当前不同的问题 https://meta.stackoverflow.com/questions/402242/dr-strangedupe-ask-a-question-with-the-same-objective-but-different-text-body因为我正在添加更多相关信息(出于同样的原因,下面的问题#2 并不是问题#1 的重复)。
这是我发现的:
-
print(gcf,'-dpngalpha', 'myplot.png');
,建议在在具有透明背景的 Octave 中保存绘图 https://stackoverflow.com/questions/12438777/saving-a-plot-in-octave-with-transparent-background, 不适合我 https://stackoverflow.com/questions/12438777/saving-a-plot-in-octave-with-transparent-background#comment113980369_23824542。
值得注意的是我没有找到有关此选项的文档.
-
这个答案 https://stackoverflow.com/a/58932458/2707864我有几个问题:1)由于某些未知的原因convert
什么也没做。 2)需要外部封装,比较麻烦。例如,我不能简单地将我的 Octave 代码发送给其他人以供他使用。
-
Option svgconvert
是唯一的官方文档 https://octave.org/doc/v5.2.0/Printing-and-Saving-Plots.html我发现。
但它不适用于 png,例如
-
imwrite https://octave.org/doc/v4.2.1/Loading-and-Saving-Images.html似乎有能力以透明方式书写,但我找不到一种方法将绘图转换为适合的图像imwrite
。
(也可以看看Matlab 文档 https://www.mathworks.com/help/matlab/ref/imwrite.html)。
也许这是一条可能的路线......
Octave 有可用的选项吗?
Related:
-
在具有透明背景的 Octave 中保存绘图 https://stackoverflow.com/questions/12438777/saving-a-plot-in-octave-with-transparent-background
-
将绘图打印/保存为 png 文件,并在 Octave 中出现 alpha 通道问题 https://stackoverflow.com/questions/58927098/printing-saving-a-plot-as-a-png-file-with-an-alpha-channel-issue-in-octave
-
http://mlab.no/blog/2014/06/image-transparency-overlay-with-gnu-octave-using-ycbcr/ http://mlab.no/blog/2014/06/image-transparency-overlay-with-gnu-octave-using-ycbcr/
The imwrite
选项似乎有效。首先创建图像文件img_fname
,然后为其创建一个 alpha 层。
知道是否可以避免中间非透明文件将会很有趣。
EDIT:
我设法直接从我的绘图创建图像,而不需要中间文件。
x = -10:0.1:10;
plot (x, sin (x));
# Print figure directly to image instead of file
im = print(gcf, '-RGBImage');
tcolor = [255 255 255];
alpha(:,:) = 255 * ( 1 - (im(:,:,1) == tcolor(1)) .* (im(:,:,2) == tcolor(2)) .* (im(:,:,3) == tcolor(3)) );
imwrite(im, 'temp.png', 'Alpha', alpha);
Notes:
-
通过一些简单的代数,我们可以为任意数量的颜色添加透明度,并为每种颜色添加任意不透明度级别。
此外,我们可以将其移至一个函数中。
-
的乘法im
and tcolor
也可能被矢量化。
Related:
https://www.mathworks.com/matlabcentral/answers/57664-how-to-add-alpha-channel-to-the-image-and-convert-that-image-into-png-format https://www.mathworks.com/matlabcentral/answers/57664-how-to-add-alpha-channel-to-the-image-and-convert-that-image-into-png-format
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)