Skip to content

Instantly share code, notes, and snippets.

@peel
Created December 12, 2014 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peel/41101906aacb8612d967 to your computer and use it in GitHub Desktop.
Save peel/41101906aacb8612d967 to your computer and use it in GitHub Desktop.
image parser
...
scalaVersion := "2.11.4"
libraryDependencies ++= Seq(
...
"com.sksamuel.scrimage" %% "scrimage-core" % "1.4.1",
"com.sksamuel.scrimage" %% "scrimage-canvas" % "1.4.1",
"com.sksamuel.scrimage" %% "scrimage-filters" % "1.4.1"
)
import java.io.{File, PrintWriter}
import javax.imageio.ImageIO
import com.sksamuel.scrimage._
import com.sksamuel.scrimage.filter._
val src = ImageIO.read(new File("/Users/peel/Downloads/6078 dow copy.jpg"))
val tmp = new File("/Users/peel/Desktop/threshold.jpg")
val img: Image = Image(src)
val processed: Image = img.filter(PixelateFilter(100),ThresholdFilter()).scale(0.1)
processed.write(tmp)
case class Matrix(data: Seq[Seq[Int]]){
val height = data.size
val width = data.head.size
override def toString = data.map(_.mkString(";")).mkString("\n")
}
val matrix = Matrix(for (y <- 0 until processed.height) yield for(x<-0 until processed.width) yield processed.pixel(x,y))
s"${matrix.width} x ${matrix.height}"
val pw = new PrintWriter(new File("/Users/peel/Desktop/test.csv"))
pw.write(matrix.toString)
pw.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment