/** Generate output image whose type is same as input image. */ private ImagePlus makeOutputImage(ImagePlus imp, FloatProcessor fp, int ptype) { int width = imp.getWidth(); int height = imp.getHeight(); float[] pixels = (float[]) fp.getPixels(); ImageProcessor oip = null; // Create output image consistent w/ type of input image. int size = pixels.length; switch (ptype) { case BYTE_TYPE: oip = imp.getProcessor().createProcessor(width, height); byte[] pixels8 = (byte[]) oip.getPixels(); for (int i = 0; i < size; i++) pixels8[i] = (byte) pixels[i]; break; case SHORT_TYPE: oip = imp.getProcessor().createProcessor(width, height); short[] pixels16 = (short[]) oip.getPixels(); for (int i = 0; i < size; i++) pixels16[i] = (short) pixels[i]; break; case FLOAT_TYPE: oip = new FloatProcessor(width, height, pixels, null); break; } // Adjust for display. // Calling this on non-ByteProcessors ensures image // processor is set up to correctly display image. oip.resetMinAndMax(); // Create new image plus object. Don't use // ImagePlus.createImagePlus here because there may be // attributes of input image that are not appropriate for // projection. return new ImagePlus(makeTitle(), oip); }
public void mousePressed(MouseEvent e) { // super.mousePressed(e); ImageProcessor ip = imp.getProcessor(); ip.setLineWidth(1); if (Toolbar.getToolId() == Toolbar.DROPPER) IJ.setTool(Toolbar.RECTANGLE); Rectangle flipperRect = new Rectangle(86, 268, 18, 18); Rectangle resetRect = new Rectangle(86, 294, 18, 18); Rectangle foreground1Rect = new Rectangle(9, 266, 45, 10); Rectangle foreground2Rect = new Rectangle(9, 276, 23, 25); Rectangle background1Rect = new Rectangle(33, 302, 45, 10); Rectangle background2Rect = new Rectangle(56, 277, 23, 25); int x = offScreenX(e.getX()); int y = offScreenY(e.getY()); long difference = System.currentTimeMillis() - mouseDownTime; boolean doubleClick = (difference <= 250); mouseDownTime = System.currentTimeMillis(); if (flipperRect.contains(x, y)) { Color c = Toolbar.getBackgroundColor(); Toolbar.setBackgroundColor(Toolbar.getForegroundColor()); Toolbar.setForegroundColor(c); } else if (resetRect.contains(x, y)) { Toolbar.setForegroundColor(new Color(0x000000)); Toolbar.setBackgroundColor(new Color(0xffffff)); } else if ((background1Rect.contains(x, y)) || (background2Rect.contains(x, y))) { background = true; if (doubleClick) editColor(); ((ColorGenerator) ip).refreshForeground(); ((ColorGenerator) ip).refreshBackground(); } else if ((foreground1Rect.contains(x, y)) || (foreground2Rect.contains(x, y))) { background = false; if (doubleClick) editColor(); ((ColorGenerator) ip).refreshBackground(); ((ColorGenerator) ip).refreshForeground(); } else { // IJ.log(" " + difference + " " + doubleClick); if (doubleClick) editColor(); else { setDrawingColor(offScreenX(e.getX()), offScreenY(e.getY()), background); } } if (ip instanceof ColorGenerator) { if (background) { ((ColorGenerator) ip).refreshForeground(); ((ColorGenerator) ip).refreshBackground(); } else { ((ColorGenerator) ip).refreshBackground(); ((ColorGenerator) ip).refreshForeground(); } } }
/*------------------------------------------------------------------*/ void putRow(ImageProcessor ip, int y, double[] row) { int rowLength = ip.getWidth(); if (rowLength != row.length) { throw new IndexOutOfBoundsException("Incoherent array sizes"); } y *= rowLength; if (ip.getPixels() instanceof float[]) { float[] floatPixels = (float[]) ip.getPixels(); for (int i = 0; (i < rowLength); i++) { floatPixels[y++] = (float) row[i]; } } else { throw new IllegalArgumentException("Float image required"); } } /* end putRow */
/*------------------------------------------------------------------*/ void putColumn(ImageProcessor ip, int x, double[] column) { int width = ip.getWidth(); if (ip.getHeight() != column.length) { throw new IndexOutOfBoundsException("Incoherent array sizes"); } if (ip.getPixels() instanceof float[]) { float[] floatPixels = (float[]) ip.getPixels(); for (int i = 0; (i < column.length); i++) { floatPixels[x] = (float) column[i]; x += width; } } else { throw new IllegalArgumentException("Float image required"); } } /* end putColumn */
void reset(ImagePlus imp, ImageProcessor ip) { // Assign the pixels of ip to the data in the restore array, while // taking care to not give the address the restore array to the // image processor. int[] pixels = (int[]) ip.getPixels(); for (int i = 0; i < numPixels; i++) pixels[i] = restore[i]; }
void setHistogram(ImagePlus imp, int j) { ImageProcessor ip = imp.getProcessor(); ImageStatistics stats = ImageStatistics.getStatistics(ip, AREA + MODE, null); int maxCount2 = 0; histogram = stats.histogram; for (int i = 0; i < stats.nBins; i++) if ((histogram[i] > maxCount2) && (i != stats.mode)) maxCount2 = histogram[i]; hmax = stats.maxCount; if ((hmax > (maxCount2 * 1.5)) && (maxCount2 != 0)) { // GL 1.5 was 2 hmax = (int) (maxCount2 * 1.1); // GL 1.1 was 1.5 histogram[stats.mode] = hmax; } os = null; ColorModel cm = ip.getColorModel(); if (!(cm instanceof IndexColorModel)) return; IndexColorModel icm = (IndexColorModel) cm; int mapSize = icm.getMapSize(); if (mapSize != 256) return; byte[] r = new byte[256]; byte[] g = new byte[256]; byte[] b = new byte[256]; icm.getReds(r); icm.getGreens(g); icm.getBlues(b); hColors = new Color[256]; if (isRGB) { if (j == 0) { for (int i = 0; i < 256; i++) hColors[i] = new Color(i & 255, 0 & 255, 0 & 255); } else if (j == 1) { for (int i = 0; i < 256; i++) hColors[i] = new Color(0 & 255, i & 255, 0 & 255); } else if (j == 2) { for (int i = 0; i < 256; i++) hColors[i] = new Color(0 & 255, 0 & 255, i & 255); } } else { if (j == 0) { for (int i = 0; i < 256; i++) hColors[i] = new Color(r[i] & 255, g[i] & 255, b[i] & 255); } else if (j == 1) { for (int i = 0; i < 256; i++) // hColors[i] = new Color(127-i/2&255, 127+i/2&255, 127-i/2&255); hColors[i] = new Color(192 - i / 4 & 255, 192 + i / 4 & 255, 192 - i / 4 & 255); } else if (j == 2) { for (int i = 0; i < 256; i++) hColors[i] = new Color(i & 255, i & 255, 0 & 255); } } }
/*------------------------------------------------------------------*/ public void getHorizontalGradient(ImageProcessor ip, double tolerance) { if (!(ip.getPixels() instanceof float[])) { throw new IllegalArgumentException("Float image required"); } float[] floatPixels = (float[]) ip.getPixels(); int width = ip.getWidth(); int height = ip.getHeight(); double line[] = new double[width]; for (int y = 0; (y < height); y++) { getRow(ip, y, line); getSplineInterpolationCoefficients(line, tolerance); getGradient(line); putRow(ip, y, line); stepProgressBar(); } } /* end getHorizontalGradient */
/*------------------------------------------------------------------*/ public void getVerticalHessian(ImageProcessor ip, double tolerance) { if (!(ip.getPixels() instanceof float[])) { throw new IllegalArgumentException("Float image required"); } float[] floatPixels = (float[]) ip.getPixels(); int width = ip.getWidth(); int height = ip.getHeight(); double line[] = new double[height]; for (int x = 0; (x < width); x++) { getColumn(ip, x, line); getSplineInterpolationCoefficients(line, tolerance); getHessian(line); putColumn(ip, x, line); stepProgressBar(); } } /* end getVerticalHessian */
void scale(ImageProcessor ip) { if (newWindow) { Rectangle r = ip.getRoi(); ImagePlus imp2 = imp.createImagePlus(); imp2.setProcessor(title, ip.resize(newWidth, newHeight)); Calibration cal = imp2.getCalibration(); if (cal.scaled()) { cal.pixelWidth *= 1.0 / xscale; cal.pixelHeight *= 1.0 / yscale; } imp2.show(); imp.trimProcessor(); imp2.trimProcessor(); imp2.changes = true; } else { if (processStack && imp.getStackSize() > 1) { Undo.reset(); StackProcessor sp = new StackProcessor(imp.getStack(), ip); sp.scale(xscale, yscale, bgValue); } else { ip.snapshot(); Undo.setup(Undo.FILTER, imp); ip.setSnapshotCopyMode(true); ip.scale(xscale, yscale); ip.setSnapshotCopyMode(false); } imp.killRoi(); imp.updateAndDraw(); imp.changes = true; } }
void createNewStack(ImagePlus imp, ImageProcessor ip) { int nSlices = imp.getStackSize(); int w = imp.getWidth(), h = imp.getHeight(); ImagePlus imp2 = imp.createImagePlus(); Rectangle r = ip.getRoi(); boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight(); ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(newWidth, newHeight); ImageProcessor ip1, ip2; int method = interpolationMethod; if (w == 1 || h == 1) method = ImageProcessor.NONE; for (int i = 1; i <= nSlices; i++) { IJ.showStatus("Scale: " + i + "/" + nSlices); ip1 = stack1.getProcessor(i); String label = stack1.getSliceLabel(i); if (crop) { ip1.setRoi(r); ip1 = ip1.crop(); } ip1.setInterpolationMethod(method); ip2 = ip1.resize(newWidth, newHeight, averageWhenDownsizing); if (ip2 != null) stack2.addSlice(label, ip2); IJ.showProgress(i, nSlices); } imp2.setStack(title, stack2); Calibration cal = imp2.getCalibration(); if (cal.scaled()) { cal.pixelWidth *= 1.0 / xscale; cal.pixelHeight *= 1.0 / yscale; } IJ.showProgress(1.0); int[] dim = imp.getDimensions(); imp2.setDimensions(dim[2], dim[3], dim[4]); if (imp.isComposite()) { imp2 = new CompositeImage(imp2, ((CompositeImage) imp).getMode()); ((CompositeImage) imp2).copyLuts(imp); } if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true); if (newDepth > 0 && newDepth != oldDepth) imp2 = (new Resizer()).zScale(imp2, newDepth, interpolationMethod); if (imp2 != null) { imp2.show(); imp2.changes = true; } }
public void run(String arg) { imp = IJ.getImage(); Roi roi = imp.getRoi(); if (roi != null && !roi.isArea()) imp.killRoi(); // ignore any line selection ImageProcessor ip = imp.getProcessor(); if (!showDialog(ip)) return; if (ip.getWidth() > 1 && ip.getHeight() > 1) ip.setInterpolate(interpolate); else ip.setInterpolate(false); ip.setBackgroundValue(bgValue); imp.startTiming(); try { if (newWindow && imp.getStackSize() > 1 && processStack) createNewStack(imp, ip); else scale(ip); } catch (OutOfMemoryError o) { IJ.outOfMemory("Scale"); } IJ.showProgress(1.0); }
void createNewStack(ImagePlus imp, ImageProcessor ip) { Rectangle r = ip.getRoi(); boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight(); int nSlices = imp.getStackSize(); ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(newWidth, newHeight); ImageProcessor ip1, ip2; boolean interp = interpolate; if (imp.getWidth() == 1 || imp.getHeight() == 1) interp = false; for (int i = 1; i <= nSlices; i++) { IJ.showStatus("Scale: " + i + "/" + nSlices); ip1 = stack1.getProcessor(i); String label = stack1.getSliceLabel(i); if (crop) { ip1.setRoi(r); ip1 = ip1.crop(); } ip1.setInterpolate(interp); ip2 = ip1.resize(newWidth, newHeight); if (ip2 != null) stack2.addSlice(label, ip2); IJ.showProgress(i, nSlices); } ImagePlus imp2 = imp.createImagePlus(); imp2.setStack(title, stack2); Calibration cal = imp2.getCalibration(); if (cal.scaled()) { cal.pixelWidth *= 1.0 / xscale; cal.pixelHeight *= 1.0 / yscale; } int[] dim = imp.getDimensions(); imp2.setDimensions(dim[2], dim[3], dim[4]); IJ.showProgress(1.0); if (imp.isComposite()) { imp2 = new CompositeImage(imp2, 0); ((CompositeImage) imp2).copyLuts(imp); } if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true); imp2.show(); imp2.changes = true; }
ImagePlus doMedianProjection() { IJ.showStatus("Calculating median..."); ImageStack stack = imp.getStack(); ImageProcessor[] slices = new ImageProcessor[sliceCount]; int index = 0; for (int slice = startSlice; slice <= stopSlice; slice += increment) slices[index++] = stack.getProcessor(slice); ImageProcessor ip2 = slices[0].duplicate(); ip2 = ip2.convertToFloat(); float[] values = new float[sliceCount]; int width = ip2.getWidth(); int height = ip2.getHeight(); int inc = Math.max(height / 30, 1); for (int y = 0; y < height; y++) { if (y % inc == 0) IJ.showProgress(y, height - 1); for (int x = 0; x < width; x++) { for (int i = 0; i < sliceCount; i++) values[i] = slices[i].getPixelValue(x, y); ip2.putPixelValue(x, y, median(values)); } } if (imp.getBitDepth() == 8) ip2 = ip2.convertToByte(false); IJ.showProgress(1, 1); return new ImagePlus(makeTitle(), ip2); }
void sample() { byte[] hsSource, ssSource, bsSource; // ImageProcessor ip2; // ip2 = imp.getProcessor(); Rectangle myroi = ip.getRoi(); int swidth = myroi.width; int sheight = myroi.height; int sy = myroi.y; int sx = myroi.x; if (swidth == width && sheight == height) { IJ.showMessage("Select a rectangular ROI"); IJ.beep(); return; } IJ.run("Select None"); int snumPixels = swidth * sheight; hsSource = new byte[snumPixels]; ssSource = new byte[snumPixels]; bsSource = new byte[snumPixels]; int[] pixs = new int[snumPixels]; int[] bin = new int[256]; int counter = 0, pi = 0, rangePassH = 0, rangeStopH = 0, rangePassL = 0, rangeStopL = 0, i, j; for (i = sy; i < sy + sheight; i++) { for (j = sx; j < sx + swidth; j++) { pixs[counter++] = ip.getPixel(j, i); } } // Get hsb or rgb from roi. ColorProcessor cp2 = new ColorProcessor(swidth, sheight, pixs); int iminhue = 256, imaxhue = -1, iminsat = 256, imaxsat = -1, iminbri = 256, imaxbri = -1; int iminred = 256, imaxred = -1, imingre = 256, imaxgre = -1, iminblu = 256, imaxblu = -1; if (isRGB) cp2.getRGB(hsSource, ssSource, bsSource); else cp2.getHSB(hsSource, ssSource, bsSource); for (i = 0; i < snumPixels; i++) { bin[hsSource[i] & 255] = 1; if ((hsSource[i] & 255) > imaxhue) imaxhue = (hsSource[i] & 255); if ((hsSource[i] & 255) < iminhue) iminhue = (hsSource[i] & 255); if ((ssSource[i] & 255) > imaxsat) imaxsat = (ssSource[i] & 255); if ((ssSource[i] & 255) < iminsat) iminsat = (ssSource[i] & 255); if ((bsSource[i] & 255) > imaxbri) imaxbri = (bsSource[i] & 255); if ((bsSource[i] & 255) < iminbri) iminbri = (bsSource[i] & 255); // IJ.showMessage("h:"+minhue+"H:"+maxhue+"s:"+minsat+"S:"+maxsat+"b:"+minbri+"B:"+maxbri); } if (!isRGB) { // get pass or stop filter whichever has a narrower range for (i = 0; i < 256; i++) { if (bin[i] > 0) { rangePassL = i; break; } } for (i = 255; i >= 0; i--) { if (bin[i] > 0) { rangePassH = i; break; } } for (i = 0; i < 256; i++) { if (bin[i] == 0) { rangeStopL = i; break; } } for (i = 255; i >= 0; i--) { if (bin[i] == 0) { rangeStopH = i; break; } } if ((rangePassH - rangePassL) < (rangeStopH - rangeStopL)) { bandPassH.setState(true); bandStopH.setState(false); iminhue = rangePassL; imaxhue = rangePassH; } else { bandPassH.setState(false); bandStopH.setState(true); iminhue = rangeStopL; imaxhue = rangeStopH; } } else { bandPassH.setState(true); bandStopH.setState(false); } adjustMinHue(iminhue); minSlider.setValue(iminhue); adjustMaxHue(imaxhue); maxSlider.setValue(imaxhue); adjustMinSat(iminsat); minSlider2.setValue(iminsat); adjustMaxSat(imaxsat); maxSlider2.setValue(imaxsat); adjustMinBri(iminbri); minSlider3.setValue(iminbri); adjustMaxBri(imaxbri); maxSlider3.setValue(imaxbri); originalB.setEnabled(true); // IJ.showStatus("done"); }
boolean showDialog(ImageProcessor ip) { int bitDepth = imp.getBitDepth(); boolean isStack = imp.getStackSize() > 1; r = ip.getRoi(); int width = newWidth; if (width == 0) width = r.width; int height = (int) ((double) width * r.height / r.width); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); if (xscale != 0.0 && yscale != 0.0) { width = (int) (r.width * xscale); height = (int) (r.height * yscale); } else { xstr = "-"; ystr = "-"; } GenericDialog gd = new GenericDialog("Scale"); gd.addStringField("X Scale (0.05-25):", xstr); gd.addStringField("Y Scale (0.05-25):", ystr); gd.setInsets(5, 0, 5); gd.addStringField("Width (pixels):", "" + width); gd.addStringField("Height (pixels):", "" + height); fields = gd.getStringFields(); for (int i = 0; i < 3; i++) { ((TextField) fields.elementAt(i)).addTextListener(this); ((TextField) fields.elementAt(i)).addFocusListener(this); } xField = (TextField) fields.elementAt(0); yField = (TextField) fields.elementAt(1); widthField = (TextField) fields.elementAt(2); heightField = (TextField) fields.elementAt(3); fieldWithFocus = xField; gd.addCheckbox("Interpolate", interpolate); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with Background Color", fillWithBackground); if (isStack) gd.addCheckbox("Process Entire Stack", processStack); gd.addCheckbox("Create New Window", newWindow); title = WindowManager.getUniqueName(imp.getTitle()); gd.setInsets(10, 0, 0); gd.addStringField("Title:", title, 12); gd.showDialog(); if (gd.wasCanceled()) return false; xstr = gd.getNextString(); ystr = gd.getNextString(); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); String wstr = gd.getNextString(); newWidth = (int) Tools.parseDouble(wstr, 0); newHeight = (int) Tools.parseDouble(gd.getNextString(), 0); if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0"))) newWidth = (int) (newHeight * (double) r.width / r.height); if (newWidth == 0 || newHeight == 0) { IJ.error("Invalid width or height entered"); return false; } if (xscale > 25.0) xscale = 25.0; if (yscale > 25.0) yscale = 25.0; if (xscale > 0.0 && yscale > 0.0) { newWidth = (int) (r.width * xscale); newHeight = (int) (r.height * yscale); } interpolate = gd.getNextBoolean(); if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean(); if (isStack) processStack = gd.getNextBoolean(); newWindow = gd.getNextBoolean(); if (!newWindow && xscale == 0.0) { xscale = (double) newWidth / r.width; yscale = (double) newHeight / r.height; } title = gd.getNextString(); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) bgValue = ip.getBestIndex(bgc); else if (bitDepth == 24) bgValue = bgc.getRGB(); } else { if (bitDepth == 8) bgValue = ip.isInvertedLut() ? 0.0 : 255.0; // white else if (bitDepth == 24) bgValue = 0xffffffff; // white } return true; }
/*------------------------------------------------------------------*/ void doIt(ImageProcessor ip) { int width = ip.getWidth(); int height = ip.getHeight(); double hLine[] = new double[width]; double vLine[] = new double[height]; if (!(ip.getPixels() instanceof float[])) { throw new IllegalArgumentException("Float image required"); } switch (operation) { case GRADIENT_MAGNITUDE: { ImageProcessor h = ip.duplicate(); ImageProcessor v = ip.duplicate(); float[] floatPixels = (float[]) ip.getPixels(); float[] floatPixelsH = (float[]) h.getPixels(); float[] floatPixelsV = (float[]) v.getPixels(); getHorizontalGradient(h, FLT_EPSILON); getVerticalGradient(v, FLT_EPSILON); for (int y = 0, k = 0; (y < height); y++) { for (int x = 0; (x < width); x++, k++) { floatPixels[k] = (float) Math.sqrt( floatPixelsH[k] * floatPixelsH[k] + floatPixelsV[k] * floatPixelsV[k]); } stepProgressBar(); } } break; case GRADIENT_DIRECTION: { ImageProcessor h = ip.duplicate(); ImageProcessor v = ip.duplicate(); float[] floatPixels = (float[]) ip.getPixels(); float[] floatPixelsH = (float[]) h.getPixels(); float[] floatPixelsV = (float[]) v.getPixels(); getHorizontalGradient(h, FLT_EPSILON); getVerticalGradient(v, FLT_EPSILON); for (int y = 0, k = 0; (y < height); y++) { for (int x = 0; (x < width); x++, k++) { floatPixels[k] = (float) Math.atan2(floatPixelsH[k], floatPixelsV[k]); } stepProgressBar(); } } break; case LAPLACIAN: { ImageProcessor hh = ip.duplicate(); ImageProcessor vv = ip.duplicate(); float[] floatPixels = (float[]) ip.getPixels(); float[] floatPixelsHH = (float[]) hh.getPixels(); float[] floatPixelsVV = (float[]) vv.getPixels(); getHorizontalHessian(hh, FLT_EPSILON); getVerticalHessian(vv, FLT_EPSILON); for (int y = 0, k = 0; (y < height); y++) { for (int x = 0; (x < width); x++, k++) { floatPixels[k] = (float) (floatPixelsHH[k] + floatPixelsVV[k]); } stepProgressBar(); } } break; case LARGEST_HESSIAN: { ImageProcessor hh = ip.duplicate(); ImageProcessor vv = ip.duplicate(); ImageProcessor hv = ip.duplicate(); float[] floatPixels = (float[]) ip.getPixels(); float[] floatPixelsHH = (float[]) hh.getPixels(); float[] floatPixelsVV = (float[]) vv.getPixels(); float[] floatPixelsHV = (float[]) hv.getPixels(); getHorizontalHessian(hh, FLT_EPSILON); getVerticalHessian(vv, FLT_EPSILON); getCrossHessian(hv, FLT_EPSILON); for (int y = 0, k = 0; (y < height); y++) { for (int x = 0; (x < width); x++, k++) { floatPixels[k] = (float) (0.5 * (floatPixelsHH[k] + floatPixelsVV[k] + Math.sqrt( 4.0 * floatPixelsHV[k] * floatPixelsHV[k] + (floatPixelsHH[k] - floatPixelsVV[k]) * (floatPixelsHH[k] - floatPixelsVV[k])))); } stepProgressBar(); } } break; case SMALLEST_HESSIAN: { ImageProcessor hh = ip.duplicate(); ImageProcessor vv = ip.duplicate(); ImageProcessor hv = ip.duplicate(); float[] floatPixels = (float[]) ip.getPixels(); float[] floatPixelsHH = (float[]) hh.getPixels(); float[] floatPixelsVV = (float[]) vv.getPixels(); float[] floatPixelsHV = (float[]) hv.getPixels(); getHorizontalHessian(hh, FLT_EPSILON); getVerticalHessian(vv, FLT_EPSILON); getCrossHessian(hv, FLT_EPSILON); for (int y = 0, k = 0; (y < height); y++) { for (int x = 0; (x < width); x++, k++) { floatPixels[k] = (float) (0.5 * (floatPixelsHH[k] + floatPixelsVV[k] - Math.sqrt( 4.0 * floatPixelsHV[k] * floatPixelsHV[k] + (floatPixelsHH[k] - floatPixelsVV[k]) * (floatPixelsHH[k] - floatPixelsVV[k])))); } stepProgressBar(); } } break; case HESSIAN_ORIENTATION: { ImageProcessor hh = ip.duplicate(); ImageProcessor vv = ip.duplicate(); ImageProcessor hv = ip.duplicate(); float[] floatPixels = (float[]) ip.getPixels(); float[] floatPixelsHH = (float[]) hh.getPixels(); float[] floatPixelsVV = (float[]) vv.getPixels(); float[] floatPixelsHV = (float[]) hv.getPixels(); getHorizontalHessian(hh, FLT_EPSILON); getVerticalHessian(vv, FLT_EPSILON); getCrossHessian(hv, FLT_EPSILON); for (int y = 0, k = 0; (y < height); y++) { for (int x = 0; (x < width); x++, k++) { if (floatPixelsHV[k] < 0.0) { floatPixels[k] = (float) (-0.5 * Math.acos( (floatPixelsHH[k] - floatPixelsVV[k]) / Math.sqrt( 4.0 * floatPixelsHV[k] * floatPixelsHV[k] + (floatPixelsHH[k] - floatPixelsVV[k]) * (floatPixelsHH[k] - floatPixelsVV[k])))); } else { floatPixels[k] = (float) (0.5 * Math.acos( (floatPixelsHH[k] - floatPixelsVV[k]) / Math.sqrt( 4.0 * floatPixelsHV[k] * floatPixelsHV[k] + (floatPixelsHH[k] - floatPixelsVV[k]) * (floatPixelsHH[k] - floatPixelsVV[k])))); } } stepProgressBar(); } } break; default: throw new IllegalArgumentException("Invalid operation"); } ip.resetMinAndMax(); imp.updateAndDraw(); } /* end doIt */
boolean showDialog(ImageProcessor ip) { String macroOptions = Macro.getOptions(); if (macroOptions != null) { if (macroOptions.indexOf(" interpolate") != -1) macroOptions.replaceAll(" interpolate", " interpolation=Bilinear"); else if (macroOptions.indexOf(" interpolation=") == -1) macroOptions = macroOptions + " interpolation=None"; Macro.setOptions(macroOptions); } int bitDepth = imp.getBitDepth(); int stackSize = imp.getStackSize(); boolean isStack = stackSize > 1; oldDepth = stackSize; if (isStack) { xstr = "1.0"; ystr = "1.0"; zstr = "1.0"; } r = ip.getRoi(); int width = newWidth; if (width == 0) width = r.width; int height = (int) ((double) width * r.height / r.width); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); zscale = 1.0; if (xscale != 0.0 && yscale != 0.0) { width = (int) (r.width * xscale); height = (int) (r.height * yscale); } else { xstr = "-"; ystr = "-"; } GenericDialog gd = new GenericDialog("Scale"); gd.addStringField("X Scale:", xstr); gd.addStringField("Y Scale:", ystr); if (isStack) gd.addStringField("Z Scale:", zstr); gd.setInsets(5, 0, 5); gd.addStringField("Width (pixels):", "" + width); gd.addStringField("Height (pixels):", "" + height); if (isStack) { String label = "Depth (images):"; if (imp.isHyperStack()) { int slices = imp.getNSlices(); int frames = imp.getNFrames(); if (slices == 1 && frames > 1) { label = "Depth (frames):"; oldDepth = frames; } else { label = "Depth (slices):"; oldDepth = slices; } } gd.addStringField(label, "" + oldDepth); } fields = gd.getStringFields(); for (int i = 0; i < fields.size(); i++) { ((TextField) fields.elementAt(i)).addTextListener(this); ((TextField) fields.elementAt(i)).addFocusListener(this); } xField = (TextField) fields.elementAt(0); yField = (TextField) fields.elementAt(1); if (isStack) { zField = (TextField) fields.elementAt(2); widthField = (TextField) fields.elementAt(3); heightField = (TextField) fields.elementAt(4); depthField = (TextField) fields.elementAt(5); } else { widthField = (TextField) fields.elementAt(2); heightField = (TextField) fields.elementAt(3); } fieldWithFocus = xField; gd.addChoice("Interpolation:", methods, methods[interpolationMethod]); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with background color", fillWithBackground); gd.addCheckbox("Average when downsizing", averageWhenDownsizing); boolean hyperstack = imp.isHyperStack() || imp.isComposite(); if (isStack && !hyperstack) gd.addCheckbox("Process entire stack", processStack); gd.addCheckbox("Create new window", newWindow); title = WindowManager.getUniqueName(imp.getTitle()); gd.setInsets(10, 0, 0); gd.addStringField("Title:", title, 12); gd.showDialog(); if (gd.wasCanceled()) return false; xstr = gd.getNextString(); ystr = gd.getNextString(); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); if (isStack) { zstr = gd.getNextString(); zscale = Tools.parseDouble(ystr, 0.0); } String wstr = gd.getNextString(); newWidth = (int) Tools.parseDouble(wstr, 0); newHeight = (int) Tools.parseDouble(gd.getNextString(), 0); if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0"))) newWidth = (int) (newHeight * (double) r.width / r.height); if (newWidth == 0 || newHeight == 0) { IJ.error("Scaler", "Width or height is 0"); return false; } if (xscale > 0.0 && yscale > 0.0) { newWidth = (int) (r.width * xscale); newHeight = (int) (r.height * yscale); } if (isStack) newDepth = (int) Tools.parseDouble(gd.getNextString(), 0); interpolationMethod = gd.getNextChoiceIndex(); if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean(); averageWhenDownsizing = gd.getNextBoolean(); if (isStack && !hyperstack) processStack = gd.getNextBoolean(); if (hyperstack) processStack = true; newWindow = gd.getNextBoolean(); if (xscale == 0.0) { xscale = (double) newWidth / r.width; yscale = (double) newHeight / r.height; } title = gd.getNextString(); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) bgValue = ip.getBestIndex(bgc); else if (bitDepth == 24) bgValue = bgc.getRGB(); } else bgValue = 0.0; return true; }
/** This plugin implements the Image/Scale command. */ public class Scaler implements PlugIn, TextListener, FocusListener { private ImagePlus imp; private static String xstr = "0.5"; private static String ystr = "0.5"; private String zstr = "1.0"; private static int newWidth, newHeight; private int newDepth; private static boolean averageWhenDownsizing = true; private static boolean newWindow = true; private static int interpolationMethod = ImageProcessor.BILINEAR; private String[] methods = ImageProcessor.getInterpolationMethods(); private static boolean fillWithBackground; private static boolean processStack = true; private double xscale, yscale, zscale; private String title = "Untitled"; private Vector fields; private double bgValue; private boolean constainAspectRatio = true; private TextField xField, yField, zField, widthField, heightField, depthField; private Rectangle r; private Object fieldWithFocus; private int oldDepth; public void run(String arg) { imp = IJ.getImage(); Roi roi = imp.getRoi(); if (roi != null && !roi.isArea()) imp.deleteRoi(); // ignore any line selection ImageProcessor ip = imp.getProcessor(); if (!showDialog(ip)) return; if (newDepth > 0 && newDepth != oldDepth) { newWindow = true; processStack = true; } if ((ip.getWidth() > 1 && ip.getHeight() > 1) || newWindow) ip.setInterpolationMethod(interpolationMethod); else ip.setInterpolationMethod(ImageProcessor.NONE); ip.setBackgroundValue(bgValue); imp.startTiming(); try { if (newWindow && imp.getStackSize() > 1 && processStack) createNewStack(imp, ip); else scale(ip); } catch (OutOfMemoryError o) { IJ.outOfMemory("Scale"); } IJ.showProgress(1.0); } void createNewStack(ImagePlus imp, ImageProcessor ip) { int nSlices = imp.getStackSize(); int w = imp.getWidth(), h = imp.getHeight(); ImagePlus imp2 = imp.createImagePlus(); Rectangle r = ip.getRoi(); boolean crop = r.width != imp.getWidth() || r.height != imp.getHeight(); ImageStack stack1 = imp.getStack(); ImageStack stack2 = new ImageStack(newWidth, newHeight); ImageProcessor ip1, ip2; int method = interpolationMethod; if (w == 1 || h == 1) method = ImageProcessor.NONE; for (int i = 1; i <= nSlices; i++) { IJ.showStatus("Scale: " + i + "/" + nSlices); ip1 = stack1.getProcessor(i); String label = stack1.getSliceLabel(i); if (crop) { ip1.setRoi(r); ip1 = ip1.crop(); } ip1.setInterpolationMethod(method); ip2 = ip1.resize(newWidth, newHeight, averageWhenDownsizing); if (ip2 != null) stack2.addSlice(label, ip2); IJ.showProgress(i, nSlices); } imp2.setStack(title, stack2); Calibration cal = imp2.getCalibration(); if (cal.scaled()) { cal.pixelWidth *= 1.0 / xscale; cal.pixelHeight *= 1.0 / yscale; } IJ.showProgress(1.0); int[] dim = imp.getDimensions(); imp2.setDimensions(dim[2], dim[3], dim[4]); if (imp.isComposite()) { imp2 = new CompositeImage(imp2, ((CompositeImage) imp).getMode()); ((CompositeImage) imp2).copyLuts(imp); } if (imp.isHyperStack()) imp2.setOpenAsHyperStack(true); if (newDepth > 0 && newDepth != oldDepth) imp2 = (new Resizer()).zScale(imp2, newDepth, interpolationMethod); if (imp2 != null) { imp2.show(); imp2.changes = true; } } void scale(ImageProcessor ip) { if (newWindow) { Rectangle r = ip.getRoi(); ImagePlus imp2 = imp.createImagePlus(); imp2.setProcessor(title, ip.resize(newWidth, newHeight, averageWhenDownsizing)); Calibration cal = imp2.getCalibration(); if (cal.scaled()) { cal.pixelWidth *= 1.0 / xscale; cal.pixelHeight *= 1.0 / yscale; } imp2.show(); imp.trimProcessor(); imp2.trimProcessor(); imp2.changes = true; } else { if (processStack && imp.getStackSize() > 1) { Undo.reset(); StackProcessor sp = new StackProcessor(imp.getStack(), ip); sp.scale(xscale, yscale, bgValue); } else { ip.snapshot(); Undo.setup(Undo.FILTER, imp); ip.setSnapshotCopyMode(true); ip.scale(xscale, yscale); ip.setSnapshotCopyMode(false); } imp.deleteRoi(); imp.updateAndDraw(); imp.changes = true; } } boolean showDialog(ImageProcessor ip) { String macroOptions = Macro.getOptions(); if (macroOptions != null) { if (macroOptions.indexOf(" interpolate") != -1) macroOptions.replaceAll(" interpolate", " interpolation=Bilinear"); else if (macroOptions.indexOf(" interpolation=") == -1) macroOptions = macroOptions + " interpolation=None"; Macro.setOptions(macroOptions); } int bitDepth = imp.getBitDepth(); int stackSize = imp.getStackSize(); boolean isStack = stackSize > 1; oldDepth = stackSize; if (isStack) { xstr = "1.0"; ystr = "1.0"; zstr = "1.0"; } r = ip.getRoi(); int width = newWidth; if (width == 0) width = r.width; int height = (int) ((double) width * r.height / r.width); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); zscale = 1.0; if (xscale != 0.0 && yscale != 0.0) { width = (int) (r.width * xscale); height = (int) (r.height * yscale); } else { xstr = "-"; ystr = "-"; } GenericDialog gd = new GenericDialog("Scale"); gd.addStringField("X Scale:", xstr); gd.addStringField("Y Scale:", ystr); if (isStack) gd.addStringField("Z Scale:", zstr); gd.setInsets(5, 0, 5); gd.addStringField("Width (pixels):", "" + width); gd.addStringField("Height (pixels):", "" + height); if (isStack) { String label = "Depth (images):"; if (imp.isHyperStack()) { int slices = imp.getNSlices(); int frames = imp.getNFrames(); if (slices == 1 && frames > 1) { label = "Depth (frames):"; oldDepth = frames; } else { label = "Depth (slices):"; oldDepth = slices; } } gd.addStringField(label, "" + oldDepth); } fields = gd.getStringFields(); for (int i = 0; i < fields.size(); i++) { ((TextField) fields.elementAt(i)).addTextListener(this); ((TextField) fields.elementAt(i)).addFocusListener(this); } xField = (TextField) fields.elementAt(0); yField = (TextField) fields.elementAt(1); if (isStack) { zField = (TextField) fields.elementAt(2); widthField = (TextField) fields.elementAt(3); heightField = (TextField) fields.elementAt(4); depthField = (TextField) fields.elementAt(5); } else { widthField = (TextField) fields.elementAt(2); heightField = (TextField) fields.elementAt(3); } fieldWithFocus = xField; gd.addChoice("Interpolation:", methods, methods[interpolationMethod]); if (bitDepth == 8 || bitDepth == 24) gd.addCheckbox("Fill with background color", fillWithBackground); gd.addCheckbox("Average when downsizing", averageWhenDownsizing); boolean hyperstack = imp.isHyperStack() || imp.isComposite(); if (isStack && !hyperstack) gd.addCheckbox("Process entire stack", processStack); gd.addCheckbox("Create new window", newWindow); title = WindowManager.getUniqueName(imp.getTitle()); gd.setInsets(10, 0, 0); gd.addStringField("Title:", title, 12); gd.showDialog(); if (gd.wasCanceled()) return false; xstr = gd.getNextString(); ystr = gd.getNextString(); xscale = Tools.parseDouble(xstr, 0.0); yscale = Tools.parseDouble(ystr, 0.0); if (isStack) { zstr = gd.getNextString(); zscale = Tools.parseDouble(ystr, 0.0); } String wstr = gd.getNextString(); newWidth = (int) Tools.parseDouble(wstr, 0); newHeight = (int) Tools.parseDouble(gd.getNextString(), 0); if (newHeight != 0 && (wstr.equals("-") || wstr.equals("0"))) newWidth = (int) (newHeight * (double) r.width / r.height); if (newWidth == 0 || newHeight == 0) { IJ.error("Scaler", "Width or height is 0"); return false; } if (xscale > 0.0 && yscale > 0.0) { newWidth = (int) (r.width * xscale); newHeight = (int) (r.height * yscale); } if (isStack) newDepth = (int) Tools.parseDouble(gd.getNextString(), 0); interpolationMethod = gd.getNextChoiceIndex(); if (bitDepth == 8 || bitDepth == 24) fillWithBackground = gd.getNextBoolean(); averageWhenDownsizing = gd.getNextBoolean(); if (isStack && !hyperstack) processStack = gd.getNextBoolean(); if (hyperstack) processStack = true; newWindow = gd.getNextBoolean(); if (xscale == 0.0) { xscale = (double) newWidth / r.width; yscale = (double) newHeight / r.height; } title = gd.getNextString(); if (fillWithBackground) { Color bgc = Toolbar.getBackgroundColor(); if (bitDepth == 8) bgValue = ip.getBestIndex(bgc); else if (bitDepth == 24) bgValue = bgc.getRGB(); } else bgValue = 0.0; return true; } public void textValueChanged(TextEvent e) { Object source = e.getSource(); double newXScale = xscale; double newYScale = yscale; double newZScale = zscale; if (source == xField && fieldWithFocus == xField) { String newXText = xField.getText(); newXScale = Tools.parseDouble(newXText, 0); if (newXScale == 0) return; if (newXScale != xscale) { int newWidth = (int) (newXScale * r.width); widthField.setText("" + newWidth); if (constainAspectRatio) { yField.setText(newXText); int newHeight = (int) (newXScale * r.height); heightField.setText("" + newHeight); } } } else if (source == yField && fieldWithFocus == yField) { String newYText = yField.getText(); newYScale = Tools.parseDouble(newYText, 0); if (newYScale == 0) return; if (newYScale != yscale) { int newHeight = (int) (newYScale * r.height); heightField.setText("" + newHeight); } } else if (source == zField && fieldWithFocus == zField) { String newZText = zField.getText(); newZScale = Tools.parseDouble(newZText, 0); if (newZScale == 0) return; if (newZScale != zscale) { int nSlices = imp.getStackSize(); if (imp.isHyperStack()) { int slices = imp.getNSlices(); int frames = imp.getNFrames(); if (slices == 1 && frames > 1) nSlices = frames; else nSlices = slices; } int newDepth = (int) (newZScale * nSlices); depthField.setText("" + newDepth); } } else if (source == widthField && fieldWithFocus == widthField) { int newWidth = (int) Tools.parseDouble(widthField.getText(), 0.0); if (newWidth != 0) { int newHeight = (int) (newWidth * (double) r.height / r.width); heightField.setText("" + newHeight); xField.setText("-"); yField.setText("-"); newXScale = 0.0; newYScale = 0.0; } } else if (source == depthField && fieldWithFocus == depthField) { int newDepth = (int) Tools.parseDouble(depthField.getText(), 0.0); if (newDepth != 0) { zField.setText("-"); newZScale = 0.0; } } xscale = newXScale; yscale = newYScale; zscale = newZScale; } public void focusGained(FocusEvent e) { fieldWithFocus = e.getSource(); if (fieldWithFocus == widthField) constainAspectRatio = true; else if (fieldWithFocus == yField) constainAspectRatio = false; } public void focusLost(FocusEvent e) {} }
void apply(ImagePlus imp, ImageProcessor ip) { // this.setCursor(wait); // IJ.showStatus("Bandpassing slice "+previousSlice); java.awt.Color col; if (invert.getState()) col = Toolbar.getForegroundColor(); else col = Toolbar.getBackgroundColor(); ip.setColor(col); int fill = ip.BLACK; int keep = 0; if (bandPassH.getState() && bandPassS.getState() && bandPassB.getState()) { // PPP All pass for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && !bandPassS.getState() && !bandPassB.getState()) { // SSS All stop for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (bandPassH.getState() && bandPassS.getState() && !bandPassB.getState()) { // PPS for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && !bandPassS.getState() && bandPassB.getState()) { // SSP for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (bandPassH.getState() && !bandPassS.getState() && !bandPassB.getState()) { // PSS for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && bandPassS.getState() && bandPassB.getState()) { // SPP for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (!bandPassH.getState() && bandPassS.getState() && !bandPassB.getState()) { // SPS for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue >= minHue) && (hue <= maxHue)) || ((sat < minSat) || (sat > maxSat)) || ((bri >= minBri) && (bri <= maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } else if (bandPassH.getState() && !bandPassS.getState() && bandPassB.getState()) { // PSP for (int j = 0; j < numPixels; j++) { int hue = hSource[j] & 0xff; int sat = sSource[j] & 0xff; int bri = bSource[j] & 0xff; if (((hue < minHue) || (hue > maxHue)) || ((sat >= minSat) && (sat <= maxSat)) || ((bri < minBri) || (bri > maxBri))) fillMask[j] = fill; else fillMask[j] = keep; } } ip.fill(fillMask); if (threshold.getState()) { ip.invert(); for (int j = 0; j < numPixels; j++) { if (fillMask[j] == fill) fillMask[j] = keep; else fillMask[j] = fill; } ip.fill(fillMask); ip.invert(); } }
ImageProcessor setup(ImagePlus imp) { ImageProcessor ip; int type = imp.getType(); if (type != ImagePlus.COLOR_RGB) return null; ip = imp.getProcessor(); int id = imp.getID(); int slice = imp.getCurrentSlice(); if ((id != previousImageID) | (slice != previousSlice) | (flag)) { flag = false; // if true, flags a change from HSB to RGB or viceversa numSlices = imp.getStackSize(); stack = imp.getStack(); width = stack.getWidth(); height = stack.getHeight(); numPixels = width * height; hSource = new byte[numPixels]; sSource = new byte[numPixels]; bSource = new byte[numPixels]; // restore = (int[])ip.getPixelsCopy(); //This runs into trouble sometimes, so do it the // long way: int[] temp = (int[]) ip.getPixels(); restore = new int[numPixels]; for (int i = 0; i < numPixels; i++) restore[i] = temp[i]; fillMask = new int[numPixels]; // Get hsb or rgb from image. ColorProcessor cp = (ColorProcessor) ip; IJ.showStatus("Gathering data"); if (isRGB) cp.getRGB(hSource, sSource, bSource); else cp.getHSB(hSource, sSource, bSource); IJ.showStatus("done"); // Create a spectrum ColorModel for the Hue histogram plot. Color c; byte[] reds = new byte[256]; byte[] greens = new byte[256]; byte[] blues = new byte[256]; for (int i = 0; i < 256; i++) { c = Color.getHSBColor(i / 255f, 1f, 1f); reds[i] = (byte) c.getRed(); greens[i] = (byte) c.getGreen(); blues[i] = (byte) c.getBlue(); } ColorModel cm = new IndexColorModel(8, 256, reds, greens, blues); // Make an image with just the hue from the RGB image and the spectrum LUT. // This is just for a hue histogram for the plot. Do not show it. // ByteProcessor bpHue = new ByteProcessor(width,height,h,cm); ByteProcessor bpHue = new ByteProcessor(width, height, hSource, cm); ImagePlus impHue = new ImagePlus("Hue", bpHue); // impHue.show(); ByteProcessor bpSat = new ByteProcessor(width, height, sSource, cm); ImagePlus impSat = new ImagePlus("Sat", bpSat); // impSat.show(); ByteProcessor bpBri = new ByteProcessor(width, height, bSource, cm); ImagePlus impBri = new ImagePlus("Bri", bpBri); // impBri.show(); plot.setHistogram(impHue, 0); splot.setHistogram(impSat, 1); bplot.setHistogram(impBri, 2); updateLabels(); updatePlot(); updateScrollBars(); imp.updateAndDraw(); } previousImageID = id; previousSlice = slice; return ip; }
private void doRGBProjection(ImageStack stack) { ImageStack[] channels = ChannelSplitter.splitRGB(stack, true); ImagePlus red = new ImagePlus("Red", channels[0]); ImagePlus green = new ImagePlus("Green", channels[1]); ImagePlus blue = new ImagePlus("Blue", channels[2]); imp.unlock(); ImagePlus saveImp = imp; imp = red; color = "(red)"; doProjection(); ImagePlus red2 = projImage; imp = green; color = "(green)"; doProjection(); ImagePlus green2 = projImage; imp = blue; color = "(blue)"; doProjection(); ImagePlus blue2 = projImage; int w = red2.getWidth(), h = red2.getHeight(), d = red2.getStackSize(); if (method == SD_METHOD) { ImageProcessor r = red2.getProcessor(); ImageProcessor g = green2.getProcessor(); ImageProcessor b = blue2.getProcessor(); double max = 0; double rmax = r.getStatistics().max; if (rmax > max) max = rmax; double gmax = g.getStatistics().max; if (gmax > max) max = gmax; double bmax = b.getStatistics().max; if (bmax > max) max = bmax; double scale = 255 / max; r.multiply(scale); g.multiply(scale); b.multiply(scale); red2.setProcessor(r.convertToByte(false)); green2.setProcessor(g.convertToByte(false)); blue2.setProcessor(b.convertToByte(false)); } RGBStackMerge merge = new RGBStackMerge(); ImageStack stack2 = merge.mergeStacks(w, h, d, red2.getStack(), green2.getStack(), blue2.getStack(), true); imp = saveImp; projImage = new ImagePlus(makeTitle(), stack2); }