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")
})
})
}
我设法用光栅法绘制了一幅均衡图像。以下是一些技巧:
req()
,而不是使用if语句`if(is.null(文件路径))返回(null)
input$files
分配给变量,您可以调用input$files$datapath
。在这种情况下也不需要gsub()
李>
我设法用光栅法绘制了一幅均衡图像。以下是一些技巧:
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)