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 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
| /**
*
*/
package filmlooking;
import java.awt.image.BufferedImage;
import millie.image.Kernel;
import millie.image.PredefinedKernel;
import millie.plugins.GenericPluginFilter;
import millie.plugins.PluginInfo;
import millie.plugins.parameters.IntSliderParameter;
import millie.se.operator.ContrastOperator;
import millie.se.operator.ConvolveOperator;
import millie.se.operator.extender.BorderExtenderCopy;
import millie.util.ColorUtils;
import millie.util.MillieUtils;
/**
* @author fhu
*
*/
@PluginInfo(name="Contrast local", category="Cinema", description="Contraste local")
public class LocalContrastFilter extends GenericPluginFilter {
public LocalContrastFilter() {
setPluginName("Local contrast");
setLongProcessing(true);
setRefreshable(true);
setWithPreview(true);
addParameter(new IntSliderParameter("contrast", "Contraste", -100, 100, 0));
addParameter(new IntSliderParameter("rayon", "Rayon", 1, 10, 6));
addParameter(new IntSliderParameter("factor", "Facteur", 1, 100, 1));
addParameter(new IntSliderParameter("sigma", "Sigma", 1, 20, 3));
}
private int range(double rgb) {
if(rgb>255)return 255;
if(rgb<0) return 0;
return (int) rgb;
}
private double gLog(double g) {
return Math.max(0 , 1.16*Math.pow(g, 0.333)-0.16);
}
private double carre(double g) {
return g*g;
}
@Override
public BufferedImage filter() throws Exception {
int contrast = getIntValue("contrast");
int rayon = getIntValue("rayon");
int factor = getIntValue("factor");
BufferedImage input = getInputImage();
Kernel k = PredefinedKernel.getMDIF(rayon, getIntValue("sigma"));
ConvolveOperator op = new ConvolveOperator(k, new BorderExtenderCopy());
BufferedImage out = op.compute(input);
for(int j=0; j<out.getHeight(); j++)
for(int i=0; i<out.getWidth();i++) {
int rgbMask = out.getRGB(i, j);
int r = (rgbMask >> 16) & 0xFF ;
int g = (rgbMask >> 8) & 0xFF ;
int b = (rgbMask >> 0) & 0xFF ;
r*=(factor+29.0f)/30.0f;
g*=(factor+29.0f)/30.0f;
b*=(factor+29.0f)/30.0f;
double norme = Math.sqrt(carre(r) + carre(g) + carre(b)) / (Math.sqrt(3) * 255.0);
norme = gLog(norme);
norme*=255;
int normeI = range(norme);
out.setRGB(i, j, ColorUtils.getRGB(normeI, normeI, normeI));
}
//if(true)
// return out;
BufferedImage iContrast = new ContrastOperator(contrast).compute(input);
for(int j=0; j<out.getHeight(); j++)
for(int i=0; i<out.getWidth();i++) {
int rgbContrastedk = iContrast.getRGB(i, j);
int rgbMask = out.getRGB(i, j);
int rgb = input.getRGB(i, j);
float rC = (rgbContrastedk>>16)&0xFF;
float gC = (rgbContrastedk>>8)&0xFF;
float bC = (rgbContrastedk>>0)&0xFF;
int r = (rgb>>16)&0xFF;
int g = (rgb>>8)&0xFF;
int b = (rgb>>0)&0xFF;
int rOPI = (rgbMask>>16)&0xFF;
int gOPI = (rgbMask>>8)&0xFF;
int bOPI = (rgbMask>>0)&0xFF;
double op2 = MillieUtils.max(rOPI, gOPI, bOPI);
op2/=255.0;
if(op2>1)
op2=1;
r = (int) (rC * op2 + r* (1.0f-op2));
g = (int) (gC * op2 + g* (1.0f-op2));
b = (int) (bC * op2 + b* (1.0f-op2));
out.setRGB(i, j, ColorUtils.getRGB(range(r), range(g), range(b)));
}
return out;
}
} |
Partager