Git Product home page Git Product logo

processing-imageprocessing's Introduction

Image processing for Processing

This library collects various image processing algorithms and provides simple access to them. All algorithms are implemented in Java and runs without any other dependencies. Some algorithms are pretty standard and others maybe do you know from Photoshop. It starts with less basic features and grow over the last years. If you need high power performance better use opencv for processing.

If you like this project and you want to keep me awake 🤪

Buy Me a Coffee at ko-fi.com

Installation

If you want to use this library in your processing sketch you can download it via the integrated Contribution Manager.

alt install

Examples

Overview

The following algorithms are supported in this library. Click on the link to see an example image and a code snippet.

Original image

alt original

Photo taken by me more here

Basics

Grayscale image

alt grayscale

PImage processedImage = Grayscale.apply(image);

Flip image

alt flip

PImage processedImage = Flip.apply(image, horizontal, vertical);  // horizontal and vertical are boolean

Invert colors

alt invert colors

// invertRed, invertGreen and invertBlue are boolean
PImage processedImage = InvertColors.apply(image, invertRed, invertGreen, invertBlue);  

Threshold image

alt threshold

PImage processedImage = Threshold.apply(image);  // Auto threshold
PImage processedImage = Threshold.apply(image, value);  // Threshold value between 0 and 255

Dilation image

alt dilation

PImage processedImage = Dilation.apply(image, radius);  // radius is a positive number

Erosion image

alt erosion

PImage processedImage = Erosion.apply(image, radius);  // radius is a positive number

Vignette image

alt vignette

// intensity and vignetteWidth are floats between 0.0 and 1.0
PImage processedImage = Vignette.apply(image, intensity, vignetteWidth); 

Quantization

alt quantization

PImage processedImage = Quantization.apply(image, shades);  // shades is a positive number between 1 and 255

PaletteMapping

alt quantization

PImage processedImage = PaletteMapping.apply(image, color1, color2, color3);  // Add any number of colors from dark to light

Difference

alt difference

// difference is a float between 0.0 and 1.0 from less to very different
float difference = Comparison.howDifferent(image1, image2);
// differenceImage is the difference between the pixel values (black is no difference, white is high difference)
PImage differenceImage = Comparison.calculateDifferenceImage(image1, image2);

Blur

Gaussian blur image

alt gaussian

PImage processedImage = Gaussian.apply(image, 7, 0.84089642);   // kernel size and sigma 

Pixelize image

alt pixelation

// pixelsize is a positive number
PImage processedImage = Pixelation.apply(image, pixelsize); 
// Pixelize a sub area of the input image
PImage processedImage = Pixelation.apply(image, pixelsize, subX, subY, subWidth, subHeight);  

Tilt-Shift-Effect

alt tilt-shift

PImage processedImage = TiltShift.apply(image, blurIntensity, horizontal, position, sharpWideness);   

Edge detection

Canny's algorithm

alt canny-edge

PImage processedImage = CannyEdgeDetector.apply(image);

Sobels algorithm

alt sobel-edge

PImage processedImage = SobelEdgeDetector.apply(image);
// for colored sobel (for each color channel)
PImage processedImage = SobelEdgeDetector.apply(image, false);

Optimisation

Brightness

alt autobalance

PImage processedImage = Brightness.apply(image, value); 
// value isa positive number for brighting up or a negative for darken down

Contrast

alt contrast

// intensity is between -1.0 and 1.0
PImage processedImage = Contrast.apply(image, intensity); 

Saturation

alt saturation

// intensity is between 0.0 and 10.0
// 0.0 to 1.0 decreases and all above increases the saturation
PImage processedImage = Saturation.apply(image, intensity); 

Changing highlights

alt changing highlights

// intensity between -1.0 and 1.0
PImage processedImage = Lights.apply(image, intensity); 

Changing shadows

alt changing shadows

// intensity between -1.0 and 1.0
PImage processedImage = Shadows.apply(image, intensity); 

AutoBalance image

alt autobalance

PImage processedImage = AutoBalance.apply(image);

Bloom image

alt bloom

PImage processedImage = Bloom.apply(image, intensity);  // intensity between 0 and 255

Sharpen image

alt sharpen

PImage processedImage = Sharpen.apply(image, sharpIntensity);  // sharpIntensity between 0.0 and 10.0

Color shift image

alt color shift

// hue is a value between 0 and 360
// offset is the color range which is accepted (in hue range)
// shift is the number of the subtracted or added hue value
PImage processedImage = ColorShift.applyHue(image, hue, offset, shift);  // or short: ColorShift.apply(image, hue, offset, shift)
PImage processedImage = ColorShift.applySaturation(image, hue, offset, shift);
PImage processedImage = ColorShift.applyBrightness(image, hue, offset, shift);

Looks

Lookup table image

alt lookup-table

LUT style = LUT.loadLut(LUT.STYLE.CONTRAST);
PImage processedImage = LUT.apply(image, style); 

RetroConsole effect (Gameboy)

alt lookup-table

PImage processedImage = RetroConsole.applyGameboy(image, pixelSize); 

Glitch image

alt glitch-effect

PImage processedImage = Glitch.apply(image, intensity, scanlineheight);

Matte effect

alt matte-effect

PImage processedImage = Matte.apply(image, 
    matteIntensity,         // intensity for the lifting blacks between 0 and 255
    contrastIntensity,      // intensity for the constrast between 0 and 255
    saturationIntensity);   // change for the saturation between -0.5 and 0.5

Sabattier effect

alt sabattier-effect

// intensity between 0.0 and 1.0
PImage processedImage = Sabattier.apply(image, intensity);
PImage processedImage = Sabattier.applyRed(image, intensity);
PImage processedImage = Sabattier.applyGreen(image, intensity);
PImage processedImage = Sabattier.applyBlue(image, intensity);

Strokes image

random angles fixed angle
alt strokes alt strokes
PImage processedImage = Strokes.apply(image, gridSize, lineLength);
PImage processedImage = Strokes.apply(image, 
    gridSize,           // is positive and the area for compound pixels 
    lineLength,         // is positive and the length in pixels for each line
    lineWeight,         // is positive and the weight of each line in pixel
    linesPerGrid,       // the number of lines per grid
    lineIntensity,      // alpha value for each line between 0 and 255
    degree,             // if set the rotation is fixed in degree, otherwise random
    inColor,            // true for colors else black and white
    backgroundColor);   // color for the background

Dithering

alt dithering

// default dithering algorithm is BAYER_4x4
PImage processedImage = Dithering.apply(image);
// change algrithm: BAYER_2x2, BAYER_4x4, BAYER_8x8
PImage processedImage = Dithering.apply(image, Dithering.Algorithm.BAYER_8x8);
// use a curstom kernel (kernel = float[])
PImage processedImage = Dithering.aapply(PImage image, kernel);  

Halftone image

alt halftone

PImage processedImage = Halftone.apply(image, dotsize);  // dot size in pixel
PImage processedImage = Halftone.apply(image, dotsize, grid); // grid = true, on false honeycomb style
PImage processedImage = Halftone.apply(image, dotsize, foreground, background);  // background and foreground colors
PImage processedImage = Halftone.apply(image, dotsize, foreground, background, grid);
PImage processedImage = Halftone.apply(image, dotsize, foreground, background, spacing, grid); // size between dots in pixels

Toning image

alt toning

// tone is a color and intensity is a value between 0.0 and 1.0
color tone = color(255, 11, 120);
float intensity = 0.8f;
PImage processedImage = Toning.apply(image, tone, intensity);

Split toning image

alt split-toning

PImage processedImage = SplitToning.apply(
      image,
      highlightTone,        // Color for highlighs (f.e. color highlightTone = color(211, 180, 21);
      intensityHighlights,  // intensity for the toning in highlights between 0.0 and 1.0
      shadowTone,           // Color for the shadows (f.e. color shadowTone = color(124, 32, 201);
      intensityShadows);    // intensity for the toning in the shadows between 0.0 and 1.0

Sine-Wave image

alt sine-wave

PImage processedImage = SineWave.apply(image, rowHeight, weight, backgroundColor, wavesColor);

Knitting image

alt knitting

// keeps the original colors
PImage processedImage = Knitting.apply(image, size);
// Sets foreground and background color and uses a threshold
PImage processedImage = Knitting.apply(image, size, threshold, 240, #EE0000); 

ASCII image

alt ascii

PImage processedImage = ASCII.apply(image);
// characterset = ASCII.SHORT_SET or ASCII.LONG_SET, another String from black to white
PImage processedImage = ASCII.apply(image, characterset); 
PImage processedImage = ASCII.apply(image, characterset, fontSize); // fontSize is an integer
PImage processedImage = ASCII.apply(image, characterset, fontSize, foregroundColor, backgroundColor, toneInColor);
// To get the ASCII image as plain string use the following method
PImage processedImage = ASCII.getAsciiText(image); 

Miscellaneous

Stacked images

alt stacked

// Add so many images in the end as you need
PImage processedImage = Stacker.apply(Stacker.ALGORITHM.AVERAGE, image1, image2);
PImage processedImage = Stacker.apply(Stacker.ALGORITHM.MEDIAN, image1, image2);

Blending two images

alt blending

// intensity is a float between 0.0 and 1.0
PImage processedImage = Blend.apply(image1, image2, intensity);

Special thanks

My special thanks goes to avatarr for implementing and publishing basic algorithms. Also thank you very much Tom Gibara for your great blog post and the implementation of the canny edge detector.

Moreover I thank you Joseph HENRY for the Sine-Wave-effect code and uheinema for the Sabattier code in the Processing Discourse.

processing-imageprocessing's People

Contributors

efferifick avatar milchreis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

processing-imageprocessing's Issues

Optimize pixel access

Substitute image.get() with pixels[] and load/updatePixels for better performance.

Possibility of using GLSL?

Hello!

Thanks for the wonderful and well-made Processing library!
It's very useful for static images and perhaps will be enough for most use cases.

I work with running Processing on Raspberry Pi and was wondering if the same functions could be implemented by using video card accelerated language such as GLSL. The main advantage of using GLSL filters would be that all of these effects could be ran at 50-60 fps on almost any hardware that has a GPU.

Let me know if you would be interested in hearing more or if you want to have a discussion about that. Thanks!

Implementation in Android

How to implementation in android using Gradle or maven?
When unavailable, can you guide how to import jar file maybe.?

Error everytime I want to use any function from the library

The code looks like that:

import milchreis.imageprocessing.*;
import milchreis.imageprocessing.utils.*;

PImage img;

void setup() {
  // Images must be in the "data" directory to load correctly
  img = loadImage("pawelstulejka.jpg");
}

PImage processedImage = Pixelation.apply(img, 2); 

void draw() {
  image(img, 0, 0, width, height);
}

When I run it, I get the following error:

java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
	at processing.core.PApplet.runSketch(PApplet.java:10852)
	at processing.core.PApplet.main(PApplet.java:10620)
Caused by: java.lang.reflect.InvocationTargetException
	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
RuntimeException: java.lang.reflect.InvocationTargetException
	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
	at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
	at processing.core.PApplet.runSketch(PApplet.java:10846)
	... 1 more
Caused by: java.lang.NullPointerException
	at milchreis.imageprocessing.Pixelation.apply(Unknown Source)
	at photoEditor2.<init>(photoEditor2.java:30)
	... 6 more

Can someone please help me?

Question about PixelDensity

thanks for this library, its cool.

I ran into something - if I set pixelDensity(displayDensity()); in my sketch to work in HiDPI , seems that the imageprocessing library might not be compatible, it throws a lot of exceptions with TiltShift , Threshold, etc.

Do I need to set something in the constructor?

Version number is not a number!

Hi, I just installed this library into Processing 4.0.1, the library version reported in Contribution Manager is 1.7.0

As soon as I installed the library I got the following message in the console output:

The version number for “Image processing algorithms” is not a number. Please contact the author to fix it according to the guidelines.

So, here I am contacting the author! 🙂

Matte effect

  • Lifting blacks
  • under saturate
  • increase contrast

Changing saturation

Saturation.apply(PImage image, float shift); // -1.0 <= shift <= 1.0
The ColorShift-Implementation could used therefor.

Hue image

Converting an image to the hue values for better color tracking possibilities

Stacker

Image stacking with median and average

Could not install

Hello,
I get this error when I want to install it from the Contribution Manager:
Could not download https://github.com/Milchreis/processing-imageprocessing/releases/download/latest/processing-imageprocessing.zip to /tmp/download2801719027574994109processing-imageprocessing.zip : Erreur lors du téléchargement et de l'installation.

Quantization

  • Quantization with custom shades
  • Calculate error image

1.6.0 -- please create a github release

Contribution Manager is still pulling the 1.5.1 release because its sources.conf points to the attachment at "latest":

https://github.com/Milchreis/processing-imageprocessing/releases/download/latest/processing-imageprocessing.txt

Right now, 1.5.1 is the "latest" release created through the GitHub releases tab -- 1.6.0 is tag-only, and so it is not on the "latest" url and doesn't have the txt attachment url.

Creating a 1.6.0 release on GitHub with the proper .txt and .zip attachments will make the new release available through for Contributions Manager.

Pixelation

  • Pixelize an image with custom pixel size
  • Apply the effect on a sub area of an image

Color-Shift

Transform a selected color area by the hue value in a brighter or darker tone.

Error in Flip class

While trying to use Flip , the new image contained a black border on one or both sides.
graySqProof_sm

I found the problem in this routine in Flip.java:

int newx = horizonal ? image.width - x : x;
int newy = vertical ? image.height - y : y;

When I changed the code to this:

int newx = horizonal ? (image.width - x) - 1 : x;
int newy = vertical ?( image.height - y ) - 1: y;

the problem was eliminated.

If you look closely at your example you can see the error.

Josh Prokop

Strokes with fixed angle

  • Strokes are in an fixed angle (f.e. -45° oer 45°)
  • Line length depending on the color intensity
  • Multiply with original image for some comic effect

strokes-house

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.