Last active
August 29, 2015 14:11
-
-
Save katzchang/4cf11bda49f55db5321f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
SBT=~/bin/sbt | |
gen: mse | |
cat $(d)/result.txt | |
mse: | |
$(SBT) 'runMain mse.MSE $(d)' |
This file contains hidden or 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
package mse | |
import java.io._ | |
import org.bytedeco.javacpp.helper.opencv_core.AbstractCvMat | |
import org.bytedeco.javacpp.opencv_core._ | |
import org.bytedeco.javacpp.opencv_highgui._ | |
object MSE { | |
def main(args: Array[String]) { | |
val ms = | |
new File(args(0)) | |
.listFiles | |
.filter(_.getName.endsWith(".png")) | |
val stream = new FileOutputStream(args(0) + "/result.txt") | |
val out = new PrintStream(stream) | |
val mses = ms.zip(ms.tail).map { | |
p => | |
for { | |
i1 <- load(p._1) | |
i2 <- load(p._2) | |
} yield out.println( | |
List(p._2.getName.substring(23,31), apply(i1, i2)) | |
.mkString("\t")) | |
} | |
} | |
def load(file: File, flags: Int = CV_LOAD_IMAGE_COLOR): Option[CvMat] = | |
Option(cvLoadImageM(file.getAbsolutePath, flags)) | |
/** | |
* see http://stackoverflow.com/a/19290458 | |
*/ | |
def apply(mat1: CvMat, mat2: CvMat): Double = { | |
val s1: CvMat = AbstractCvMat.create(mat1.rows(), mat1.cols(), mat1.depth(), mat1.nChannels()) | |
cvAbsDiff(mat1, mat2, s1) | |
val s1Squared: CvMat = cvCreateMat(s1.rows(), s1.cols(), CV_32FC3) | |
cvMul(s1, s1, s1Squared, 1) | |
val scalar: CvScalar = cvSum(s1Squared) | |
val sse: Double = scalar.getVal(0) + scalar.getVal(1) + scalar.getVal(2) | |
val mse: Double = sse / (s1.channels() * s1.total()).toDouble | |
mse | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment