task 3
This commit is contained in:
		| @@ -4,16 +4,18 @@ package imagefilters | |||||||
|  * This class implements the various image filters |  * This class implements the various image filters | ||||||
|  */ |  */ | ||||||
| object ImageFilters { | object ImageFilters { | ||||||
|  |   def filter(src: Array[Array[Int]], func: (Int, Int, Int) => Int): Array[Array[Int]] = { | ||||||
|   def duplicate(a: Array[Array[Int]]): Array[Array[Int]] = { |     val height: Int = src.length | ||||||
|     val height: Int = a.length |     val width: Int = if (height == 0) 0 else src(0).length | ||||||
|     val width: Int = if (height == 0) 0 else a(0).length |     val dst: Array[Array[Int]] = Array.ofDim(height, width) | ||||||
|     val res: Array[Array[Int]] = Array.ofDim(height, width) |  | ||||||
|     for (y: Int <- 0 until height) { |     for (y: Int <- 0 until height) { | ||||||
|       for (x: Int <- 0 until width) { |       for (x: Int <- 0 until width) { | ||||||
|         res(y)(x) = a(y)(x) |         dst(y)(x) = func(src(y)(x), x, y) | ||||||
|       } |       } | ||||||
|     } |     } | ||||||
|     return res |     return dst | ||||||
|   } |   } | ||||||
|  |  | ||||||
|  |   def duplicate(a: Array[Array[Int]]): Array[Array[Int]] = filter(a, (value, x, y) => value) | ||||||
|  |   def threshold(a: Array[Array[Int]], thresh: Int): Array[Array[Int]] = filter(a, (value, x, y) => if (value > thresh) 255 else 0) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -7,8 +7,11 @@ object ImageProcessingApp extends App { | |||||||
| 	val imageFile = "./res/collins_eileen.png" | 	val imageFile = "./res/collins_eileen.png" | ||||||
| 	val org = new ImageGraphics(imageFile, "Original", -500, -250) | 	val org = new ImageGraphics(imageFile, "Original", -500, -250) | ||||||
| 	val dest = new ImageGraphics(imageFile, "Duplicate", 0, -250) | 	val dest = new ImageGraphics(imageFile, "Duplicate", 0, -250) | ||||||
|  | 	val thresh = new ImageGraphics(imageFile, "Threshold", -500, 250) | ||||||
|  |  | ||||||
|     // Simple copy and display |     // Simple copy and display | ||||||
| 	val newPixels = ImageFilters.duplicate(org.getPixelsBW()) | 	val newPixels = ImageFilters.duplicate(org.getPixelsBW()) | ||||||
| 	dest.setPixelsBW(newPixels) | 	dest.setPixelsBW(newPixels) | ||||||
|  |  | ||||||
|  | 	thresh.setPixelsBW(ImageFilters.threshold(newPixels, 128)) | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user