如何抑制闪亮图像的抗锯齿?

问题描述 投票:0回答:1

我在

shiny
应用程序中有一个 image 图形,具有相对大量的网格单元。然而,平滑的颜色过渡在浏览器中显得扭曲。我怀疑这是一个抗锯齿伪影,并想知道如何在 R 中或使用 css 选项来防止它。

这是一个普通 R 语言的最小示例,看起来如预期顺利:

library(RColorBrewer)
mycol <- colorRampPalette(brewer.pal(11, 'Spectral'))

png("image.png", width=600, height=600)
x <- seq(-0.5, 0.5, length.out = 200)
r <- sqrt(outer(x^2, x^2, `+`))
image(z = cos(r^2) * exp(-r/6), col = mycol(100))
dev.off()

picture with smooth colors

以及相应的 shiny 演示,其中生成的图像显示了令人讨厌的网格伪影:

library(shiny)
library(RColorBrewer)

mycol <- colorRampPalette(brewer.pal(11, 'Spectral'))

ui <- fluidPage(
    plotOutput("imagePlot")
)

server <- function(input, output) {
    output$imagePlot <- renderPlot({
        x <- seq(-0.5, 0.5, length.out = 200)
        r <- sqrt(outer(x^2, x^2, `+`))
        image(z = cos(r^2) * exp(-r/6), col = mycol(100))
    })
}

shinyApp(ui = ui, server = server)

image with distorted colors

css r image shiny antialiasing
1个回答
1
投票

参数非常好

useRaster = TRUE
:

server <- function(input, output) {
  output$imagePlot <- renderPlot({
    x <- seq(-0.5, 0.5, length.out = 200)
    r <- sqrt(outer(x^2, x^2, `+`))
    image(z = cos(r^2) * exp(-r/6), col = mycol(100), useRaster = TRUE)
  })
}

不幸的是,我无法添加生成的图像,这不起作用。

© www.soinside.com 2019 - 2024. All rights reserved.