/** Create background for a float image by rolling a ball over * the image. */ void rollingBallFloatBackground(FloatProcessor fp, float radius, boolean invert, boolean doPresmooth, RollingBall ball) { float[] pixels = (float[])fp.getPixels(); //this will become the background boolean shrink = ball.shrinkFactor >1; showProgress(0.0); if (invert) for (int i=0; i<pixels.length; i++) pixels[i] = -pixels[i]; if (doPresmooth) filter3x3(fp, MEAN); double[] minmax = Tools.getMinMax(pixels); if (Thread.currentThread().isInterrupted()) return; FloatProcessor smallImage = shrink ? shrinkImage(fp, ball.shrinkFactor) : fp; if (Thread.currentThread().isInterrupted()) return; rollBall(ball, smallImage); if (Thread.currentThread().isInterrupted()) return; showProgress(0.9); if (shrink) enlargeImage(smallImage, fp, ball.shrinkFactor); if (Thread.currentThread().isInterrupted()) return; if (invert) for (int i=0; i<pixels.length; i++) pixels[i] = -pixels[i]; pass++; }
/** Create background for a float image by rolling a ball over * the image. */ void rollingBallFloatBackground(FloatProcessor fp, float radius, boolean invert, boolean doPresmooth, RollingBall ball) { float[] pixels = (float[])fp.getPixels(); //this will become the background boolean shrink = ball.shrinkFactor >1; showProgress(0.0); if (invert) for (int i=0; i<pixels.length; i++) pixels[i] = -pixels[i]; if (doPresmooth) filter3x3(fp, MEAN); double[] minmax = Tools.getMinMax(pixels); if (Thread.currentThread().isInterrupted()) return; FloatProcessor smallImage = shrink ? shrinkImage(fp, ball.shrinkFactor) : fp; if (Thread.currentThread().isInterrupted()) return; rollBall(ball, smallImage); if (Thread.currentThread().isInterrupted()) return; showProgress(0.9); if (shrink) enlargeImage(smallImage, fp, ball.shrinkFactor); if (Thread.currentThread().isInterrupted()) return; if (invert) for (int i=0; i<pixels.length; i++) pixels[i] = -pixels[i]; pass++; }
lastTime = time; if (thread.isInterrupted()) return; showProgress(0.1+0.8*y/(height+ballWidth));
lastTime = time; if (thread.isInterrupted()) return; showProgress(0.1+0.8*y/(height+ballWidth));
if (i%50==0) { if (Thread.currentThread().isInterrupted()) return; showProgress(i/(double)nLines);
if (i%50==0) { if (Thread.currentThread().isInterrupted()) return; showProgress(i/(double)nLines);
/** Creates a lower resolution image for ball-rolling. */ FloatProcessor shrinkImage(FloatProcessor ip, int shrinkFactor) { int width = ip.getWidth(); int height = ip.getHeight(); float[] pixels = (float[])ip.getPixels(); int sWidth = (width+shrinkFactor-1)/shrinkFactor; int sHeight = (height+shrinkFactor-1)/shrinkFactor; showProgress(0.1); FloatProcessor smallImage = new FloatProcessor(sWidth, sHeight); float[] sPixels = (float[])smallImage.getPixels(); float min, thispixel; for (int ySmall=0; ySmall<sHeight; ySmall++) { for (int xSmall=0; xSmall<sWidth; xSmall++) { min = Float.MAX_VALUE; for (int j=0, y=shrinkFactor*ySmall; j<shrinkFactor&&y<height; j++, y++) { for (int k=0, x=shrinkFactor*xSmall; k<shrinkFactor&&x<width; k++, x++) { thispixel = pixels[x+y*width]; if (thispixel<min) min = thispixel; } } sPixels[xSmall+ySmall*sWidth] = min; // each point in small image is minimum of its neighborhood } } //new ImagePlus("smallImage", smallImage).show(); return smallImage; }
/** Creates a lower resolution image for ball-rolling. */ FloatProcessor shrinkImage(FloatProcessor ip, int shrinkFactor) { int width = ip.getWidth(); int height = ip.getHeight(); float[] pixels = (float[])ip.getPixels(); int sWidth = (width+shrinkFactor-1)/shrinkFactor; int sHeight = (height+shrinkFactor-1)/shrinkFactor; showProgress(0.1); FloatProcessor smallImage = new FloatProcessor(sWidth, sHeight); float[] sPixels = (float[])smallImage.getPixels(); float min, thispixel; for (int ySmall=0; ySmall<sHeight; ySmall++) { for (int xSmall=0; xSmall<sWidth; xSmall++) { min = Float.MAX_VALUE; for (int j=0, y=shrinkFactor*ySmall; j<shrinkFactor&&y<height; j++, y++) { for (int k=0, x=shrinkFactor*xSmall; k<shrinkFactor&&x<width; k++, x++) { thispixel = pixels[x+y*width]; if (thispixel<min) min = thispixel; } } sPixels[xSmall+ySmall*sWidth] = min; // each point in small image is minimum of its neighborhood } } //new ImagePlus("smallImage", smallImage).show(); return smallImage; }
float coeff2diag = 1.f/radius; //same for diagonal directions where step is sqrt2 showProgress(0.000001); //start the progress bar (only filter1D will increment it) if (invert) for (int i=0; i<pixels.length; i++) if (doPresmooth) { shiftBy = (float)filter3x3(fp, MAXIMUM);//3x3 maximum to remove dust etc. showProgress(0.5);
float coeff2diag = 1.f/radius; //same for diagonal directions where step is sqrt2 showProgress(0.000001); //start the progress bar (only filter1D will increment it) if (invert) for (int i=0; i<pixels.length; i++) if (doPresmooth) { shiftBy = (float)filter3x3(fp, MAXIMUM);//3x3 maximum to remove dust etc. showProgress(0.5);