File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments