Created
December 12, 2014 12:33
-
-
Save peel/41101906aacb8612d967 to your computer and use it in GitHub Desktop.
image parser
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
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" | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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