[Rd] png(type='cairo'): point symbols without boarders are not anti-aliased?
Simon Urbanek
simon.urbanek at r-project.org
Tue Oct 22 16:09:05 CEST 2013
On Oct 21, 2013, at 9:07 PM, Yihui Xie wrote:
> Perhaps yes. Sorry I did not check the bug reports. Can someone
> elaborate on the "undesirable artefacts"? I made two heatmaps using
> png() and CairoPNG(), respectively. I can see the difference, but it
> is not very clear to me what the artefacts are, or what the facts
> should be.
>
The Cairo package does "smart" anti-aliasing - it aligns lines that are perpendicular to the axes such that they centered at pixels. That avoids the anti-aliasing effects that Brian was talking about for the heatmap example. This enables Cairo to have full anti-aliasing support and still render heatmaps without artifacts.
However, there is no way around the anti-aliasing artifacts if you use arbitrary polygons without borders. For example:
library(deldir)
plot(c(-1,1),c(-1,1),ty='n')
for(p in tile.list(deldir(rnorm(200),rnorm(200)))) polygon(p$x,p$y,col=heat.colors(15)[runif(1,1,15)], border=NA)
That said, in our experience the Cairo approach works very well in practice.
Cheers,
Simon
> png(): http://i.imgur.com/lKrFG9i.png
> CairoPNG(): http://i.imgur.com/Dv0rsKK.png
>
> f = function(dev, ...) {
> dev(...)
> x = y <- seq(-4*pi, 4*pi, len = 27)
> r = sqrt(outer(x^2, y^2, "+"))
> z = cos(r^2)*exp(-r/6)
> image(z, main = deparse(substitute(dev)))
> dev.off()
> }
> f(grDevices::png, 'png-base.png', type = 'cairo')
> f(Cairo::CairoPNG, 'png-Cairo.png')
>
> Thanks!
>
> Regards,
> Yihui
> --
> Yihui Xie <xieyihui at gmail.com>
> Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
>
> On Mon, Oct 21, 2013 at 5:28 PM, Paul Murrell <paul at stat.auckland.ac.nz> wrote:
>> Hi
>>
>> Is this the same as "Bug 15462" ?
>> https://bugs.r-project.org/bugzilla3/show_bug.cgi?id=15462
>>
>> Paul
>>
>>
>> On 10/22/13 10:43, Yihui Xie wrote:
>>>
>>> Hi,
>>>
>>> It seems that anti-aliasing in png(type = 'cairo') is not well
>>> supported for the point symbols without boarders, e.g. pch = 16. The
>>> Cairo package works well, though. You can compare png() with
>>> CairoPNG():
>>>
>>> png(): http://i.imgur.com/8niB3jX.png
>>> CairoPNG(): http://i.imgur.com/FZBJOxm.png
>>>
>>> f = function(dev, ..., main = '') {
>>> dev(...)
>>> plot(c(1, 2, 1, 2), c(1, 1, 2, 2), pch=c(16, 19), cex=c(2, 2, 15, 15),
>>> xlim=c(0.5, 2.5), ylim=c(0.5, 3), main = deparse(substitute(dev)))
>>> dev.off()
>>> }
>>> f(grDevices::png, 'png-base.png', type = 'cairo')
>>> f(Cairo::CairoPNG, 'png-Cairo.png')
>>>
>>> If I remove the border for pch=19 (i.e. lwd=0), the point shows rough
>>> edges as well.
>>>
>>> I'm not sure if that is expected, or it is due to my misconfiguration
>>> somewhere. I installed R via `apt-get install r-base-dev` under Ubuntu
>>> using the CRAN repository.
>>>
>>>> sessionInfo()
>>>
>>> R version 3.0.2 (2013-09-25)
>>> Platform: x86_64-pc-linux-gnu (64-bit)
>>>
>>> locale:
>>> [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
>>> LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
>>> [5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=en_US.UTF-8
>>> LC_PAPER=en_US.UTF-8 LC_NAME=C
>>> [9] LC_ADDRESS=C LC_TELEPHONE=C
>>> LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
>>>
>>> attached base packages:
>>> [1] stats graphics grDevices utils datasets methods base
>>>
>>> loaded via a namespace (and not attached):
>>> [1] Cairo_1.5-2 tools_3.0.2
>>>
>>>> capabilities()
>>>
>>> jpeg png tiff tcltk X11 aqua http/ftp sockets
>>> TRUE TRUE TRUE TRUE TRUE FALSE TRUE TRUE
>>> libxml fifo cledit iconv NLS profmem cairo
>>> TRUE TRUE TRUE TRUE TRUE TRUE TRUE
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>
More information about the R-devel
mailing list