ij.process.ShortProcessor Java Examples
The following examples show how to use
ij.process.ShortProcessor.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DistanceTransform3x3Short.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private void normalizeResult(ShortProcessor distMap, ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Normalization")); // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // normalization weight int w0 = weights[0]; for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { if ((int) labelImage.getf(x, y) > 0) { distMap.set(x, y, distMap.get(x, y) / w0); } } } }
Example #2
Source File: DistanceTransform5x5Short.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private ShortProcessor initializeResult(ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Initialization")); // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // create new empty image, and fill it with black ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (background) or Inf (foreground) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int label = (int) labelImage.getf(x, y); distMap.set(x, y, label == 0 ? 0 : Short.MAX_VALUE); } } return distMap; }
Example #3
Source File: DistanceTransform5x5Short.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private void normalizeResult(ShortProcessor distMap, ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Normalization")); // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // normalization weight int w0 = weights[0]; for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { if ((int) labelImage.getf(x, y) > 0) { distMap.set(x, y, distMap.get(x, y) / w0); } } } }
Example #4
Source File: GeodesicDistanceTransformShort.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private ShortProcessor initialize(ImageProcessor marker) { // size of image sizeX = marker.getWidth(); sizeY = marker.getHeight(); ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (foreground) or Inf (background) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int val = marker.get(x, y) & 0x00ff; distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0); } } return distMap; }
Example #5
Source File: GeodesicDistanceTransformShort5x5.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private ShortProcessor initialize(ImageProcessor marker) { // size of image sizeX = marker.getWidth(); sizeY = marker.getHeight(); ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (foreground) or Inf (background) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int val = marker.get(x, y) & 0x00ff; distMap.set(x, y, val == 0 ? Short.MAX_VALUE : 0); } } return distMap; }
Example #6
Source File: LabelImages.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
/** * Creates a label image with the appropriate class to store the required * number of labels. * * @param width * the width of the new label image * @param height * the height of the new label image * @param nLabels * expected number of labels in new image * @return a new ImageProcessor with type adapted to store the expected * number of labels */ public static final ImageProcessor createLabelImage(int width, int height, int nLabels) { if (nLabels < 256) { return new ByteProcessor(width, height); } else if (nLabels < 256 * 256) { return new ShortProcessor(width, height); } else if (nLabels < (0x01 << 23)) { return new FloatProcessor(width, height); } else { IJ.error("Too many classes"); return null; } }
Example #7
Source File: BorderManager.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
public BorderManager createBorderManager(ImageProcessor image) { switch((Type) this) { case REPLICATED: return new ReplicatedBorder(image); case PERIODIC: return new PeriodicBorder(image); case MIRRORED: return new MirroringBorder(image); case BLACK: return new ConstantBorder(image, 0); case WHITE: return new ConstantBorder(image, 0xFFFFFF); case GRAY: if (image instanceof ColorProcessor) return new ConstantBorder(image, 0x7F7F7F); if (image instanceof ShortProcessor) return new ConstantBorder(image, 0x007FFF); return new ConstantBorder(image, 127); default: throw new RuntimeException("Unknown border manager for type " + this); } }
Example #8
Source File: DistanceTransform3x3Short.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 6 votes |
private ShortProcessor initializeResult(ImageProcessor labelImage) { this.fireStatusChanged(new AlgoEvent(this, "Initialization")); // size of image int sizeX = labelImage.getWidth(); int sizeY = labelImage.getHeight(); // create new empty image, and fill it with black ShortProcessor distMap = new ShortProcessor(sizeX, sizeY); distMap.setValue(0); distMap.fill(); // initialize empty image with either 0 (background) or Inf (foreground) for (int y = 0; y < sizeY; y++) { for (int x = 0; x < sizeX; x++) { int label = (int) labelImage.getf(x, y); distMap.set(x, y, label == 0 ? 0 : Short.MAX_VALUE); } } return distMap; }
Example #9
Source File: DataGeneratorPlugIn.java From thunderstorm with GNU General Public License v3.0 | 6 votes |
@Override public void run() { for(int f = frame_start; f <= frame_end; f++) { if(Thread.interrupted()) { local_stack.clear(); local_table.clear(); return; } processingNewFrame("ThunderSTORM is generating frame %d out of %d..."); FloatProcessor backgroundMeanIntensity; backgroundMeanIntensity = createBackgroundIntensityImage(); Vector<EmitterModel> molecules = singleFixedMolecule ? datagen.generateSingleFixedMolecule(width, height, 0, 0, intensity_range, psf) : datagen.generateMolecules(width, height, densityMask, density, intensity_range, psf); ShortProcessor slice = datagen.renderFrame(width, height, f, drift, molecules, backgroundMeanIntensity); local_stack.add(slice); local_table.add(molecules); } }
Example #10
Source File: ImageUtils.java From orbit-image-analysis with GNU General Public License v3.0 | 6 votes |
/** * Converts image file into a BufferedImage * * @param inputFile * @return * @throws IOException */ public static BufferedImage convertImageFileToBI(String inputFile) throws IOException { BufferedImage bi = null; try { ImageIO.setUseCache(false); bi = ImageIO.read(new File(inputFile)); } catch (javax.imageio.IIOException e) // in case tiff format is not recognized, try to resolve exception using ImagePlus (ImageJ) methods { if (inputFile.endsWith(".tif") || inputFile.endsWith(".tiff")) { ImagePlus ip = new ImagePlus(inputFile); // :TODO validate if tiff to be read is truly 16 bit :: otherwise there could be a scaling issue occurring afterwards bi = ((ShortProcessor) ip.getProcessor().convertToShort(false)).get16BitBufferedImage(); } else { throw e; } } return bi; }
Example #11
Source File: ImagePlusMatConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 6 votes |
/** * Dispatcher method. Duplicates {@link ImageProcessor} to the corresponding * OpenCV image of type {@link Mat}. TODO: Could be coded more elegantly ;-) * * @param ip The {@link ImageProcessor} to be converted * @return The OpenCV image (of type {@link Mat}) */ public static Mat toMat(ImageProcessor ip) { Mat mat = null; if (ip instanceof ByteProcessor) { mat = toMat((ByteProcessor) ip); } else if (ip instanceof ColorProcessor) { mat = toMat((ColorProcessor) ip); } else if (ip instanceof ShortProcessor) { mat = toMat((ShortProcessor) ip); } else if (ip instanceof FloatProcessor) { mat = toMat((FloatProcessor) ip); } else { throw new IllegalArgumentException("cannot convert to Mat: " + ip); } return mat; }
Example #12
Source File: BinaryImagesTest.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
@Test public final void testDistanceMapImageProcessorShortArrayBoolean() { ImageProcessor image = createBinarySquareImage(); short[] weights = new short[]{3, 4}; ImageProcessor result = BinaryImages.distanceMap(image, weights, true); assertNotNull(result); assertTrue(result instanceof ShortProcessor); assertEquals(image.getWidth(), result.getWidth()); assertEquals(image.getHeight(), result.getHeight()); assertEquals(3, result.get(4, 4), 1e-12); }
Example #13
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** A method that circumvents the findMinAndMax when creating a float processor from an existing processor. Ignores color calibrations and does no scaling at all. */ static public final FloatProcessor fastConvertToFloat(final ImageProcessor ip, final int type) { switch (type) { case ImagePlus.GRAY16: return fastConvertToFloat((ShortProcessor)ip); case ImagePlus.GRAY32: return (FloatProcessor)ip; case ImagePlus.GRAY8: case ImagePlus.COLOR_256: return fastConvertToFloat((ByteProcessor)ip); case ImagePlus.COLOR_RGB: return (FloatProcessor)ip.convertToFloat(); // SLOW } return null; }
Example #14
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
static public final ImageProcessor createProcessor(final int type, final int width, final int height) { switch (type) { case ImagePlus.GRAY8: return new ByteProcessor(width, height); case ImagePlus.GRAY16: return new ShortProcessor(width, height); case ImagePlus.GRAY32: return new FloatProcessor(width, height); case ImagePlus.COLOR_RGB: return new ColorProcessor(width, height); } return null; }
Example #15
Source File: DownsamplerTest.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
final private static void testShort( ShortProcessor ipShort ) { final double min = ipShort.getMin(); final double max = ipShort.getMax(); while( ipShort.getWidth() > 32 ) { ipShort = Downsampler.downsampleShortProcessor( ipShort ); ipShort.setMinAndMax( min, max ); } }
Example #16
Source File: DownsamplerTest.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** * Test downsampling the pyramid of a short image + byte alpha channel * including the byte mapping of the short doing the alpha channel in a * separate loop. * * @param ba */ final private static void testShortAlphaIndependently( Pair< ShortProcessor, byte[] > ba, ByteProcessor alpha ) { while( ba.a.getWidth() > 32 ) { ba = Downsampler.downsampleShort( ba.a ); alpha = Downsampler.downsampleByteProcessor( alpha ); // new ImagePlus( "pixels " + ba.a.getWidth(), ba.a ).show(); // new ImagePlus( "pixels to byte " + ba.a.getWidth(), new ByteProcessor( ba.a.getWidth(), ba.a.getHeight(), ba.b[ 0 ], null ) ).show(); // new ImagePlus( "alpha " + ba.a.getWidth(), new ByteProcessor( ba.a.getWidth(), ba.a.getHeight(), ba.b[ 1 ], null ) ).show(); } }
Example #17
Source File: DistanceTransform3x3Short.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Computes the distance map of the distance to the nearest pixel with a different value. * The function returns a new short processor the same size as the input, * with values greater or equal to zero. * * @param labelImage a label image with black pixels (0) as foreground * @return a new instance of ShortProcessor containing: <ul> * <li> 0 for each background pixel </li> * <li> the (strictly positive) distance to the nearest background pixel otherwise</li> * </ul> */ public ShortProcessor distanceMap(ImageProcessor labelImage) { ShortProcessor distMap = initializeResult(labelImage); // Two iterations are enough to compute distance map to boundary forwardScan(distMap, labelImage); backwardScan(distMap, labelImage); // Normalize values by the first weight if (this.normalizeMap) { normalizeResult(distMap, labelImage); } // Compute max value within the mask for setting min/max of ImageProcessor double maxVal = LabelValues.maxValueWithinLabels(distMap, labelImage); distMap.setMinAndMax(0, maxVal); // Forces the display to non-inverted LUT if (distMap.isInvertedLut()) distMap.invertLut(); this.fireStatusChanged(new AlgoEvent(this, "")); return distMap; }
Example #18
Source File: IntegralHistogram2d.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
@SuppressWarnings("unused") static public final void main(String[] args) { final ShortProcessor sp = (ShortProcessor) IJ.openImage("/home/albert/Desktop/t2/bridge-16bit.tif").getProcessor(); final ShortProcessor filtered = median(sp, 64, 0, 65535, 100); new ImageJ(); new ImagePlus("median", filtered).show(); }
Example #19
Source File: Utils.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
/** A method that circumvents the findMinAndMax when creating a float processor from an existing processor. Ignores color calibrations and does no scaling at all. */ static public final FloatProcessor fastConvertToFloat(final ShortProcessor ip) { final short[] pix = (short[])ip.getPixels(); final float[] data = new float[pix.length]; for (int i=0; i<pix.length; i++) data[i] = pix[i]&0xffff; final FloatProcessor fp = new FloatProcessorT2(ip.getWidth(), ip.getHeight(), data, ip.getColorModel(), ip.getMin(), ip.getMax()); return fp; }
Example #20
Source File: ExportUnsignedShort.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
final static protected ShortProcessor mapIntensities( final PatchIntensityRange pir, final double min, final double max ) { final double a = 65535.0 / ( max - min ); final ImageProcessor source = pir.patch.getImageProcessor(); final short[] targetPixels = new short[ source.getWidth() * source.getHeight() ]; for ( int i = 0; i < targetPixels.length; ++i ) { targetPixels[ i ] = ( short )Math.max( 0, Math.min( 65535, Math.round( ( ( source.getf( i ) - pir.patch.getMin() ) / pir.a - min ) * a ) ) ); } final ShortProcessor target = new ShortProcessor( source.getWidth(), source.getHeight(), targetPixels, null ); target.setMinAndMax( -min * a, ( 1.0 - min ) * a ); return target; }
Example #21
Source File: DistanceTransform5x5Short.java From MorphoLibJ with GNU Lesser General Public License v3.0 | 5 votes |
/** * Computes the distance map of the distance to the nearest pixel with a * different value. The function returns a new short processor the same size * as the input, with values greater or equal to zero. * * @param labelImage * a label image with black pixels (0) as foreground * @return a new instance of ShortProcessor containing: * <ul> * <li>0 for each background pixel</li> * <li>the (strictly positive) distance to the nearest background * pixel otherwise</li> * </ul> */ public ShortProcessor distanceMap(ImageProcessor labelImage) { ShortProcessor distMap = initializeResult(labelImage); // Two iterations are enough to compute distance map to boundary forwardScan(distMap, labelImage); backwardScan(distMap, labelImage); // Normalize values by the first weight if (this.normalizeMap) { normalizeResult(distMap, labelImage); } // Compute max value within the mask for setting min/max of ImageProcessor double maxVal = LabelValues.maxValueWithinLabels(distMap, labelImage); distMap.setMinAndMax(0, maxVal); // Forces the display to non-inverted LUT if (distMap.isInvertedLut()) distMap.invertLut(); this.fireStatusChanged(new AlgoEvent(this, "")); return distMap; }
Example #22
Source File: SingleChannelMapper.java From render with GNU General Public License v2.0 | 5 votes |
public static ImageProcessorWithMasks normalizeSourceForTarget(final ImageProcessorWithMasks source, final ImageProcessor target) throws IllegalArgumentException { final ImageProcessorWithMasks normalizedSource; if (target instanceof ByteProcessor) { normalizedSource = new ImageProcessorWithMasks(source.ip.convertToByteProcessor(), source.mask, null); } else if (target instanceof ShortProcessor) { normalizedSource = new ImageProcessorWithMasks(source.ip.convertToShortProcessor(), source.mask, null); } else if (target instanceof FloatProcessor) { normalizedSource = new ImageProcessorWithMasks(source.ip.convertToFloatProcessor(), source.mask, null); } else if (target instanceof ColorProcessor) { normalizedSource = new ImageProcessorWithMasks(source.ip.convertToColorProcessor(), source.mask, null); } else { throw new IllegalArgumentException("conversion to " + target.getClass() + " is not supported"); } return normalizedSource; }
Example #23
Source File: ShortRenderer.java From render with GNU General Public License v2.0 | 5 votes |
/** * Converts the processor to a short (16-bit) image. * * @param renderedImageProcessorWithMasks processor to convert. * * @return the converted image. */ public static BufferedImage targetToShortImage(final ImageProcessorWithMasks renderedImageProcessorWithMasks) { // convert to 16-bit gray-scale final ShortProcessor sp = renderedImageProcessorWithMasks.ip.convertToShortProcessor(); final BufferedImage image = new BufferedImage(sp.getWidth(), sp.getHeight(), BufferedImage.TYPE_USHORT_GRAY); final WritableRaster raster = image.getRaster(); raster.setDataElements(0, 0, sp.getWidth(), sp.getHeight(), sp.getPixels()); return image; }
Example #24
Source File: LabelImageProcessorCache.java From render with GNU General Public License v2.0 | 5 votes |
/** * @param width image width. * @param height image height. * * @return a 16-bit gray image filled with white pixels. */ public static BufferedImage createEmptyImage(final int width, final int height) { final short[] pixels = new short[width * height]; Arrays.fill(pixels, (short) MAX_LABEL_INTENSITY); final ShortProcessor labelProcessor = new ShortProcessor(width, height, pixels, null); labelProcessor.setMinAndMax(0, MAX_LABEL_INTENSITY); return labelProcessor.getBufferedImage(); }
Example #25
Source File: ExportBestFlatImage.java From TrakEM2 with GNU General Public License v3.0 | 5 votes |
protected FloatProcessor convertToFloat( final ShortProcessor sp ) { final short[] pixS = (short[]) sp.getPixels(); loader.releaseToFit( pixS.length * 4 ); final float[] pixF = new float[pixS.length]; for ( int i=0; i<pixS.length; ++i) { pixF[i] = pixS[i] & 0xffff; } return new FloatProcessor( sp.getWidth(), sp.getHeight(), pixF ); }
Example #26
Source File: DataGeneratorPlugIn.java From thunderstorm with GNU General Public License v3.0 | 5 votes |
public GeneratorWorker(int frame_start, int frame_end) { this.frame_start = frame_start; this.frame_end = frame_end; //this.bkg = bkg; datagen = new DataGenerator(); local_stack = new Vector<ShortProcessor>(); local_table = new Vector<Vector<EmitterModel>>(); }
Example #27
Source File: MatImagePlusConverter.java From IJ-OpenCV with GNU General Public License v3.0 | 5 votes |
private static ShortProcessor makeShortProcessor(Mat mat) { if (mat.type() != opencv_core.CV_16UC1) { throw new IllegalArgumentException("wrong Mat type: " + mat.type()); } final int w = mat.cols(); final int h = mat.rows(); ShortProcessor sp = new ShortProcessor(w, h); ShortPointer sptr = new ShortPointer(mat.data()); sptr.get((short[]) sp.getPixels()); sptr.close(); return sp; }
Example #28
Source File: DownsamplerMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static private final ImageBytes asBytes(final ShortProcessor sp, final ByteProcessor mask) { return asBytes((ByteProcessor)sp.convertToByte(true), mask); }
Example #29
Source File: ExportUnsignedShort.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
final static protected void map( final PatchTransform pt, final double x, final double y, final ShortProcessor mappedIntensities, final ShortProcessor target) { map( pt, x, y, Double.NaN, mappedIntensities, target); }
Example #30
Source File: DownsamplerMipMaps.java From TrakEM2 with GNU General Public License v3.0 | 4 votes |
static private final ImageBytes asBytes(final ShortProcessor sp) { return asBytes((ByteProcessor)sp.convertToByte(true)); }