public void noise(double standardDeviation) { if (rnd==null) rnd = new Random(); if (!Double.isNaN(seed)) rnd.setSeed((int) seed); seed = Double.NaN; for (int y=roiY; y<(roiY+roiHeight); y++) { int i = y * width + roiX; for (int x=roiX; x<(roiX+roiWidth); x++) { float RandomBrightness = (float)(rnd.nextGaussian()*standardDeviation); pixels[i] = pixels[i] + RandomBrightness; i++; } } resetMinAndMax(); }
final static public void floatArray2DToFloatProcessor( final FloatArray2D pixels, final FloatProcessor ip ) { float[] data = new float[ pixels.width * pixels.height ]; int count = 0; for ( int y = 0; y < pixels.height; y++ ) for ( int x = 0; x < pixels.width; x++ ) data[ count ] = pixels.data[ count++ ]; ip.setPixels( data ); ip.resetMinAndMax(); } }
public void noise(double standardDeviation) { if (rnd==null) rnd = new Random(); if (!Double.isNaN(seed)) rnd.setSeed((int) seed); seed = Double.NaN; for (int y=roiY; y<(roiY+roiHeight); y++) { int i = y * width + roiX; for (int x=roiX; x<(roiX+roiWidth); x++) { float RandomBrightness = (float)(rnd.nextGaussian()*standardDeviation); pixels[i] = pixels[i] + RandomBrightness; i++; } } resetMinAndMax(); }
final static public void floatArray2DToFloatProcessor( final FloatArray2D pixels, final FloatProcessor ip ) { float[] data = new float[ pixels.width * pixels.height ]; int count = 0; for ( int y = 0; y < pixels.height; y++ ) for ( int x = 0; x < pixels.width; x++ ) data[ count ] = pixels.data[ count++ ]; ip.setPixels( data ); ip.resetMinAndMax(); } }
/** Sets the min and max variables that control how real * pixel values are mapped to 0-255 screen values. Use * resetMinAndMax() to enable auto-scaling; * @see ij.plugin.frame.ContrastAdjuster */ public void setMinAndMax(double minimum, double maximum) { if (minimum==0.0 && maximum==0.0) { resetMinAndMax(); return; } min = (float)minimum; max = (float)maximum; fixedScale = true; minMaxSet = true; resetThreshold(); }
/** Sets the min and max variables that control how real * pixel values are mapped to 0-255 screen values. Use * resetMinAndMax() to enable auto-scaling; * @see ij.plugin.frame.ContrastAdjuster */ public void setMinAndMax(double minimum, double maximum) { if (minimum==0.0 && maximum==0.0) { resetMinAndMax(); return; } min = (float)minimum; max = (float)maximum; fixedScale = true; minMaxSet = true; resetThreshold(); }
public static ImagePlus FloatArrayToImagePlus(FloatArray2D image, String name, float min, float max) { ImagePlus imp = IJ.createImage(name,"32-Bit Black", image.width, image.height, 1); FloatProcessor ip = (FloatProcessor)imp.getProcessor(); FloatArrayToFloatProcessor(ip, image); if (min == max) ip.resetMinAndMax(); else ip.setMinAndMax(min, max); imp.updateAndDraw(); return imp; }
final static public ImagePlus FloatArrayToImagePlus( final FloatArray2D image, final String name, final float min, final float max ) { final ImagePlus imp = IJ.createImage( name, "32-Bit Black", image.width, image.height, 1 ); final FloatProcessor ip = ( FloatProcessor )imp.getProcessor(); floatArray2DToFloatProcessor( image, ip ); if ( min == max ) ip.resetMinAndMax(); else ip.setMinAndMax( min, max ); imp.updateAndDraw(); return imp; }
final static public ImagePlus FloatArrayToImagePlus( final FloatArray2D image, final String name, final float min, final float max ) { final ImagePlus imp = IJ.createImage( name, "32-Bit Black", image.width, image.height, 1 ); final FloatProcessor ip = ( FloatProcessor )imp.getProcessor(); floatArray2DToFloatProcessor( image, ip ); if ( min == max ) ip.resetMinAndMax(); else ip.setMinAndMax( min, max ); imp.updateAndDraw(); return imp; }
/** * Normalize float image so the pixel are between 0 and 1 * @param fp input image */ public static void normalize01( FloatProcessor fp ) { fp.resetMinAndMax(); double max = fp.getMax(); double min = fp.getMin(); double scale = max>min?1.0/(max-min):1.0; int size = fp.getWidth()*fp.getHeight(); float[] pixels = (float[])fp.getPixels(); double v; for (int i=0; i<size; i++) { v = pixels[i] - min; if (v<0.0) v = 0.0; v *= scale; if (v>1.0) v = 1.0; pixels[i] = (float)v; } }
/** * This method converts my FloatArray2D to an ImageJ ImagePlus * * @param image The image as FloatArray2D * @param name The name of the ImagePlus * @param min Lowest brightness value that will be displayed (see Brightness&Contrast in Imagej) * @param max Highest brightness value that will be displayed (set both to zero for automatic) * @return ImagePlus The ImageJ image */ public static ImagePlus FloatArrayToImagePlus(FloatArray2D image, String name, float min, float max) { ImagePlus imp = IJ.createImage(name,"32-Bit Black", image.width, image.height, 1); FloatProcessor ip = (FloatProcessor)imp.getProcessor(); FloatArrayToFloatProcessor(ip, image); if (min == max) ip.resetMinAndMax(); else ip.setMinAndMax(min, max); imp.updateAndDraw(); return imp; }
/** * Show an image in a new bUnwarpJ window. * * @param title image title * @param array image in a double array */ public static void showImage( final String title, final double [][]array) { int Ydim=array.length; int Xdim=array[0].length; final FloatProcessor fp=new FloatProcessor(Xdim,Ydim); for (int i=0; i<Ydim; i++) for (int j=0; j<Xdim; j++) fp.setf(j,i, (float) array[i][j]); fp.resetMinAndMax(); final ImagePlus ip=new ImagePlus(title, fp); ip.updateImage(); ip.show(); } // end showImage
/** * This method converts my FloatArray2D to an ImageJ ImagePlus * * @param image The image as FloatArray2D * @param name The name of the ImagePlus * @param min Lowest brightness value that will be displayed (see Brightness&Contrast in Imagej) * @param max Highest brightness value that will be displayed (set both to zero for automatic) * @return ImagePlus The ImageJ image * * @author Stephan Preibisch */ private ImagePlus FloatArrayToImagePlus(FloatArray2D image, String name, float min, float max) { ImagePlus imp = IJ.createImage(name, "32-Bit Black", image.width, image.height, 1); FloatProcessor ip = (FloatProcessor) imp.getProcessor(); FloatArrayToFloatProcessor(ip, image); if (min == max) ip.resetMinAndMax(); else ip.setMinAndMax(min, max); imp.updateAndDraw(); return imp; }
/** * Normalize float image so the pixel are between 0 and 1 * @param fp input image */ public static void normalize01( FloatProcessor fp ) { fp.resetMinAndMax(); double max = fp.getMax(); double min = fp.getMin(); double scale = max>min?1.0/(max-min):1.0; int size = fp.getWidth()*fp.getHeight(); float[] pixels = (float[])fp.getPixels(); double v; for (int i=0; i<size; i++) { v = pixels[i] - min; if (v<0.0) v = 0.0; v *= scale; if (v>1.0) v = 1.0; pixels[i] = (float)v; } }
/** * Show an image in a new bUnwarpJ window. * * @param title image title * @param array image in a double array * @param Ydim image height * @param Xdim image width */ public static void showImage( final String title, final double [] array, final int Ydim, final int Xdim) { final FloatProcessor fp=new FloatProcessor(Xdim,Ydim); int ij=0; for (int i=0; i<Ydim; i++) for (int j=0; j<Xdim; j++, ij++) fp.setf(j,i, (float) array[ij]); fp.resetMinAndMax(); final ImagePlus ip=new ImagePlus(title, fp); ip.updateImage(); ip.show(); }
public ImagePlus imageplus() { final ImageStack imagestack = new ImageStack(dims.x,dims.y); for (int t=0; t<dims.t; ++t) for (int z=0; z<dims.z; ++z) for (int c=0; c<dims.c; ++c) imagestack.addSlice("",elements[c][t][z]); final FloatProcessor minmax = new FloatProcessor(2,1); final double[] evals = extrema(); minmax.putPixelValue(0,0,evals[0]); minmax.putPixelValue(1,0,evals[1]); minmax.resetMinAndMax(); imagestack.update(minmax); final Calibration cal = new Calibration(); cal.pixelWidth = aspects.x; cal.pixelHeight = aspects.y; cal.pixelDepth = aspects.z; cal.frameInterval = aspects.t; ImagePlus imageplus = new ImagePlus(name,imagestack); imageplus.setDimensions(dims.c,dims.z,dims.t); imageplus.setCalibration(cal); return imageplus; }
public ImagePlus imageplus() { final ImageStack imagestack = new ImageStack(dims.x,dims.y); for (int t=0; t<dims.t; ++t) for (int z=0; z<dims.z; ++z) for (int c=0; c<dims.c; ++c) imagestack.addSlice("",elements[c][t][z]); final FloatProcessor minmax = new FloatProcessor(2,1); final double[] evals = extrema(); minmax.putPixelValue(0,0,evals[0]); minmax.putPixelValue(1,0,evals[1]); minmax.resetMinAndMax(); imagestack.update(minmax); final Calibration cal = new Calibration(); cal.pixelWidth = aspects.x; cal.pixelHeight = aspects.y; cal.pixelDepth = aspects.z; cal.frameInterval = aspects.t; ImagePlus imageplus = new ImagePlus(name,imagestack); imageplus.setDimensions(dims.c,dims.z,dims.t); imageplus.setCalibration(cal); return imageplus; }
fp.resetMinAndMax(); sourceImp.setProcessor(sourceImp.getTitle(), fp); sourceImp.updateAndDraw(); fp.resetMinAndMax(); targetImp.setProcessor(targetImp.getTitle(), fp); targetImp.updateAndDraw();
if (imp.getCalibration().isSigned16Bit()) fp.subtract(sliceCount*32768.0); fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else if (method==SD_METHOD) { rayFunc.postProcess(); fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else {
if (imp.getCalibration().isSigned16Bit()) fp.subtract(sliceCount*32768.0); fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else if (method==SD_METHOD) { rayFunc.postProcess(); fp.resetMinAndMax(); projImage = new ImagePlus(makeTitle(), fp); } else {