png(type='cairo'): point symbols without boarders are not anti-aliased?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

png(type='cairo'): point symbols without boarders are not anti-aliased?

Yihui Xie-2
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


Regards,
Yihui
--
Yihui Xie <[hidden email]>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: png(type='cairo'): point symbols without boarders are not anti-aliased?

Yihui Xie-2
Sorry, typo in the subject: I mean "borders".

Regards,
Yihui
--
Yihui Xie <[hidden email]>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Mon, Oct 21, 2013 at 4:43 PM, Yihui Xie <[hidden email]> 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
>
>
> Regards,
> Yihui
> --
> Yihui Xie <[hidden email]>
> Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: png(type='cairo'): point symbols without boarders are not anti-aliased?

Paul Murrell-2
In reply to this post by Yihui Xie-2
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
>
>
> Regards,
> Yihui
> --
> Yihui Xie <[hidden email]>
> Web: http://yihui.name
> Department of Statistics, Iowa State University
> 2215 Snedecor Hall, Ames, IA
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: png(type='cairo'): point symbols without boarders are not anti-aliased?

Yihui Xie-2
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.

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 <[hidden email]>
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 <[hidden email]> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: png(type='cairo'): point symbols without boarders are not anti-aliased?

Simon Urbanek
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 <[hidden email]>
> 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 <[hidden email]> 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
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: png(type='cairo'): point symbols without boarders are not anti-aliased?

Yihui Xie-2
Thanks for the hints! I was originally wondering the difference
between grDevices::png(type='cairo') and Cairo::CairoPNG() for the
case pch=16, a solid point without border. Cairo does a nice job for
such point symbols, but png() renders them very poorly.

Regards,
Yihui
--
Yihui Xie <[hidden email]>
Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA


On Tue, Oct 22, 2013 at 9:09 AM, Simon Urbanek
<[hidden email]> wrote:

> 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

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel