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
| /**
* @author millie
*
*/
public class GaussianNoiseGenerator extends ImageOperator {
private Random gauss = new Random();
private Random sign = new Random();
private double sigma;
private double mean;
private double getGaussian() {
return gauss.nextGaussian() * sigma + mean;
}
public GaussianNoiseGenerator(double sigma, double mean) {
this.sigma = sigma;
this.mean = mean;
}
/* (non-Javadoc)
* @see millie.operator.commons.point.PointOperator#computePoint(double)
*/
@Override
public double computePoint(double point) {
int s = sign.nextInt(2);
if(s==0)
s--;
return point + getGaussian() * s;
}
}
public void compute(Image out, Image in, PointOperator op) {
if (out.getNumComponents() != in.getNumComponents())
throw new IllegalArgumentException(
"PointOperator : num components problem");
out.resize(in.getWidth(), in.getHeight());
for (int canal = 0; canal < in.getNumComponents(); canal++)
for (int y = 0; y < in.getHeight(); y++)
for (int x = 0; x < in.getWidth(); x++)
out.setPixel(x, y, canal, op.computePoint(in.getPixel(x, y,
canal)));
} |
Partager