@Override public ImageProcessor crop() { record("crop"); return proc.crop(); }
@Override public ImageProcessor crop() { record("crop"); return proc.crop(); }
ImageProcessor ip = //... get the image processor to crop ip.setRoi(left,top,width,height); //set the "Region Of Interest" (rectangle within the image) ImageProcessor ip2 = ip.crop();
public static ImageProcessor crop(ImageProcessor ip, Rectangle rect) { ip.setRoi(rect); return ip.crop(); }
// works all the same for: byte, short, int float[] myData; // create a new image. change 32 to 16 for short or 8 for byte ImageStack stack = ImageStack.create(width, height, 1, 32); stack.setPixels(myData, 1); ImageProcessor processor = new ImagePlus("", stack).getProcessor(); // crop and scale processor.setRoi(x, y, rwidth, rheight); ImageProcessor result = processor.crop().resize(newWidth, newHeight); // retrieve results float[] myScaledData = (float[]) result.getPixels();
/** Creates a new stack by cropping this one. */ public ImageStack crop(int x, int y, int z, int width, int height, int depth) { if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>getSize()) throw new IllegalArgumentException("Argument out of range"); ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=z; i<z+depth; i++) { ImageProcessor ip2 = this.getProcessor(i+1); ip2.setRoi(x, y, width, height); ip2 = ip2.crop(); stack2.addSlice(this.getSliceLabel(i+1), ip2); } return stack2; }
double getColorValue(Color color) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null || imp.getBitDepth()==24) return color.getRGB()&0xffffff; ImageProcessor ip = imp.getProcessor(); ip.setRoi(0,0,1,1); ip = ip.crop(); ip.setColor(color); ip.drawDot(0,0); return ip.getf(0,0); }
/** Creates a new stack by cropping this one. */ public ImageStack crop(int x, int y, int z, int width, int height, int depth) { if (x<0||y<0||z<0||x+width>this.width||y+height>this.height||z+depth>getSize()) throw new IllegalArgumentException("Argument out of range"); ImageStack stack2 = new ImageStack(width, height, getColorModel()); for (int i=z; i<z+depth; i++) { ImageProcessor ip2 = this.getProcessor(i+1); ip2.setRoi(x, y, width, height); ip2 = ip2.crop(); stack2.addSlice(this.getSliceLabel(i+1), ip2); } return stack2; }
double getColorValue(Color color) { ImagePlus imp = WindowManager.getCurrentImage(); if (imp==null || imp.getBitDepth()==24) return color.getRGB()&0xffffff; ImageProcessor ip = imp.getProcessor(); ip.setRoi(0,0,1,1); ip = ip.crop(); ip.setColor(color); ip.drawDot(0,0); return ip.getf(0,0); }
ImageProcessor trimPlot(ImageProcessor plot, int maxTrim) { int background = plot.getPixel(0, 0); int width = plot.getWidth(); int height = plot.getHeight(); int trim = maxTrim-5; a: for (int y=0; y<(maxTrim-5); y++) for (int x=0; x<width; x++) if (plot.getPixel(x,y)!=background) {trim = y-5; break a;} if (trim>10) { plot.setRoi(0, trim, width, height-trim); plot = plot.crop(); } return plot; }
ImageProcessor trimPlot(ImageProcessor plot, int maxTrim) { int background = plot.getPixel(0, 0); int width = plot.getWidth(); int height = plot.getHeight(); int trim = maxTrim-5; a: for (int y=0; y<(maxTrim-5); y++) for (int x=0; x<width; x++) if (plot.getPixel(x,y)!=background) {trim = y-5; break a;} if (trim>10) { plot.setRoi(0, trim, width, height-trim); plot = plot.crop(); } return plot; }
private void addMean(int column, int start) { double value = Double.NaN; if (start!=-1) { float[] c = column>=0?rt.getColumn(column):null; if (c!=null) { ImageProcessor ip = new FloatProcessor(c.length, 1, c, null); if (ip==null) return; ip.setRoi(start, 0, ip.getWidth()-start, 1); ip = ip.crop(); ImageStatistics stats = new FloatStatistics(ip); if (stats==null) return; value = stats.mean; } } summaryTable.addValue(ResultsTable.getDefaultHeading(column), value); }
private ImageStatistics RGBHistogram(ImagePlus imp, int bins, double histMin, double histMax) { ImageProcessor ip = (ColorProcessor)imp.getProcessor(); ip = ip.crop(); int w = ip.getWidth(); int h = ip.getHeight(); ImageProcessor ip2 = new ByteProcessor(w*3, h); ByteProcessor temp = null; for (int i=0; i<3; i++) { temp = ((ColorProcessor)ip).getChannel(i+1,temp); ip2.insert(temp, i*w, 0); } ImagePlus imp2 = new ImagePlus("imp2", ip2); return imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); }
private ImageStatistics RGBHistogram(ImagePlus imp, int bins, double histMin, double histMax) { ImageProcessor ip = (ColorProcessor)imp.getProcessor(); ip = ip.crop(); int w = ip.getWidth(); int h = ip.getHeight(); ImageProcessor ip2 = new ByteProcessor(w*3, h); ByteProcessor temp = null; for (int i=0; i<3; i++) { temp = ((ColorProcessor)ip).getChannel(i+1,temp); ip2.insert(temp, i*w, 0); } ImagePlus imp2 = new ImagePlus("imp2", ip2); return imp2.getStatistics(AREA+MEAN+MODE+MIN_MAX, bins, histMin, histMax); }
private void addMean(int column, int start) { double value = Double.NaN; if (start!=-1) { float[] c = column>=0?rt.getColumn(column):null; if (c!=null) { ImageProcessor ip = new FloatProcessor(c.length, 1, c, null); if (ip==null) return; ip.setRoi(start, 0, ip.getWidth()-start, 1); ip = ip.crop(); ImageStatistics stats = new FloatStatistics(ip); if (stats==null) return; value = stats.mean; } } summaryTable.addValue(ResultsTable.getDefaultHeading(column), value); }
public ImageStack makeStack(ImageProcessor ip, int rows, int columns, int border) { int stackSize = rows*columns; int width = ip.getWidth()/columns; int height = ip.getHeight()/rows; //IJ.log("makeStack: "+rows+" "+columns+" "+border+" "+width+" "+height); ImageStack stack = new ImageStack(width, height); for (int y=0; y<rows; y++) for (int x=0; x<columns; x++) { ip.setRoi(x*width, y*height, width, height); stack.addSlice(null, ip.crop()); } if (border>0) { int cropwidth = width-border-border/2; int cropheight = height-border-border/2; StackProcessor sp = new StackProcessor(stack,ip); stack = sp.crop(border, border, cropwidth, cropheight); } return stack; } }
/** Crops the stack to the specified rectangle. */ public ImageStack crop(int x, int y, int width, int height) { ImageStack stack2 = new ImageStack(width, height); ImageProcessor ip2; for (int i=1; i<=nSlices; i++) { ImageProcessor ip1 = stack.getProcessor(1); ip1.setRoi(x, y, width, height); String label = stack.getSliceLabel(1); stack.deleteSlice(1); ip2 = ip1.crop(); stack2.addSlice(label, ip2); IJ.showProgress((double)i/nSlices); } IJ.showProgress(1.0); return stack2; }
/** Converts the stack to 8-bits indexed color. 'nColors' must be greater than 1 and less than or equal to 256. */ public void convertToIndexedColor(int nColors) { if (type!=ImagePlus.COLOR_RGB) throw new IllegalArgumentException("RGB stack required"); ImageStack stack = imp.getStack(); int size = stack.getSize(); ImageProcessor montage = new ColorProcessor(width*size, height); for (int i=0; i<size; i++) montage.insert(stack.getProcessor(i+1), i*width, 0); MedianCut mc = new MedianCut((ColorProcessor)montage); montage = mc.convertToByte(nColors); ImageStack stack2 = new ImageStack(width, height); for (int i=0; i<size; i++) { montage.setRoi(i*width, 0, width, height); stack2.addSlice(null, montage.crop()); } imp.setStack(null, stack2); }
/** Crops the stack to the specified rectangle. */ public ImageStack crop(int x, int y, int width, int height) { ImageStack stack2 = new ImageStack(width, height); ImageProcessor ip2; for (int i=1; i<=nSlices; i++) { ImageProcessor ip1 = stack.getProcessor(1); ip1.setRoi(x, y, width, height); String label = stack.getSliceLabel(1); stack.deleteSlice(1); ip2 = ip1.crop(); stack2.addSlice(label, ip2); IJ.showProgress((double)i/nSlices); } IJ.showProgress(1.0); return stack2; }
private FloatProcessor getRoiProcessor(ImagePlus imp, Roi roi, int index) { ImageProcessor ip = imp.getStack().getProcessor(index); ip.setRoi(roi.getBounds()); FloatProcessor fp = subtract(ip.crop().convertToFloatProcessor(), (float) CameraSetupPlugIn.getOffset()); float minVal = VectorMath.min((float[]) fp.getPixels()); if(minVal < 0) { IJ.log("\\Update:Camera base level is set higher than values in the image!"); fp = add(-minVal, fp); } fp.setMask(roi.getMask()); return fp; }