Skip to content

Instantly share code, notes, and snippets.

{
"tcount": "123,456",
"datime": "July 31st 2016"
}
@brooksandrew
brooksandrew / makeSquare.scala
Created April 12, 2016 19:26
Square rectangular images and center as much as possible using ImageIO and imgscalr in Scala. Save output as new jpg.
import org.imgscalr._
import java.io.File
import javax.imageio.ImageIO
object makeSqaure extends App {
def makeSquare(img: java.awt.image.BufferedImage): java.awt.image.BufferedImage = {
val w = img.getWidth
val h = img.getHeight
val dim = List(w, h).min
@brooksandrew
brooksandrew / resize.scala
Last active April 12, 2016 19:31
Re-size images using ImageIO and imgscalr in Scala and save output as a new jpgs
import org.imgscalr._
import java.io.File
import javax.imageio.ImageIO
object resize extends App {
def resizeImg(img: java.awt.image.BufferedImage, width: Int, height: Int) = {
Scalr.resize(img, Scalr.Method.BALANCED, width, height)
}
@brooksandrew
brooksandrew / makeGray.scala
Created April 12, 2016 16:52
Example of color to grayscale conversion with ImageIO in Scala.
import java.io.File
import javax.imageio.ImageIO
import java.awt.Color
object makegray extends App {
def pixels2gray(red: Int, green: Int, blue: Int): Int = (red + green + blue) / 3
def makeGray(img: java.awt.image.BufferedImage): java.awt.image.BufferedImage = {
val w = img.getWidth
@brooksandrew
brooksandrew / shiny_arules.R
Last active May 19, 2022 08:14
Launches a Shiny App that provides an interactive interface to the arules and arulesViz package which train and visualize association rules
#' @title Assocation Rules Visualization Shiny App
#' @description Launches a Shiny App that provides an interactive interface to the visualizations of the \code{arulesViz} package.
#' The app allows users to mine rules based on all or just subsets of features, sort by criteria (lift, support, confidence) and visualize
#' using network graph, grouped bubble and scatter plots. \cr
#' Users filter rules to target only those with a certain variable on the RHS or LHS of the rule.
#' Rule mining is computed using the \link{apriori} algorithm from \code{arules}.
#'
#' @param dataset data.frame, this is the dataset that association rules will be mined from. Each row is treated as a transaction. Seems to work
#' OK when a the S4 transactions class from \code{arules} is used, however this is not thoroughly tested.
#' @param bin logical, \code{TRUE} will automatically discretize/bin numerical data into categorical features that can be used for association analysis.