GithubHelp home page GithubHelp logo

kdanik / scala-kuva Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 35.92 MB

Scala library for image and color processing, manipulation and filters

Scala 100.00%
image image-filtering image-manipulation image-processing scala color binarization blending grayscale hashing

scala-kuva's Introduction

Description

Scala Kuva is a Scala library that focuses on image and color processing and filtering.

Functionality

Color types

The library contains implementations for three color formats: RGB(A), HSL(A), and HSV(A). These color types are immutable and can be converted between each other. Additionally, they can also be converted to java.awt.Color and created from it

Immutable image

For all image operations in this library own implementation of the immutable image is used. The Immutable image simply wraps two-dimensional Vector of immutable Pixels, offering some useful operations to work with it in functional way.

It can also be converted to java.awt.image.BufferedImage and created from it.

Color and image manipulation

This library contains implementation for various color and image operations. For example: most grayscale algorithms, many blend modes, binarization, resizing with different algorithms, croping and more.

This initial image will be used to demonstrate the effects of the different operations.

Original picture of cocktail

Basic image operations

Cropping

Cropped picture of cocktail

Scaling

Nearest Neighbor

Example image is downscaled (from 1024x1280 to 400 x 500) using nearest neighbor algorithm.

Downscaled (with nearest neighbor) picture of cocktail

Example image is upscaled (from 128x160 to 1024x1280) using nearest neighbor algorithm.

Upscaled (with nearest neighbor) picture of cocktail

Bilinear interpolation

Example image is upscaled (from 128x160 to 1024x1280) using bilinear interpolation.

Upscaled (with bilinear interpolation) picture of cocktail

Bicubic interpolation

Example image is upscaled (from 128x160 to 1024x1280) using bicubic interpolation.

Upscaled (with bicubic interpolation) picture of cocktail

Hashing

Average hash (aHash)

The average hash algorithm works by converting an image into a grayscale, downsampling it to a small size (8x8 per default), computing the average pixel value, and creating a binary hash by comparing each pixels value with the average value.

Median hash (mHash)

The average hash algorithm works by converting an image into a grayscale, downsampling it to a small size (8x8 per default), computing the median pixel value, and creating a binary hash by comparing each pixels value with the median value.

Difference hash (dHash)

The difference hash algorithm works by converting an image into a grayscale, downsampling it to a small size (9x8 per default), and by computing the difference in pixel values between adjacent pixels (compares each pixel with the pixel on the right from it).

Blur

Box blur

Picture of cocktail after applying box blur with radius 7

Median blur

Picture of cocktail after applying median blur with radius 7

Gaussian blur

Picture of cocktail after applying gaussian blur with kernel 101x101

Grayscale

Averaging

This algorithm simply uses average of all color channels as grayscale color.

Picture of cocktail after applying averaging grayscale

Decomposition (using max channel value)

Calculates max value of 3 color channels and uses it as grayscale color.

Picture of cocktail after applying decomposition (max) grayscale

Decomposition (using min channel value)

Calculates min value of 3 color channels and uses it as grayscale color.

Picture of cocktail after applying decomposition (min) grayscale

Desaturation

This algorithm first convert color to HSL and then reduces saturation to 0.

Picture of cocktail after applying desaturation grayscale

Luma (ITU-R BT 601)

Calculate grayscale color using luma (luminance or brightness) formula (from ITU-R BT 601 specification).

Picture of cocktail after applying luma (BT 601) grayscale

Luma (ITU-R BT 709)

Also calculates grayscale color using luma formula, but from newer standard (ITU-R BT 709). The weighting coefficients used in the formulas are different between the two standards.

Picture of cocktail after applying luma (BT 709) grayscale

Single channel (red)

Uses as grayscale color the value of red color channel

Picture of cocktail after applying single channel (red) grayscale

Single channel (green)

Uses as grayscale color the value of green color channel

Picture of cocktail after applying single channel (green) grayscale

Single channel (blue)

Uses as grayscale color the value of blue color channel

Picture of cocktail after applying single channel (blue) grayscale

Lightness

Calculates and uses as grayscale lightness using formula from this paper.

Picture of cocktail after applying lightness grayscale

Lightness (HSL)

Calculates and uses as grayscale lightness using formula from HSL color format.

Picture of cocktail after applying lightness (HSL) grayscale

Middle value

Calculates and uses as grayscale middle value of the RGB channels

Picture of cocktail after applying middle value grayscale

N-shades of gray (using Luma 601 for initial grayscale)

Converts grayscale image to grayscale image with limited number of shades. (Example image has 8 shades of gray)

Picture of cocktail after applying N-shades of gray algorithm (8 shades)

Inversion

Color inversion is a photo effect that flips all colors to their opposite hue on the color wheel (with inversion of alpha channel or without).

Picture of cocktail after inversion

Blending colors

To demonstrate different color blending algorithms two abstract (background and foreground) images will be used. (There also additional examples in src/main/resources/source/blend/gradient folder)

Background (initial image):

Abstract background

Foreground (overlay image):

Abstract foreground

Simple Alpha Compositing

Color blending with alpha compositing algorithm

Dissolve

Color blending with dissolve algorithm

Multiply

Color blending with dissolve algorithm

Screen

Color blending with screen algorithm

Overlay

Color blending with overlay algorithm

Hard Light

Color blending with hard light algorithm

Soft Light

Color blending with soft light algorithm

Color Dodge

Color blending with color dodge algorithm

Linear Dodge

Color blending with linear dodge algorithm

Color Burn

Color blending with color burn algorithm

Linear Burn

Color blending with linear burn algorithm

Vivid Light

Color blending with vivid light algorithm

Linear Light

Color blending with linear light algorithm

Divide

Color blending with divide algorithm

Difference

Color blending with difference algorithm

Subtract

Color blending with subtract algorithm

Lighten only

Color blending with lighten only algorithm

Darken only

Color blending with darken only algorithm

Hard mix

Color blending with hard mix algorithm

Pin light

Color blending with pin light algorithm

Reflect

Color blending with reflect algorithm

Exclusion

Color blending with exclusion algorithm

Geometric mean

Color blending with geometric mean algorithm

Luminosity

Color blending with geometric luminosity algorithm

Color

Color blending with geometric color(HSL) algorithm

Binarization

Binarization is the process of converting a multi-tone grayscale image into a two-tone black and white image. This is achieved by finding a threshold value, which is then used to create the binary output.

Otsu's method

Otsu's method is a thresholding technique used to separate an image into foreground and background pixels. It calculates the optimal threshold value by maximizing the between-class variance of pixel intensities.

Otsu's method requires the image to be converted into grayscale before applying the algorithm, and the resulting threshold value may vary depending on the specific grayscale conversion algorithm used.

Source sheep image

Sheep image binarized with Otsu's method

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.