public ImageProcessor rotateLine(ImagePlus imp, int width) { Roi roi = imp.getRoi(); if (roi==null || roi.getType()!=Roi.LINE) throw new IllegalArgumentException("Straight line selection expected"); Polygon p = ((Line)roi).getPoints(); imp.setRoi(new PolygonRoi(p.xpoints, p.ypoints, 2, Roi.POLYLINE)); ImageProcessor ip2 = imp.getBitDepth()==24?straightenRGB(imp, width):straightenLine(imp, width); imp.setRoi(roi); return ip2; }
public ImageProcessor rotateLine(ImagePlus imp, int width) { Roi roi = imp.getRoi(); if (roi==null || roi.getType()!=Roi.LINE) throw new IllegalArgumentException("Straight line selection expected"); Polygon p = ((Line)roi).getPoints(); imp.setRoi(new PolygonRoi(p.xpoints, p.ypoints, 2, Roi.POLYLINE)); ImageProcessor ip2 = imp.getBitDepth()==24?straightenRGB(imp, width):straightenLine(imp, width); imp.setRoi(roi); return ip2; }
ImagePlus dummy = new ImagePlus("dummy", stack.getProcessor(i + 1)); dummy.setRoi(rois[i]); ImageProcessor ip2 = straightener.straightenLine(dummy, lineWidth); if (w < ip2.getWidth()) { w = ip2.getWidth();
public ImageProcessor straighten(ImagePlus imp, Roi roi, int width) { ImageProcessor ip2; if (imp.getBitDepth()==24 && roi.getType()!=Roi.LINE) ip2 = straightenRGB(imp, width); else if (imp.isComposite() && ((CompositeImage)imp).getMode()==IJ.COMPOSITE) { if (roi.getType()==Roi.LINE) ip2 = rotateCompositeLine(imp, width); else ip2 = straightenComposite(imp, width); } else if (roi.getType()==Roi.LINE) ip2 = rotateLine(imp, width); else ip2 = straightenLine(imp, width); return ip2; }
public ImageProcessor straighten(ImagePlus imp, Roi roi, int width) { ImageProcessor ip2; if (imp.getBitDepth()==24 && roi.getType()!=Roi.LINE) ip2 = straightenRGB(imp, width); else if (imp.isComposite() && ((CompositeImage)imp).getMode()==IJ.COMPOSITE) { if (roi.getType()==Roi.LINE) ip2 = rotateCompositeLine(imp, width); else ip2 = straightenComposite(imp, width); } else if (roi.getType()==Roi.LINE) ip2 = rotateLine(imp, width); else ip2 = straightenLine(imp, width); return ip2; }
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; }
protected static float[] getProfile(ImageProcessor ip, PolygonRoi roi, boolean fitSpline, int lineWidth) { if (fitSpline && !roi.isSplineFit()) { roi = (PolygonRoi)roi.clone(); roi.fitSpline(); } ImagePlus dummy = new ImagePlus("dummy", ip); dummy.setRoi(roi); Straightener straightener = new Straightener(); ip = straightener.straightenLine(dummy, lineWidth); int w = ip.getWidth(); float[] result = new float[w]; // need to average explicitely for (int j = 0; j < w; j++) { float value = ip.getf(j, 0); for (int k = 1; k < lineWidth; k++) value += ip.getf(j, k); result[j] = value / lineWidth; } return result; } }
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 straightenRGB(ImagePlus imp, int width) { int w=imp.getWidth(), h=imp.getHeight(); int size = w*h; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; ColorProcessor cp = (ColorProcessor)imp.getProcessor(); cp.getRGB(r, g, b); ImagePlus imp2 = new ImagePlus("red", new ByteProcessor(w, h, r, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor red = straightenLine(imp2, width); if (red==null) return null; imp2 = new ImagePlus("green", new ByteProcessor(w, h, g, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor green = straightenLine(imp2, width); if (green==null) return null; imp2 = new ImagePlus("blue", new ByteProcessor(w, h, b, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor blue = straightenLine(imp2, width); if (blue==null) return null; ColorProcessor cp2 = new ColorProcessor(red.getWidth(), red.getHeight()); red = red.convertToByte(false); green = green.convertToByte(false); blue = blue.convertToByte(false); cp2.setRGB((byte[])red.getPixels(), (byte[])green.getPixels(), (byte[])blue.getPixels()); imp.setRoi(imp2.getRoi()); return cp2; }
ImageProcessor straightenRGB(ImagePlus imp, int width) { int w=imp.getWidth(), h=imp.getHeight(); int size = w*h; byte[] r = new byte[size]; byte[] g = new byte[size]; byte[] b = new byte[size]; ColorProcessor cp = (ColorProcessor)imp.getProcessor(); cp.getRGB(r, g, b); ImagePlus imp2 = new ImagePlus("red", new ByteProcessor(w, h, r, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor red = straightenLine(imp2, width); if (red==null) return null; imp2 = new ImagePlus("green", new ByteProcessor(w, h, g, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor green = straightenLine(imp2, width); if (green==null) return null; imp2 = new ImagePlus("blue", new ByteProcessor(w, h, b, null)); imp2.setRoi((Roi)imp.getRoi().clone()); ImageProcessor blue = straightenLine(imp2, width); if (blue==null) return null; ColorProcessor cp2 = new ColorProcessor(red.getWidth(), red.getHeight()); red = red.convertToByte(false); green = green.convertToByte(false); blue = blue.convertToByte(false); cp2.setRGB((byte[])red.getPixels(), (byte[])green.getPixels(), (byte[])blue.getPixels()); imp.setRoi(imp2.getRoi()); return cp2; }
ImagePlus dummy = new ImagePlus("dummy", stack.getProcessor(i + 1)); dummy.setRoi(rois[i]); ImageProcessor ip = straightener.straightenLine(dummy, lineWidth); int w = ip.getWidth(); if (!useFullLineWidth && lineWidth > 1)
ImagePlus dummy = new ImagePlus("dummy", stack.getProcessor(i + 1)); dummy.setRoi(rois[i]); ImageProcessor ip = straightener.straightenLine(dummy, lineWidth); int w = ip.getWidth(); if (!useFullLineWidth && lineWidth > 1)
ImagePlus dummy = new ImagePlus("dummy", stack.getProcessor(i + 1)); dummy.setRoi(rois[i]); ImageProcessor ip2 = straightener.straightenLine(dummy, lineWidth); if (w < ip2.getWidth()) { w = ip2.getWidth();
Calibration cal = imp2.getCalibration().copy(); imp2.getCalibration().disableDensityCalibration(); ip2 = (new Straightener()).straightenLine(imp2, lineWidth); imp2.setCalibration(cal); ip2 = convertToOriginalDepth(imp2, ip2); } else if (lineWidth>1) { if ((measurements&AREA)!=0 || (measurements&MEAN)!=0 || calibrated) { ip2 = (new Straightener()).straightenLine(imp2, lineWidth); if (limit!=0) ip2 = convertToOriginalDepth(imp2, ip2);
Calibration cal = imp2.getCalibration().copy(); imp2.getCalibration().disableDensityCalibration(); ip2 = (new Straightener()).straightenLine(imp2, lineWidth); imp2.setCalibration(cal); ip2 = convertToOriginalDepth(imp2, ip2); } else if (lineWidth>1) { if ((measurements&AREA)!=0 || (measurements&MEAN)!=0 || calibrated) { ip2 = (new Straightener()).straightenLine(imp2, lineWidth); if (limit!=0) ip2 = convertToOriginalDepth(imp2, ip2);
ip2.setRoi(saveR); } else { ip2 = (new Straightener()).straightenLine(imp, lineWidth); stats = ImageStatistics.getStatistics(ip2, params, cal);
ip2.setRoi(saveR); } else { ip2 = (new Straightener()).straightenLine(imp, lineWidth); stats = ImageStatistics.getStatistics(ip2, params, cal);