1 package ij.plugin.filter;
10 Random r =
new Random();
16 public void run(ImageProcessor ip) {
20 public int rand(
int min,
int max) {
21 return min + (int)(r.nextDouble()*(max-min));
24 public void add(ImageProcessor ip,
double percent) {
25 Rectangle roi = ip.getRoi();
26 int n = (int)(percent*roi.width*roi.height);
27 byte[] pixels = (byte[])ip.getPixels();
29 int width = ip.getWidth();
31 int xmax = roi.x+roi.width-1;
33 int ymax = roi.y+roi.height-1;
35 for (
int i=0; i<n/2; i++) {
36 rx = rand(xmin, xmax);
37 ry = rand(ymin, ymax);
38 pixels[ry*width+rx] = (byte)255;
39 rx = rand(xmin, xmax);
40 ry = rand(ymin, ymax);
41 pixels[ry*width+rx] = (byte)0;