代码之家  ›  专栏  ›  技术社区  ›  tpetzoldt

如何在有光泽的情况下抑制图像的抗锯齿?

  •  0
  • tpetzoldt  · 技术社区  · 1 年前

    我有一个 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

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

    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

    0 回复  |  直到 1 年前
        1
  •  0
  •   Stéphane Laurent    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)
      })
    }
    

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