task 8.3
This commit is contained in:
parent
ee6999b095
commit
0657c28d7d
@ -6,6 +6,19 @@ import java.awt.Color
|
|||||||
* This class implements the various image filters
|
* This class implements the various image filters
|
||||||
*/
|
*/
|
||||||
object ImageFilters {
|
object ImageFilters {
|
||||||
|
// Default factors (reference values)
|
||||||
|
/*val SEPIA_FACTORS: Array[Array[Double]] = Array(
|
||||||
|
Array( 0.393, 0.769, 0.189),
|
||||||
|
Array( 0.349, 0.686, 0.168),
|
||||||
|
Array( 0.272, 0.534, 0.131)
|
||||||
|
)*/
|
||||||
|
|
||||||
|
// Adapted factors (matches the example in the instructions)
|
||||||
|
val SEPIA_FACTORS: Array[Array[Double]] = Array(
|
||||||
|
Array( 0.883, 0.004, 0.003),
|
||||||
|
Array(-0.058, 0.791,-0.097),
|
||||||
|
Array( 0.034,-0.244, 0.583)
|
||||||
|
)
|
||||||
|
|
||||||
def filter(src: Array[Array[Int]], func: (Int, Int, Int, Int, Int) => Int): Array[Array[Int]] = {
|
def filter(src: Array[Array[Int]], func: (Int, Int, Int, Int, Int) => Int): Array[Array[Int]] = {
|
||||||
val width: Int = src.length
|
val width: Int = src.length
|
||||||
@ -146,4 +159,20 @@ object ImageFilters {
|
|||||||
else col
|
else col
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def sepia(a: Array[Array[Color]]): Array[Array[Color]] = colorFilter(a, (col) => {
|
||||||
|
val r: Double = Math.max(0, Math.min(255, col.getRed * SEPIA_FACTORS(0)(0) +
|
||||||
|
col.getGreen * SEPIA_FACTORS(0)(1) +
|
||||||
|
col.getBlue * SEPIA_FACTORS(0)(2)))
|
||||||
|
|
||||||
|
val g: Double = Math.max(0, Math.min(255, col.getRed * SEPIA_FACTORS(1)(0) +
|
||||||
|
col.getGreen * SEPIA_FACTORS(1)(1) +
|
||||||
|
col.getBlue * SEPIA_FACTORS(1)(2)))
|
||||||
|
|
||||||
|
val b: Double = Math.max(0, Math.min(255, col.getRed * SEPIA_FACTORS(2)(0) +
|
||||||
|
col.getGreen * SEPIA_FACTORS(2)(1) +
|
||||||
|
col.getBlue * SEPIA_FACTORS(2)(2)))
|
||||||
|
|
||||||
|
new Color(r.toInt, g.toInt, b.toInt)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
@ -47,8 +47,13 @@ object ImageProcessingApp extends App {
|
|||||||
val masked = new ImageGraphics(imageFile, "Masked", 256, -512)
|
val masked = new ImageGraphics(imageFile, "Masked", 256, -512)
|
||||||
masked.setPixelsColor(ImageFilters.mask(org.getPixelsColor(), mask.getPixelsBW()))*/
|
masked.setPixelsColor(ImageFilters.mask(org.getPixelsColor(), mask.getPixelsBW()))*/
|
||||||
|
|
||||||
val imageFile: String = "./res/grace_hopper.jpg"
|
/*val imageFile: String = "./res/grace_hopper.jpg"
|
||||||
val org = new ImageGraphics(imageFile, "Original", -768, -512)
|
val org = new ImageGraphics(imageFile, "Original", -768, -512)
|
||||||
val pixelated = new ImageGraphics(imageFile, "Pixelated", -256, -512)
|
val pixelated = new ImageGraphics(imageFile, "Pixelated", -256, -512)
|
||||||
pixelated.setPixelsColor(ImageFilters.pixelize(org.getPixelsColor(), 30, 130, 120, 400, 230))
|
pixelated.setPixelsColor(ImageFilters.pixelize(org.getPixelsColor(), 30, 130, 120, 400, 230))*/
|
||||||
|
|
||||||
|
val imageFile: String = "./res/collins_eileen.png"
|
||||||
|
val org = new ImageGraphics(imageFile, "Original", -768, -512)
|
||||||
|
val sepia = new ImageGraphics(imageFile, "Sepia", -256, -512)
|
||||||
|
sepia.setPixelsColor(ImageFilters.sepia(org.getPixelsColor()))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user