@Override public final void run() { while (!isInterrupted()) { final boolean b; synchronized (this) { b = pleaseRepaint; pleaseRepaint = keepPainting; } if (b) { final long t = System.currentTimeMillis(); lambda += dt * dLambda; phi += dt * dPhi; this.camera.setOrientation(lambda, phi, rho); mapper.map(temp); final Object targetPixels = target.getPixels(); target.setPixels(temp.getPixels()); temp.setPixels(targetPixels); impTarget.updateAndDraw(); if (visualize) visualize(impSource, temp.getWidth(), temp.getHeight(), p); dt = (System.currentTimeMillis() - t) / 1000f; } synchronized (this) { try { if (!pleaseRepaint) wait(); } catch (final InterruptedException e) { } } } }
/** * Returns an ImageProcessor for the specified slice, were 1<=n<=nslices. Returns null if the * stack is empty. */ public ImageProcessor getProcessor(int n) { ImageProcessor ip; if (n < 1 || n > nSlices) throw new IllegalArgumentException(outOfRange + n); if (nSlices == 0) return null; if (stack[0] == null) throw new IllegalArgumentException("Pixel array is null"); if (stack[0] instanceof byte[]) ip = new ByteProcessor(width, height, null, cm); else if (stack[0] instanceof short[]) ip = new ShortProcessor(width, height, null, cm); else if (stack[0] instanceof int[]) ip = new ColorProcessor(width, height, null); else if (stack[0] instanceof float[]) ip = new FloatProcessor(width, height, null, cm); else throw new IllegalArgumentException("Unknown stack type"); ip.setPixels(stack[n - 1]); if (min != Double.MAX_VALUE && ip != null && !(ip instanceof ColorProcessor)) ip.setMinAndMax(min, max); if (cTable != null) ip.setCalibrationTable(cTable); return ip; }
/** * Converts a binary image into a 8-bit grayscale Euclidean Distance Map (EDM). Each foreground * (nonzero) pixel in the binary image is assigned a value equal to its distance from the nearest * background (zero) pixel. */ public void toEDM(ImageProcessor ip) { ip.setPixels(0, makeFloatEDM(ip, 0, false)); ip.resetMinAndMax(); }
/** Called by the PlugInFilterRunner to process the image or one frame of a stack */ public void run(ImageProcessor ip) { if (interrupted) return; int width = ip.getWidth(); int height = ip.getHeight(); int backgroundValue = (processType == VORONOI) ? (background255 ? 0 : (byte) 255) : // Voronoi needs EDM of the background (background255 ? (byte) 255 : 0); // all others do EDM of the foreground if (USES_WATERSHED[processType]) nPasses = 0; // watershed has its own progress bar FloatProcessor floatEdm = makeFloatEDM(ip, backgroundValue, false); ByteProcessor maxIp = null; if (USES_MAX_FINDER[processType]) { if (processType == VORONOI) floatEdm.multiply(-1); // Voronoi starts from minima of EDM int maxOutputType = USES_WATERSHED[processType] ? MaximumFinder.SEGMENTED : MaximumFinder.SINGLE_POINTS; boolean isEDM = processType != VORONOI; maxIp = maxFinder.findMaxima( floatEdm, MAXFINDER_TOLERANCE, ImageProcessor.NO_THRESHOLD, maxOutputType, false, isEDM); if (maxIp == null) { // segmentation cancelled by user? interrupted = true; return; } else if (processType != WATERSHED) { if (processType == VORONOI) floatEdm.multiply(-1); resetMasked(floatEdm, maxIp, processType == VORONOI ? -1 : 0); } } ImageProcessor outIp = null; if (processType == WATERSHED) { if (background255) maxIp.invert(); ip.copyBits(maxIp, 0, 0, Blitter.COPY); ip.setBinaryThreshold(); } else switch (outImageType) { // for all these, output contains the values of the EDM case FLOAT: outIp = floatEdm; break; case SHORT: floatEdm.setMinAndMax(0., 65535.); outIp = floatEdm.convertToShort(true); break; case BYTE: floatEdm.setMinAndMax(0., 255.); outIp = floatEdm.convertToByte(true); break; case BYTE_OVERWRITE: ip.setPixels(0, floatEdm); if (floatEdm.getMax() > 255.) ip.resetMinAndMax(); // otherwise we have max of floatEdm } if (outImageType != BYTE_OVERWRITE) { // new output image if (outStack == null) { outImp = new ImagePlus(TITLE_PREFIX[processType] + imp.getShortTitle(), outIp); } else outStack.setPixels(outIp.getPixels(), pfr.getSliceNumber()); } } // public void run
/** Apply a local Binary Partition filter */ public static void localBinaryPartition(ImageProcessor processor) { LocalBinaryPartitionFilter localbinary = new LocalBinaryPartitionFilter(processor.convertToByte(true)); byte[] bytes = localbinary.performExtraction(); processor.setPixels(bytes); }
/** * @param ip * @param v */ public static void run(final ImageProcessor ip, final float v) { final int w = ip.getWidth(); final int h = ip.getHeight(); final int wh = w * h; final ImageProcessor ipTarget = ip.duplicate(); int numSaturatedPixels = 0; do { numSaturatedPixels = 0; for (int i = 0; i < wh; ++i) if (ip.getf(i) == v) { ++numSaturatedPixels; final int y = i / w; final int x = i % w; float s = 0; float n = 0; if (y > 0) { if (x > 0) { final float tl = ip.getf(x - 1, y - 1); if (tl != v) { s += 0.5f * tl; n += 0.5f; } } final float t = ip.getf(x, y - 1); if (t != v) { s += t; n += 1; } if (x < w - 1) { final float tr = ip.getf(x + 1, y - 1); if (tr != v) { s += 0.5f * tr; n += 0.5f; } } } if (x > 0) { final float l = ip.getf(x - 1, y); if (l != v) { s += l; n += 1; } } if (x < w - 1) { final float r = ip.getf(x + 1, y); if (r != v) { s += r; n += 1; } } if (y < h - 1) { if (x > 0) { final float bl = ip.getf(x - 1, y + 1); if (bl != v) { s += 0.5f * bl; n += 0.5f; } } final float b = ip.getf(x, y + 1); if (b != v) { s += b; n += 1; } if (x < w - 1) { final float br = ip.getf(x + 1, y + 1); if (br != v) { s += 0.5f * br; n += 0.5f; } } } if (n > 0) ipTarget.setf(i, s / n); } ip.setPixels(ipTarget.getPixelsCopy()); } while (numSaturatedPixels > 0); }