Title: | Tools for Working with Image Pixels |
---|---|
Description: | Provides tools to show and draw image pixels using 'HTML' widgets and 'Shiny' applications. It can be used to visualize the 'MNIST' dataset for handwritten digit recognition or to create new image recognition datasets. |
Authors: | Daniel Falbel [aut, cre], Javier Luraschi [aut], RStudio [cph] |
Maintainer: | Daniel Falbel <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.1.1 |
Built: | 2024-11-07 03:11:22 UTC |
Source: | https://github.com/javierluraschi/pixels |
This package provides tools to show and draw image pixels using 'HTML' widgets and 'Shiny' applications.
This package can be used to: Visualize the 'MNIST' dataset for handwritten digit recognition, create simple test cases for image classification, or to create new datasets by building a 'Shiny' applicaiton that enables many users to capture images for supervised learning.
Maintainer: Javier Luraschi [email protected]
Other contributors:
RStudio [copyright holder]
Useful links:
Report bugs at https://github.com/javierluraschi/pixels/issues
Creates an ShinyGadget to retrieve pixels.
get_pixels(pixels = NULL, grid = c(28, 28), size = c(250, 250), brush = matrix(c(0, 0.5, 0.8, 0.5, 0, 0.5, 1, 1, 1, 0.5, 0.8, 1, 1, 1, 0.8, 0.5, 1, 1, 1, 0.5, 0, 0.5, 0.8, 0.5, 0), 5, 5), params = list(fill = list(color = "#555555"), grid = list(color = "#EEEEEE")))
get_pixels(pixels = NULL, grid = c(28, 28), size = c(250, 250), brush = matrix(c(0, 0.5, 0.8, 0.5, 0, 0.5, 1, 1, 1, 0.5, 0.8, 1, 1, 1, 0.8, 0.5, 1, 1, 1, 0.5, 0, 0.5, 0.8, 0.5, 0), 5, 5), params = list(fill = list(color = "#555555"), grid = list(color = "#EEEEEE")))
pixels |
The pixels to render as a 1-dimensional vector, row-first order expected. |
grid |
The grid dimensions specified as a vector. |
size |
The canvas dimensions specified as a vector. |
brush |
The brush specified as a matrix. |
params |
A set of parameters to customize the visual appearance. #' @examples library(pixels) if (interactive()) get_pixels() |
Provides a Shiny Widget for Output.
shiny_pixels_output(outputId, width = "100%", height = "400px")
shiny_pixels_output(outputId, width = "100%", height = "400px")
outputId |
The identifier for this widget. |
width |
The width for this widget. |
height |
The height for this widget. |
library(shiny) ui <- fluidPage( tags$head( tags$style(HTML(" #pixels { height: 270px !important; margin-top: 10px; } ")) ), titlePanel("Digit Capture Application"), textOutput("prompt"), shiny_pixels_output("pixels"), actionButton("captureDigit", "Capture") ) server <- function(input, output) { output$pixels <- shiny_render_pixels( show_pixels() ) digit <- reactiveVal(floor(runif(1, 1, 10))) output$prompt <- renderText(paste0("Please draw number ", digit(), ":")) observeEvent(input$captureDigit, { digit_path <- file.path("digits", digit()) if (!dir.exists(digit_path)) dir.create(digit_path, recursive = TRUE) saveRDS(input$pixels, paste0(digit_path, "/", as.numeric(Sys.time()), ".rds")) digit(floor(runif(1, 1, 10))) output$pixels <- shiny_render_pixels( show_pixels() ) }) } if (interactive()) { shinyApp(ui = ui, server = server) }
library(shiny) ui <- fluidPage( tags$head( tags$style(HTML(" #pixels { height: 270px !important; margin-top: 10px; } ")) ), titlePanel("Digit Capture Application"), textOutput("prompt"), shiny_pixels_output("pixels"), actionButton("captureDigit", "Capture") ) server <- function(input, output) { output$pixels <- shiny_render_pixels( show_pixels() ) digit <- reactiveVal(floor(runif(1, 1, 10))) output$prompt <- renderText(paste0("Please draw number ", digit(), ":")) observeEvent(input$captureDigit, { digit_path <- file.path("digits", digit()) if (!dir.exists(digit_path)) dir.create(digit_path, recursive = TRUE) saveRDS(input$pixels, paste0(digit_path, "/", as.numeric(Sys.time()), ".rds")) digit(floor(runif(1, 1, 10))) output$pixels <- shiny_render_pixels( show_pixels() ) }) } if (interactive()) { shinyApp(ui = ui, server = server) }
Renders the Shiny Widget.
shiny_render_pixels(expr, env = parent.frame(), quoted = FALSE)
shiny_render_pixels(expr, env = parent.frame(), quoted = FALSE)
expr |
The |
env |
The |
quoted |
The |
[shiny_pixels_output()] for an example of using this function within a 'Shiny' application.
Creates an HTMLWidget to show pixels.
show_pixels(pixels = NULL, grid = c(28, 28), size = c(250, 250), brush = matrix(c(0, 0.5, 0.8, 0.5, 0, 0.5, 1, 1, 1, 0.5, 0.8, 1, 1, 1, 0.8, 0.5, 1, 1, 1, 0.5, 0, 0.5, 0.8, 0.5, 0), 5, 5), params = list(fill = list(color = "#555555"), grid = list(color = "#EEEEEE")))
show_pixels(pixels = NULL, grid = c(28, 28), size = c(250, 250), brush = matrix(c(0, 0.5, 0.8, 0.5, 0, 0.5, 1, 1, 1, 0.5, 0.8, 1, 1, 1, 0.8, 0.5, 1, 1, 1, 0.5, 0, 0.5, 0.8, 0.5, 0), 5, 5), params = list(fill = list(color = "#555555"), grid = list(color = "#EEEEEE")))
pixels |
The pixels to render as a 1-dimensional vector, row-first order expected. |
grid |
The grid dimensions specified as a |
size |
The canvas dimensions specified as a |
brush |
The brush specified as a matrix. |
params |
A set of parameters to customize the visual appearance. |
library(pixels) show_pixels( round(runif(400, 0, 1)), grid = c(40, 10), size = c(800, 200), params = list(fill = list(color = "#FF3388")) )
library(pixels) show_pixels( round(runif(400, 0, 1)), grid = c(40, 10), size = c(800, 200), params = list(fill = list(color = "#FF3388")) )