public void setInterpolate(boolean interpolate) { record("setInterpolate", new Boolean(interpolate), boolean.class); proc.setInterpolate(interpolate); }
public void setInterpolate(boolean interpolate) { record("setInterpolate", new Boolean(interpolate), boolean.class); proc.setInterpolate(interpolate); }
public static double[] getColumnAverageProfile(Rectangle rect, ImageProcessor ip) { double[] profile = new double[rect.width]; int[] counts = new int[rect.width]; double[] aLine; ip.setInterpolate(false); for (int y=rect.y; y<rect.y+rect.height; y++) { aLine = ip.getLine(rect.x, y, rect.x+rect.width-1, y); for (int i=0; i<rect.width; i++) { if (!Double.isNaN(aLine[i])) { profile[i] += aLine[i]; counts[i]++; } } } for (int i=0; i<rect.width; i++) profile[i] /= counts[i]; return profile; }
double[] getRowAverageProfile(Rectangle rect, Calibration cal, ImageProcessor ip) { double[] profile = new double[rect.height]; int[] counts = new int[rect.height]; double[] aLine; ip.setInterpolate(false); for (int x=rect.x; x<rect.x+rect.width; x++) { aLine = ip.getLine(x, rect.y, x, rect.y+rect.height-1); for (int i=0; i<rect.height; i++) { if (!Double.isNaN(aLine[i])) { profile[i] += aLine[i]; counts[i]++; } } } for (int i=0; i<rect.height; i++) profile[i] /= counts[i]; if (cal!=null) xInc = cal.pixelHeight; return profile; }
public static double[] getColumnAverageProfile(Rectangle rect, ImageProcessor ip) { double[] profile = new double[rect.width]; int[] counts = new int[rect.width]; double[] aLine; ip.setInterpolate(false); for (int y=rect.y; y<rect.y+rect.height; y++) { aLine = ip.getLine(rect.x, y, rect.x+rect.width-1, y); for (int i=0; i<rect.width; i++) { if (!Double.isNaN(aLine[i])) { profile[i] += aLine[i]; counts[i]++; } } } for (int i=0; i<rect.width; i++) profile[i] /= counts[i]; return profile; }
double[] getRowAverageProfile(Rectangle rect, Calibration cal, ImageProcessor ip) { double[] profile = new double[rect.height]; int[] counts = new int[rect.height]; double[] aLine; ip.setInterpolate(false); for (int x=rect.x; x<rect.x+rect.width; x++) { aLine = ip.getLine(x, rect.y, x, rect.y+rect.height-1); for (int i=0; i<rect.height; i++) { if (!Double.isNaN(aLine[i])) { profile[i] += aLine[i]; counts[i]++; } } } for (int i=0; i<rect.height; i++) profile[i] /= counts[i]; if (cal!=null) xInc = cal.pixelHeight; return profile; }
double[] getStraightLineProfile(Roi roi, Calibration cal, ImageProcessor ip) { ip.setInterpolate(PlotWindow.interpolate); Line line = (Line)roi; double[] values = line.getPixels(); if (values==null) return null; if (cal!=null && cal.pixelWidth!=cal.pixelHeight) { FloatPolygon p = line.getFloatPoints(); double dx = p.xpoints[1] - p.xpoints[0]; double dy = p.ypoints[1] - p.ypoints[0]; double pixelLength = Math.sqrt(dx*dx + dy*dy); dx = cal.pixelWidth*dx; dy = cal.pixelHeight*dy; double calibratedLength = Math.sqrt(dx*dx + dy*dy); xInc = calibratedLength * 1.0/pixelLength; } return values; }
double[] getStraightLineProfile(Roi roi, Calibration cal, ImageProcessor ip) { ip.setInterpolate(PlotWindow.interpolate); Line line = (Line)roi; double[] values = line.getPixels(); if (values==null) return null; if (cal!=null && cal.pixelWidth!=cal.pixelHeight) { FloatPolygon p = line.getFloatPoints(); double dx = p.xpoints[1] - p.xpoints[0]; double dy = p.ypoints[1] - p.ypoints[0]; double pixelLength = Math.sqrt(dx*dx + dy*dy); dx = cal.pixelWidth*dx; dy = cal.pixelHeight*dy; double calibratedLength = Math.sqrt(dx*dx + dy*dy); xInc = calibratedLength * 1.0/pixelLength; } return values; }
/** * Convert the data in the ImageStack in imp into a float[][] matrix * and scale by scaleFactor on the fly. Do not use Roi. * @param imp the imageplus containing the stack. * @param i the image number in the stack, starting with 0. * @param scaleFactor the scaling factor. * @return a float[] with the image as a vector. */ public static float [] vectorFromImageStack(ImagePlus imp, int i, float scaleFactor) { float [] a = null; try { int width = imp.getWidth(); int height = imp.getHeight(); // Make a matrix out of the images in the stack. Take care of the ROI. ImageProcessor ipp = imp.getStack().getProcessor(i+1); // Make sure resize using interpolation. ipp.setInterpolate(true); if (scaleFactor != 1f) ipp = ipp.resize((int) (width * scaleFactor), (int) (height * scaleFactor)); a = getFloatPixels(ipp.getPixels()); } catch (Exception e) { CharArrayWriter c = new CharArrayWriter(); e.printStackTrace(new PrintWriter(c)); IJ.write(c.toString()); } return a; } /**
public void draw(Graphics g) { Graphics2D g2d = (Graphics2D)g; double mag = getMagnification(); int sx2 = screenX(x+width); int sy2 = screenY(y+height); Composite saveComposite = null; if (composite!=null) { saveComposite = g2d.getComposite(); g2d.setComposite(composite); } Image img2 = img; if (angle!=0.0) { ImageProcessor ip = new ColorProcessor(img); ip.setInterpolate(true); ip.setBackgroundValue(0.0); ip.rotate(angle); if (zeroTransparent) ip = makeZeroTransparent(ip, true); img2 = ip.createImage(); } g.drawImage(img2, screenX(x), screenY(y), sx2, sy2, 0, 0, img.getWidth(null), img.getHeight(null), null); if (composite!=null) g2d.setComposite(saveComposite); if (isActiveOverlayRoi() && !overlay) super.draw(g); }
public void draw(Graphics g) { Graphics2D g2d = (Graphics2D)g; double mag = getMagnification(); int sx2 = screenX(x+width); int sy2 = screenY(y+height); Composite saveComposite = null; if (composite!=null) { saveComposite = g2d.getComposite(); g2d.setComposite(composite); } Image img2 = img; if (angle!=0.0) { ImageProcessor ip = new ColorProcessor(img); ip.setInterpolate(true); ip.setBackgroundValue(0.0); ip.rotate(angle); if (zeroTransparent) ip = makeZeroTransparent(ip, true); img2 = ip.createImage(); } g.drawImage(img2, screenX(x), screenY(y), sx2, sy2, 0, 0, img.getWidth(null), img.getHeight(null), null); if (composite!=null) g2d.setComposite(saveComposite); if (isActiveOverlayRoi() && !overlay) super.draw(g); }
int width = ip.getWidth(); int height = ip.getHeight(); ip.setInterpolate(true); ip = ip.resize((int)(width*scale),(int)(height*scale)); img.setProcessor(null,ip);
/** * Convert the data in the ImageStack in imp into a float[][] matrix * and scale by scaleFactor on the fly. Do not use Roi. * @param imp an ImagePlus * @param scaleFactor the scalefactor between 100-0.01. * @return a float[][] with the images. */ public static float [][] matrixFromImageStack(ImagePlus imp, double scaleFactor) { float [][] a = new float[imp.getStackSize()][]; try{ int width = imp.getWidth(); int height = imp.getHeight(); IJ.showStatus("Downsampling images "+width*scaleFactor+" x "+height*scaleFactor); // Make a matrix out of the images in the stack. Take care of the ROI. for (int i = 0; i < imp.getStackSize(); i++) { ImageProcessor ipp = imp.getStack().getProcessor(i+1); // Make sure resize using interpolation. ipp.setInterpolate(true); if (scaleFactor != 1f) ipp = ipp.resize((int) (width * scaleFactor), (int) (height * scaleFactor)); a[i] = (float []) (ipp.convertToFloat()).getPixels(); } }catch (Exception e) { CharArrayWriter c = new CharArrayWriter(); e.printStackTrace(new PrintWriter(c)); IJ.write(c.toString()); } return a; } /**
/** * 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(); } /**
/** Returns the pixel values along this line. */ public double[] getPixels() { double[] profile; if (getStrokeWidth()<=1) { ImageProcessor ip = imp.getProcessor(); profile = ip.getLine(x1d, y1d, x2d, y2d); } else { ImageProcessor ip2 = (new Straightener()).rotateLine(imp,(int)getStrokeWidth()); if (ip2==null) return new double[0]; int width = ip2.getWidth(); int height = ip2.getHeight(); if (ip2 instanceof FloatProcessor) return ProfilePlot.getColumnAverageProfile(new Rectangle(0,0,width,height),ip2); profile = new double[width]; double[] aLine; ip2.setInterpolate(false); for (int y=0; y<height; y++) { aLine = ip2.getLine(0, y, width-1, y); for (int i=0; i<width; i++) profile[i] += aLine[i]; } for (int i=0; i<width; i++) profile[i] /= height; } return profile; }
/** Returns the pixel values along this line. */ public double[] getPixels() { double[] profile; if (getStrokeWidth()<=1) { ImageProcessor ip = imp.getProcessor(); profile = ip.getLine(x1d, y1d, x2d, y2d); } else { ImageProcessor ip2 = (new Straightener()).rotateLine(imp,(int)getStrokeWidth()); if (ip2==null) return new double[0]; int width = ip2.getWidth(); int height = ip2.getHeight(); if (ip2 instanceof FloatProcessor) return ProfilePlot.getColumnAverageProfile(new Rectangle(0,0,width,height),ip2); profile = new double[width]; double[] aLine; ip2.setInterpolate(false); for (int y=0; y<height; y++) { aLine = ip2.getLine(0, y, width-1, y); for (int i=0; i<width; i++) profile[i] += aLine[i]; } for (int i=0; i<width; i++) profile[i] /= height; } return profile; }
double[] getWideLineProfile(ImagePlus imp, int lineWidth) { Roi roi = (Roi)imp.getRoi().clone(); ImageProcessor ip2 = (new Straightener()).straightenLine(imp, lineWidth); int width = ip2.getWidth(); int height = ip2.getHeight(); if (ip2 instanceof FloatProcessor) return getColumnAverageProfile(new Rectangle(0,0,width,height),ip2); profile = new double[width]; double[] aLine; ip2.setInterpolate(false); for (int y=0; y<height; y++) { aLine = ip2.getLine(0, y, width-1, y); for (int i=0; i<width; i++) profile[i] += aLine[i]; } for (int i=0; i<width; i++) profile[i] /= height; imp.setRoi(roi); if (roi.getType()==Roi.POLYLINE&& !((PolygonRoi)roi).isSplineFit()) { ((PolygonRoi)roi).fitSpline(); imp.draw(); } return profile; }
double[] getWideLineProfile(ImagePlus imp, int lineWidth) { Roi roi = (Roi)imp.getRoi().clone(); ImageProcessor ip2 = (new Straightener()).straightenLine(imp, lineWidth); int width = ip2.getWidth(); int height = ip2.getHeight(); if (ip2 instanceof FloatProcessor) return getColumnAverageProfile(new Rectangle(0,0,width,height),ip2); profile = new double[width]; double[] aLine; ip2.setInterpolate(false); for (int y=0; y<height; y++) { aLine = ip2.getLine(0, y, width-1, y); for (int i=0; i<width; i++) profile[i] += aLine[i]; } for (int i=0; i<width; i++) profile[i] /= height; imp.setRoi(roi); if (roi.getType()==Roi.POLYLINE&& !((PolygonRoi)roi).isSplineFit()) { ((PolygonRoi)roi).fitSpline(); imp.draw(); } return profile; }
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; }
void process(int command) { String s = ""; ImageProcessor ip2 = stack.getProcessor(1); switch (command) { case FLIPH: case FLIPV: s="Flip: "; break; case SCALE: s="Scale: "; break; case SCALE_WITH_FILL: s="Scale: "; ip2.setBackgroundValue(fillValue); break; case INVERT: s="Invert: "; break; case APPLY_TABLE: s="Apply: "; break; } if (ip==null) ip = ip2; ip2.setRoi(this.ip.getRoi()); ip2.setInterpolate(this.ip.getInterpolate()); for (int i=1; i<=nSlices; i++) { showStatus(s,i,nSlices); ip2.setPixels(stack.getPixels(i)); if (nSlices==1 && i==1 && command==SCALE) ip2.snapshot(); switch (command) { case FLIPH: ip2.flipHorizontal(); break; case FLIPV: ip2.flipVertical(); break; case SCALE: case SCALE_WITH_FILL: ip2.scale(xScale, yScale); break; case INVERT: ip2.invert(); break; case APPLY_TABLE: ip2.applyTable(table); break; } IJ.showProgress((double)i/nSlices); } IJ.showProgress(1.0); }