Skip to content

Commit f84d35f

Browse files
committed
Adds matte effect (fixes #30)
1 parent e8615e9 commit f84d35f

File tree

5 files changed

+97
-0
lines changed

5 files changed

+97
-0
lines changed

README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ The following algorithms are supported in this library. Click on the link to see
4444
- [Looks](#looks)
4545
- [Lookup table (LUT)](#lookup-table-image)
4646
- [Glitch-Effect](#glitch-image)
47+
- [Matte-Effect](#matte-effect)
4748
- [Strokes](#strokes-image)
4849
- [Dithering](#dithering)
4950
- [Halftone](#halftone-image)
@@ -242,6 +243,15 @@ PImage processedImage = LUT.apply(image, style);
242243
PImage processedImage = Glitch.apply(image, intensity, scanlineheight);
243244
```
244245

246+
#### Matte effect
247+
![alt matte-effect](https://github.com/Milchreis/processing-imageprocessing/blob/master/img/matte.png?raw=true)
248+
```java
249+
PImage processedImage = Matte.apply(image,
250+
matteIntensity, // intensity for the lifting blacks between 0 and 255
251+
contrastIntensity, // intensity for the constrast between 0 and 255
252+
saturationIntensity); // change for the saturation between -0.5 and 0.5
253+
```
254+
245255
#### Strokes image
246256
![alt strokes](https://github.com/Milchreis/processing-imageprocessing/blob/master/img/strokes.png?raw=true)
247257
```java
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* Example for creating a matte effect in the dark areas.
2+
* Use the mouse in X-axis (left and right) to change the matte intensity.
3+
* Use the mouse in Y-axis (up and down) to change the contrast intensity.
4+
* Author: Nick 'Milchreis' Müller
5+
*/
6+
7+
import milchreis.imageprocessing.*;
8+
9+
PImage image;
10+
11+
void setup() {
12+
size(550, 550);
13+
// Load image
14+
image = loadImage(dataPath("example.jpg"));
15+
}
16+
17+
void draw() {
18+
19+
if (mousePressed == true) {
20+
image(image, 0, 0);
21+
22+
} else {
23+
int matteIntensity = (int) map(mouseX, 0, width, 0, 50);
24+
int contrastIntensity = (int) map(mouseY, 0, height, 0, 50);
25+
float saturationIntensity = -0.02;
26+
27+
PImage processedImage = Matte.apply(image, matteIntensity, contrastIntensity, saturationIntensity);
28+
image(processedImage, 0, 0);
29+
}
30+
}
76 KB
Loading

img/matte.png

609 KB
Loading
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package milchreis.imageprocessing;
2+
3+
import milchreis.imageprocessing.utils.Tools;
4+
import processing.core.PImage;
5+
6+
import static processing.core.PApplet.constrain;
7+
import static processing.core.PApplet.map;
8+
9+
/**
10+
* @author milchreis
11+
*/
12+
public class Matte {
13+
14+
public static PImage apply(PImage image, int matteIntensity) {
15+
return apply(image, matteIntensity, 12, -0.02f);
16+
}
17+
18+
public static PImage apply(PImage image, int matteIntensity, int contrastIntensity) {
19+
return apply(image, matteIntensity, contrastIntensity, -0.02f);
20+
}
21+
22+
public static PImage apply(PImage image, int matteIntensity, int contrastIntensity, float saturationOffset) {
23+
24+
int offset = constrain(matteIntensity, 0, 255);
25+
contrastIntensity = constrain(contrastIntensity, 0, 255);
26+
saturationOffset = constrain(saturationOffset, -0.5f, 0.5f);
27+
28+
PImage output = image.copy();
29+
30+
for (int x = 0; x < image.width; x++) {
31+
for (int y = 0; y < image.height; y++) {
32+
33+
int[] rgb = Tools.getColors(image, x, y);
34+
float[] hsb = Tools.rgbToHsb(image.get(x, y));
35+
36+
float strength = constrain((1.0f - (3 * hsb[2])), 0.0f, 1.0f);
37+
38+
// Raise the dark pixel
39+
rgb[0] = (int) constrain(rgb[0] + (strength * offset), 0, 255);
40+
rgb[1] = (int) constrain(rgb[1] + (strength * offset), 0, 255);
41+
rgb[2] = (int) constrain(rgb[2] + (strength * offset), 0, 255);
42+
43+
// Raise contrast
44+
Contrast.contrastPixel(rgb, Contrast.getContrasCorrectionFactor(contrastIntensity));
45+
46+
// Lower saturation
47+
hsb = Tools.rgbToHsb(rgb);
48+
hsb[1] = constrain(hsb[1] + saturationOffset, 0.0f, 1.0f);
49+
50+
Tools.set(output, x, y, Tools.hsbToRgb(hsb));
51+
}
52+
}
53+
54+
return output;
55+
}
56+
57+
}

0 commit comments

Comments
 (0)