Skip to content

Commit ca8de14

Browse files
committed
Add noiser to produce noisy images
1 parent d110be5 commit ca8de14

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

src/main/scala/Noiser/Noiser.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import java.io.File
2+
import scala.util.Random
3+
import _root_.Utils.FileUtils
4+
5+
object Noiser {
6+
val PROB = 0.3
7+
val inputImage = "./data/4.jpg"
8+
val outputImage = "./data/test_4.png"
9+
10+
def main(args: Array[String]) = {
11+
println("Start noiser")
12+
println("Image: " + inputImage)
13+
14+
val is = FileUtils.getInputStream(inputImage)
15+
val imageIn = new Image()
16+
var matrix = imageIn.getPixelMatrix(is, true)
17+
is.close()
18+
19+
val out = matrix.map( pixel => {
20+
if ( Random.nextDouble < PROB ) {
21+
if(pixel > 128) 0 else 255
22+
} else pixel
23+
})
24+
25+
val os = FileUtils.getOutputStream(outputImage)
26+
val imageOut = new Image()
27+
imageOut.setPixelMatrix(out, imageIn.width, imageIn.height, true)
28+
imageOut.saveImage(os)
29+
os.close()
30+
31+
println("End noiser")
32+
}
33+
}

0 commit comments

Comments
 (0)