/** Returns a new ImageProcessor containing a scaled copy of this image or ROI, with the aspect ratio maintained. */ public ImageProcessor resize(int dstWidth) { return resize(dstWidth, (int)(dstWidth*((double)roiHeight/roiWidth))); }
/** Returns a new ImageProcessor containing a scaled copy of this image or ROI, with the aspect ratio maintained. */ public ImageProcessor resize(int dstWidth) { return resize(dstWidth, (int)(dstWidth*((double)roiHeight/roiWidth))); }
ImageProcessor shrink(ImageProcessor ip1, int w1, int h1, int w, int h){ if(ip1==null)return null; int wFinal,hFinal; if((((double)w)/w1) < (((double)h)/h1)){ //scale factor = w/w1 wFinal = w; hFinal = w*h1/w1; }else{ //scale factor = h/h1 wFinal = w1*h/h1; hFinal = h; } return ip1.resize(wFinal,hFinal); } void insert(ImageProcessor ip1temp, ImagePlus imp1){
public ImageProcessor resize(int dstWidth, int dstHeight) { record("resize", new Object[] {new Integer(dstWidth), new Integer(dstHeight)}, new Class[] {int.class, int.class}); return proc.resize(dstWidth, dstHeight); }
public ImageProcessor resize(int dstWidth, int dstHeight) { record("resize", new Object[] {new Integer(dstWidth), new Integer(dstHeight)}, new Class[] {int.class, int.class}); return proc.resize(dstWidth, dstHeight); }
public ImageProcessor resize(int dstWidth) { record("resize", new Integer(dstWidth), int.class); return proc.resize(dstWidth); }
public ImageProcessor resize(int dstWidth) { record("resize", new Integer(dstWidth), int.class); return proc.resize(dstWidth); }
ImageProcessor cropped = IJ.getImage().getProcessor().crop(); //image from currently selected roi ImageProcessor scaled = cropped.resize(cropped.getWidth()*2,cropped.getHeight()*2); //magnified image Overlay overlay = new Overlay(new ImageRoi(0,0, scaled)); IJ.getImage().setOverlay(overlay);
ImageProcessor resizeFilter(ImageProcessor ip, int maxN) { int width = ip.getWidth(); int height = ip.getHeight(); if (width==maxN && height==maxN) return ip; showStatus("Scaling filter to "+ maxN + "x" + maxN); return ip.resize(maxN, maxN); }
ImageProcessor resizeFilter(ImageProcessor ip, int maxN) { int width = ip.getWidth(); int height = ip.getHeight(); if (width==maxN && height==maxN) return ip; showStatus("Scaling filter to "+ maxN + "x" + maxN); return ip.resize(maxN, maxN); }
/** * Scale an image with good quality in both up and down direction */ final static public ImageProcessor scale( final ImageProcessor source, final float scale ) { if ( scale == 1.0f ) return source.duplicate(); else if ( scale < 1.0f ) return createDownsampled( source, scale, 0.5f, 0.5f ); else { source.setInterpolationMethod( ImageProcessor.BILINEAR ); return source.resize( Math.round( scale * source.getWidth() ) ); } }
import ij.IJ; import ij.ImagePlus; import ij.io.Opener; import ij.process.ImageProcessor; public class Resizer { public static void main(String[] args) { processPicture("X0aPT.jpg", "output.jpg", 0.0198, ImageProcessor.NONE, 0.3); } public static void processPicture(String inputFile, String outputFilePath, double scaleFactor, int interpolationMethod, double sigmaFactor) { Opener opener = new Opener(); ImageProcessor ip = opener.openImage(inputFile).getProcessor(); ip.blurGaussian(sigmaFactor / scaleFactor); ip.setInterpolationMethod(interpolationMethod); ImageProcessor outputProcessor = ip.resize((int)(ip.getWidth() * scaleFactor), (int)(ip.getHeight()*scaleFactor)); IJ.saveAs(new ImagePlus("", outputProcessor), outputFilePath.substring(outputFilePath.lastIndexOf('.')+1), outputFilePath); } }
static public ImageProcessor scaleImage(final ImagePlus imp, double mag, final boolean quality) { if (mag > 1) mag = 1; ImageProcessor ip = imp.getProcessor(); if (Math.abs(mag - 1) < 0.000001) return ip; // else, make a properly scaled image: // - gaussian blurred for best quality when resizing with nearest neighbor // - direct nearest neighbor otherwise final int w = ip.getWidth(); final int h = ip.getHeight(); // TODO releseToFit ! if (quality) { // apply proper gaussian filter final double sigma = Math.sqrt(Math.pow(2, getMipMapLevel(mag, Math.max(imp.getWidth(), imp.getHeight()))) - 0.25); // sigma = sqrt(level^2 - 0.5^2) ip = new FloatProcessorT2(w, h, ImageFilter.computeGaussianFastMirror(new FloatArray2D((float[])ip.convertToFloat().getPixels(), w, h), (float)sigma).data, ip.getDefaultColorModel(), ip.getMin(), ip.getMax()); ip = ip.resize((int)(w * mag), (int)(h * mag)); // better while float return Utils.convertTo(ip, imp.getType(), false); } else { return ip.resize((int)(w * mag), (int)(h * mag)); } }
static public ImageProcessor scaleImage(final ImagePlus imp, final int level, final boolean quality) { if (level <= 0) return imp.getProcessor(); // else, make a properly scaled image: // - gaussian blurred for best quality when resizing with nearest neighbor // - direct nearest neighbor otherwise ImageProcessor ip = imp.getProcessor(); final int w = ip.getWidth(); final int h = ip.getHeight(); final double mag = 1 / Math.pow(2, level); // TODO releseToFit ! if (quality) { // apply proper gaussian filter final double sigma = Math.sqrt(Math.pow(2, level) - 0.25); // sigma = sqrt(level^2 - 0.5^2) ip = new FloatProcessorT2(w, h, ImageFilter.computeGaussianFastMirror(new FloatArray2D((float[])ip.convertToFloat().getPixels(), w, h), (float)sigma).data, ip.getDefaultColorModel(), ip.getMin(), ip.getMax()); ip = ip.resize((int)(w * mag), (int)(h * mag)); // better while float return Utils.convertTo(ip, imp.getType(), false); } else { return ip.resize((int)(w * mag), (int)(h * mag)); } }
/** * Scale an image with good quality in both up and down direction */ final static public ImageProcessor scale( final ImageProcessor source, final float scale ) { final ImageProcessor target; if ( scale == 1.0f ) target = source.duplicate(); else if ( scale < 1.0f ) target = createDownsampled( source, scale, 0.5f, 0.5f ); else { source.setInterpolationMethod( ImageProcessor.BILINEAR ); target = source.resize( Math.round( scale * source.getWidth() ) ); } target.setMinAndMax( source.getMin(), source.getMax() ); return target; } }
public void setSlice(int index, ImageProcessor ip) { String name = preview.getSliceLabel(index); ImagePlus imp = new ImagePlus(name, ip); new FileSaver(imp).saveAsPng(dir + "/" + name); ip = ip.resize(w_prev).convertToByte(true); preview.setPixels(ip.getPixels(), index); }
/** * Compute the width of the images in imp, containing a stack, including scaling. * @param imp an ImageJ ImagePlus * @param scaleFactor the scaling factor. * @return the width of the images in imp. */ public static int getMatrixWidth(ImagePlus imp, double scaleFactor) { int width = imp.getWidth(); int height = imp.getHeight(); ImageProcessor ipp = imp.getStack().getProcessor(1); // Make sure resize using interpolation. ipp.setInterpolate(true); if (scaleFactor != 1f && scaleFactor != 0f) ipp = ipp.resize((int) (width * scaleFactor), (int) (height * scaleFactor)); return ipp.getWidth(); } /**
/** * downscale a grey scale float image using gaussian blur */ final static private ImageProcessor downScale( final ImageProcessor ip, final double s ) { final FloatArray2D g = new FloatArray2D( ip.getWidth(), ip.getHeight() ); ImageArrayConverter.imageProcessorToFloatArray2D( ip, g ); final float sigma = ( float )Math.sqrt( 0.25 * 0.25 / s / s - 0.25 ); final float[] kernel = Filter.createGaussianKernel( sigma, true ); final FloatArray2D h = Filter.convolveSeparable( g, kernel, kernel ); final FloatProcessor fp = new FloatProcessor( ip.getWidth(), ip.getHeight() ); ImageArrayConverter.floatArray2DToFloatProcessor( h, fp ); return ip.resize( ( int )( s * ip.getWidth() ) ); }
/** * downscale a grey scale float image using gaussian blur */ final static private ImageProcessor downScale( final ImageProcessor ip, final double s ) { final FloatArray2D g = new FloatArray2D( ip.getWidth(), ip.getHeight() ); ImageArrayConverter.imageProcessorToFloatArray2D( ip, g ); final float sigma = ( float )Math.sqrt( 0.25 * 0.25 / s / s - 0.25 ); final float[] kernel = Filter.createGaussianKernel( sigma, true ); final FloatArray2D h = Filter.convolveSeparable( g, kernel, kernel ); final FloatProcessor fp = new FloatProcessor( ip.getWidth(), ip.getHeight() ); ImageArrayConverter.floatArray2DToFloatProcessor( h, fp ); return ip.resize( ( int )( s * ip.getWidth() ) ); }
ImageProcessor getSlice(ImagePlus imp, double x1, double y1, double x2, double y2, String status) { Roi roi = imp.getRoi(); int roiType = roi!=null?roi.getType():0; ImageStack stack = imp.getStack(); int stackSize = stack.getSize(); ImageProcessor ip,ip2=null; float[] line = null; for (int i=0; i<stackSize; i++) { ip = stack.getProcessor(i+1); line = getLine(ip, x1, y1, x2, y2, line); if (i==0) ip2 = ip.createProcessor(line.length, stackSize); putRow(ip2, 0, i, line, line.length); if (status!=null) IJ.showStatus("Slicing: "+status +i+"/"+stackSize); } Calibration cal = imp.getCalibration(); double zSpacing = inputZSpacing/cal.pixelWidth; if (zSpacing!=1.0) { ip2.setInterpolate(true); ip2 = ip2.resize(line.length, (int)(stackSize*zSpacing)); } return ip2; }