【问题标题】:problematic Moire pattern in image produced with gnuplot pm3d and pdf output使用 gnuplot pm3d 和 pdf 输出生成的图像中有问题的莫尔条纹
【发布时间】:2013-09-20 23:58:49
【问题描述】:

我正在使用此处讨论的命令文件绘制数据: gnuplot contour line color: set style line and set linetype not working 我想提供不同的输出选项。 PNG 效果很好,wxt 终端也一样,但是,它们具有固定的分辨率,例如当我“放大”情节时,它会变得更粗糙。

如果我对终端使用 pdf 或 pdfcairo,则生成的文件具有莫尔条纹。可以通过在 pm3d 命令中使用增加的插值量来减少图像中观察到莫尔条纹的区域。径向数据集中有很多点,但角度数据集不多,所以我需要在那个“方向”上插值更多。不使用插值会导致非常粗糙的 pm3d 图像,所以我一直在尝试 0,20 到 20,20 甚至 20,40。不幸的是,即使是大量的插值也不能完全消除莫尔条纹,使文件大小变得巨大(例如 PNG 文件大约 250kB,但 pdf 文件超过 11MB),因此渲染速度非常慢。我试过用 Adob​​e Acrobat Reader 10.1.8 和 GSview 查看这些,结果是一样的。

我对使用 pdf 格式很感兴趣,因为它无处不在,可以放大而不会过度丢失细节(与 PNG 不同)。

下面是我在不同插值级别捕获的结果 pdf 输出中的模式的几个屏幕截图。第一张图片是 png 文件供参考,因为它没有显示莫尔条纹,文件大小为 250kB。

接下来,没有 pm3d 插值的 pdf 输出,72kB 文件大小:

接下来,使用set pm3d map interpolate 0,20的pdf输出,文件大小1861kB:

接下来,使用set pm3d map interpolate 10,20的pdf输出,文件大小5942kB:

最后,使用set pm3d map interpolate 20,20的pdf输出,文件大小11515kB:

为什么会为 pdf 输出生成这些 Moire 图案?是否存在这样的问题,这将使我仍然拥有可以放大而不会(很多)损失分辨率的矢量格式?

【问题讨论】:

  • 这里有一个更新:我在 GSview 中找到了一个名为“graphics alpha”的设置。这可以采用 1、2 或 4 位的值。在网上阅读后,似乎此设置在设置为 2 或 4 时启用抗锯齿。有趣的是,当我将其设置为 1 时,莫尔条纹消失了。但是根据我的阅读,将其设置为 1 是关闭抗锯齿,这应该是防止问题,而不是导致问题。
  • 可能与此有关,我发布了一个类似的问题:stackoverflow.com/questions/10431039/… 我的解决方法是调用一个 sed 脚本,该脚本略微增加了 postscript 文件中多边形的大小,使它们重叠,然后我转换转PDF

标签: image pdf gnuplot antialiasing interpolation


【解决方案1】:

这不应该是一个解决方案,而是一个解释和一个可能的,虽然丑陋的解决方法。

gnuplot邮件列表时不时会有关于这个问题的报告,但似乎与观众有关。它与gnuplot 创建曲面图的方式有关。这些被绘制为多边形,它们被缝合在一起。您显示的莫尔图案来自两个多边形之间的错误渲染。这取决于查看器、查看器设置和缩放系数。

显示该效果的最简单示例是以下 Postscript 文件:

%!PS-Adobe-2.0
50 50 moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto closepath 0 setgray fill
100 50 moveto 50 0 rlineto 0 50 rlineto -50 0 rlineto closepath 0 setgray fill

保存此文件,例如作为moire.ps 并查看它,或将其转换为ps2pdf 并查看它。使用 Acrobat reader 9.5.1 我看到以下内容:

Acrobat Reader 有一个设置Preferences -> Page Display -> Enhance thin lines 可以防止此问题,但会导致其他部分出现问题。

在我的系统 (Debian) 上,所有查看器都显示此模式,mupdf、firefox、ghostscript、pdftocairo、libpoppler` 等。

那么,该怎么办?对于我自己,我使用以下解决方法。我将splot 转换为高分辨率的png,稍后使用plot ... with rgbimage 重新读取该文件。然后你得到你的热图作为位图,其余的都是矢量的。在大多数情况下,这没有问题,因为无论如何您都有一些分辨率有限的测量数据,您可以对其进行插值。

基于问题gnuplot contour line color: set style line and set linetype not working,您可以通过以下方式实现它:

reset 

set lmargin at screen 0.05
set rmargin at screen 0.85
set bmargin at screen 0.1
set tmargin at screen 0.9

set pm3d map interpolate 20,20
unset key

set cntrparam bspline
set cntrparam points 10
set cntrparam levels increment -6,-6,-24
set contour surface

set linetype 1 lc rgb "blue" lw 2 
set linetype 2 lc rgb "blue"
set linetype 3 lc rgb "black"
set linetype 4 lc rgb "orange"
set linetype 5 lc rgb "yellow"

set palette rgb 33,13,10 #rainbow (blue-green-yellow-red)
set cbrange [-18:0]

unset border
unset xtics
unset ytics

set angles degree
r = 3.31
set xrange[-r:r]
set yrange[-r:r]
set colorbox user origin 0.9,0.1 size 0.03,0.8

##################### start changes ##############
set autoscale fix
RES_X = 2000
RES_Y = 2000

save('settings.tmp')
set lmargin at screen 0
set rmargin at screen 1
set bmargin at screen 0
set tmargin at screen 1
unset colorbox

set terminal pngcairo size RES_X, RES_Y
set output '3d-polar-inc.png'
splot 'new_test.dat' nocontour

unset output
load('settings.tmp')

# mapping of the coordinates for the png plotting later
X0 = GPVAL_X_MIN
Y0 = GPVAL_Y_MIN
DX = (GPVAL_X_MAX - GPVAL_X_MIN)/real(RES_X)
DY = (GPVAL_Y_MAX - GPVAL_Y_MIN)/real(RES_Y)
C0 = GPVAL_CB_MIN
DC = GPVAL_CB_MAX - GPVAL_CB_MIN
C(x) = (x/255.0) * DC + C0

# now plot the png 
#set terminal pdfcairo size 10cm,10cm
#set output '3d-polar.pdf'
set terminal postscript eps color level3 size 10cm,10cm solid
set output '3d-polar-eps.eps'

set multiplot

set cbrange[GPVAL_CB_MIN:GPVAL_CB_MAX]
plot '3d-polar-inc.png' binary filetype=png \
     origin=(X0, Y0) dx=DX dy=DY \
     using (C($1)):(C($2)):(C($3)) \
     with rgbimage, \
     NaN with image t '' # hack for getting the colorbox

# plot the contours
unset surface
unset pm3d
splot 'new_test.dat' w l

###################### end changes #################

# now plot the polar grid only
set style line 11 lc rgb 'black' lw 2 lt 0
set grid polar ls 11
set polar
set logscale r 10
set rrange[10:20000]
unset raxis
set rtics format '' scale 0
#set rtics axis scale 
set rtics (20,50,100,200,500,1000,2000,5000,10000,20000)
do for [i=-150:180:30] {
dum = r+0.15+0.05*int(abs(i/100))+0.05*int(abs(i/140))-0.05/abs(i+1)
set label i/30+6 at first dum*cos(i), first dum*sin(i) center sprintf('%d', i)
}
set label 20 at first 0, first -(log(20)/log(10)-1) center "20"
set label 100 at first 0, first -(log(100)/log(10)-1) center "100"
set label 200 at first 0, first -(log(200)/log(10)-1) center "200"
set label 1000 at first 0, first -(log(1000)/log(10)-1) center "1k"
set label 2000 at first 0, first -(log(2000)/log(10)-1) center "2k"
set label 10000 at first 0, first -(log(10000)/log(10)-1) center "10k"
set label 20000 at first 0, first -(log(20000)/log(10)-1) center "20k"
plot NaN w l
unset multiplot
unset output

pdfcairo 会生成 1.7 MB 的 pdf 文件,epslatex level3(此选项仅在 4.7 开发版中可用)会生成 1.5 MB eps 文件,可以使用 epstopdf 将其转换为 136 KB pdf 文件。

另请参阅我在 TeX.SX 上对 Big data surface plots: Call gnuplot from tikz to generate bitmap and include automatically? 的回答。

【讨论】:

  • 感谢您发布解决方法。这绝对是一个非常复杂的方法......我还没有时间回去尝试它。我正在尝试创建其他用户可以修改以满足他们特定需求的脚本,并且我希望它尽可能简单。
  • @Charlie 我知道,这个解决方案非常不方便,但是光栅化热图是绕过这个问题的唯一方法,独立于查看器及其设置。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-10-22
  • 2021-08-13
  • 1970-01-01
  • 1970-01-01
  • 2014-09-09
  • 1970-01-01
相关资源
最近更新 更多