Repository with filters for image.
First you should clone and compile the project.
$ git clone https://github.com/janczer/filters
$ cd filters
$ sbt compile
$ sbt packageAfter that you will have file filters_2.12-X.X.jar in target/scala-2.12/.
Simple script for test this library:
import janczer.filters.Filters
import java.io.File
import javax.imageio.ImageIO
def test() {
val photoIn = ImageIO.read(new File("test.jpg"))
ImageIO.write(Filters.mirror(photoIn, true, true), "jpg", new File("mirror.jpg"))
}
test()This is the way how you can run it:
$ scala -classpath "filters_2.12-0.2.jar" test.scala- Mirror image
- Gray filter
- Sepia filter
- Inverse filter
- Split image to RGB channels
- Color accent filter
- Histogram
- Median filter
- Noise filter
- Sort zig zag
Function mirror get 3 parameters:
def mirror(img: BuffereImage, ox: Boolean, oy: Boolean): BuffereImageimg- Image objectox- iftruewhen image mirrored horizontallyoy- iftruewhen image mirrored vertically
And you will have one file mirror.jpg.
| Original | ox=true, oy = false | ox = false, oy = true | ox = true, oy = true |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Function gray get 2 parameters:
def gray(img: BufferedImage, typ: String): BufferedImageimg- Image objecttyp- type of filter gray (avarage, lightness, luminosity)
And you will have one file gray.jpg.
| Original | Avarage | Lightness | luminosity |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Sepia filter work on gray scale images.
Function sepia get 2 parameters:
def sepia(img: BufferedImage, sp: Int): BufferedImageimg- Image objectsp- factor of sepia effect (20-40)
And you will have one file sepia.jpg.
| Original | Factor 20 | Factor 40 |
|---|---|---|
![]() |
![]() |
![]() |
Function inverse get 1 parameter:
def inverse(img: BufferedImage): BufferedImageimg- Image object
And you will have one file inverse.jpg.
| Original | Inverse |
|---|---|
![]() |
![]() |
Function rgb get 3 parameters:
def rgb_channels(img: BufferedImage, r: Boolean, g: Boolean, b: Boolean): BufferedImageimg- Image objectr- Show only red channelg- Show only green channelb- Show only blue channel
And you will have 3 files red.jpg, green.jpg and blue.jpg.
| Original | Only red | Only green | Only blue |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Function color_accent get 3 parameters:
def color_accent(img: BufferedImage, hue: Int, range: Int): BufferedImageimg- Image objecthue- Color in HSVrange- Range around colorhue
| Original | Hue = 0, Range = 50 | Hue = 70, Range = 50 | Hue = 200, Range = 50 |
|---|---|---|---|
![]() |
![]() |
![]() |
![]() |
Function histogram get 1 parameter:
def histogram(img: BufferedImage, grid: Boolean): BufferedImageimg- Image objectgrid- If true image will be have grid
| Original | Histogram |
|---|---|
![]() |
![]() |
![]() |
![]() |
![]() |
![]() |
Function median get 1 parameter:
def median(img: BufferedImage): BufferedImageimg- Image object
| Original | Median filter |
|---|---|
![]() |
![]() |
Function noise get 1 parameter:
def noise(img: BufferedImage): BufferedImageimg- Image object
| Original | Noise filter |
|---|---|
![]() |
![]() |
More about this filter you can read on my blog.
Function sort_zig_zag get 2 parameters:
def sort_zig_zag(img: BufferedImage, gray: Boolean): BufferedImageimg- Image objectgray- if true then function transfor image to gray
| Original | color | gray |
|---|---|---|
![]() |
![]() |
![]() |
To run test:
$ sbt clean test
To get coverage report:
$ sbt clean coverage test && sbt coverageReport
























