-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolarization.java
More file actions
36 lines (34 loc) · 1.29 KB
/
Solarization.java
File metadata and controls
36 lines (34 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class Solarization extends ColorPixelConverter{
/* lower end of threshold */
private int lowerR=80,lowerG=80,lowerB=80;
/* upper end of threshold */
private int upperR=160,upperG=160,upperB=160;
/* constructor */
public Solarization(){
}
public Solarization(int lower,int upper){
lowerR=lowerG=lowerB=lower;
upperR=upperG=upperB=upper;
}
public Solarization(int lowerR,int lowerG,int lowerB,
int upperR,int upperG,int upperB){
this.lowerR=lowerR; this.lowerG=lowerG; this.lowerB=lowerB;
this.upperR=upperR; this.upperG=upperG; this.upperB=upperB;
}
/* solarization function */
public int functionR(int r){
if(r<lowerR) return (int)(255/(lowerR+0.1)*r);
else if(r<upperR) return (int)(-255/(upperR-lowerR+0.1)*(r-upperR));
else return (int)(255/(255-upperR+0.1)*(r-upperR));
}
public int functionG(int g){
if(g<lowerG) return (int)(255/(lowerG+0.1)*g);
else if(g<upperG) return (int)(-255/(upperG-lowerG+0.1)*(g-upperG));
else return (int)(255/(255-upperG+0.1)*(g-upperG));
}
public int functionB(int b){
if(b<lowerB) return (int)(255/(lowerB+0.1)*b);
else if(b<upperB) return (int)(-255/(upperB-lowerB+0.1)*(b-upperB));
else return (int)(255/(255-upperB+0.1)*(b-upperB));
}
}