Adds pseudorandom, Gaussian ("normally") distributed values, with mean 0.0 and the specified standard deviation, to this image or ROI.
(double standardDeviation)
| 870 | /** Adds pseudorandom, Gaussian ("normally") distributed values, with |
| 871 | mean 0.0 and the specified standard deviation, to this image or ROI. */ |
| 872 | public void noise(double standardDeviation) { |
| 873 | if (rnd==null) |
| 874 | rnd = new Random(); |
| 875 | if (!Double.isNaN(seed)) |
| 876 | rnd.setSeed((int)seed); |
| 877 | seed = Double.NaN; |
| 878 | int v, ran; |
| 879 | boolean inRange; |
| 880 | for (int y=roiY; y<(roiY+roiHeight); y++) { |
| 881 | int i = y * width + roiX; |
| 882 | for (int x=roiX; x<(roiX+roiWidth); x++) { |
| 883 | inRange = false; |
| 884 | do { |
| 885 | ran = (int)Math.round(rnd.nextGaussian()*standardDeviation); |
| 886 | v = (pixels[i] & 0xff) + ran; |
| 887 | inRange = v>=0 && v<=255; |
| 888 | if (inRange) pixels[i] = (byte)v; |
| 889 | } while (!inRange); |
| 890 | i++; |
| 891 | } |
| 892 | } |
| 893 | } |
| 894 | |
| 895 | |
| 896 | /** Scales the image or selection using the specified scale factors. |
no test coverage detected