Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/powerbi/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R服务器内的图像处理操作。R_R_Image Processing_Shiny - Fatal编程技术网

R服务器内的图像处理操作。R

R服务器内的图像处理操作。R,r,image-processing,shiny,R,Image Processing,Shiny,我目前正在使用R开发图像处理应用程序,它使用文件上载上传图像,然后我需要读取图像来执行图像处理操作服务器.R文件如下所示 library(shiny) library(EBImage) library(imager) library(jpeg) function(input, output) { observe({ file_path <- input$files if (is.null(file_path)) return(NULL)

我目前正在使用
R
开发图像处理应用程序,它使用文件上载上传图像,然后我需要读取图像来执行图像处理操作<代码>服务器.R文件如下所示

library(shiny)
library(EBImage)  
library(imager)
library(jpeg)
function(input, output) {

  observe({
      file_path <- input$files
      if (is.null(file_path))
        return(NULL)
      file_path$datapath <- gsub("\\\\", "/", file_path$datapath)      

      img <- readImage(file_path$datapath)
      equalized <- equalize(img,range = c(0, 1), levels = 256)

      output$text <- renderText({
        file_path$datapath          
      })
      output$img <- renderImage({
        list(src = file_path$datapath,
             contentType = "image/jpg",
             width = "50%",
             height = "auto",
             alt = "This is alternate text")
    })

  })  

}

我设法用光栅法绘制了一幅均衡图像。以下是一些技巧:

  • 你把所有的东西都放在一个观察者里面,这是一个非常糟糕的主意,所以我把它去掉了

  • 检查文件是否上载、UI是否呈现等时,请使用
    req()
    ,而不是使用if语句`

  • if(is.null(文件路径))返回(null)

  • 无需将
    input$files
    分配给变量,您可以调用
    input$files$datapath
    。在这种情况下也不需要
    gsub()

    我设法用光栅法绘制了一幅均衡图像。以下是一些技巧:

  • 你把所有的东西都放在一个观察者里面,这是一个非常糟糕的主意,所以我把它去掉了

  • 检查文件是否上载、UI是否呈现等时,请使用
    req()
    ,而不是使用if语句`

  • if(is.null(文件路径))返回(null)

  • 无需将
    input$files
    分配给变量,您可以调用
    input$files$datapath
    。在这种情况下也不需要
    gsub()

    使用EBImage,我们可以将图像加载到Rshiny中,并将其用于进一步处理。下面的代码允许用户上传图像,然后在闪亮的屏幕背面显示相同的图像

    library(shiny)
    library(EBImage)  
    upload_image <- list()
    
    ui <- fluidPage(
      fileInput("file1", "Upload an Image"),
      plotOutput("img")
    )
    
    server <- function(input, output) {
      output$img <- renderPlot({ 
        req(input$file1)
        upload_image[[1]] <- readImage(input$file1$datapath)
        plot(upload_image[[1]])
       })
    }
    
    
    shinyApp(ui , server)
    
    库(闪亮)
    图书馆(电子图像)
    
    上传图片使用EBImage,我们可以将图片加载到Rshiny中,并使用它进行进一步处理。下面的代码允许用户上传图像,然后在闪亮的屏幕背面显示相同的图像

    library(shiny)
    library(EBImage)  
    upload_image <- list()
    
    ui <- fluidPage(
      fileInput("file1", "Upload an Image"),
      plotOutput("img")
    )
    
    server <- function(input, output) {
      output$img <- renderPlot({ 
        req(input$file1)
        upload_image[[1]] <- readImage(input$file1$datapath)
        plot(upload_image[[1]])
       })
    }
    
    
    shinyApp(ui , server)
    
    库(闪亮)
    图书馆(电子图像)
    
    上传图像检查
    读取图像
    行之前的
    文件路径$datapath
    值。与您的问题无关,但在
    观察
    中创建输出有点奇怪检查
    文件路径$datapath
    行之前的值。与您的问题无关,但在
    读取图像
    行中创建输出
    观察
    有点奇怪
    library(shiny)
    library(EBImage)  
    library(imager)
    library(jpeg)
    
    ui <- fluidPage(
      fileInput("files", "Upload a file"),
      plotOutput("img"),
      textOutput("txt")
    )
    
    server <- function(input, output) {
      output$img <- renderPlot({ 
        req(input$files)
        st <- strsplit(input$files$name, split = "[.]")[[1]]
        extension <- st[length(st)]
        display(equalize(readImage(input$files$datapath, type = extension), range = c(0, 1), levels = 256), method = "raster")
      })
      output$txt <- renderText({
        input$files$datapath
      })
    }
    
    shinyApp(ui, server)
    
    library(shiny)
    library(EBImage)  
    upload_image <- list()
    
    ui <- fluidPage(
      fileInput("file1", "Upload an Image"),
      plotOutput("img")
    )
    
    server <- function(input, output) {
      output$img <- renderPlot({ 
        req(input$file1)
        upload_image[[1]] <- readImage(input$file1$datapath)
        plot(upload_image[[1]])
       })
    }
    
    
    shinyApp(ui , server)