net.imglib2.img.ImgFactory Java Examples
The following examples show how to use
net.imglib2.img.ImgFactory.
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: Align.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public Align(final RandomAccessibleInterval< T > template, final ImgFactory< FloatType > factory, WarpFunction model) { this.template = template; n = template.numDimensions(); warpFunction = model; numParameters = warpFunction.numParameters(); currentTransform = new AffineTransform( n ); final long[] dim = new long[n + 1]; for ( int d = 0; d < n; ++d ) dim[d] = template.dimension( d ); dim[n] = n; final Img< FloatType > gradients = factory.create( dim, new FloatType() ); gradients( Views.extendBorder( template ), gradients ); dim[n] = numParameters; descent = factory.create( dim, new FloatType() ); computeSteepestDescents( gradients, warpFunction, descent ); Hinv = computeInverseHessian( descent ); error = factory.create( template, new FloatType() ); }
Example #2
Source File: MVDeconFFTThreads.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
final protected static Thread getCUDAThread2( final AtomicInteger ai, final ImgFactory< FloatType > blockFactory, final Block[] blocks, final int[] blockSize, final Img< FloatType > image, final Img< FloatType > result, final int deviceId, final Img< FloatType > kernel2 ) { final Thread cudaThread2 = new Thread( new Runnable() { public void run() { final Img< FloatType > block = blockFactory.create( Util.int2long( blockSize ), new FloatType() ); int i; while ( ( i = ai.getAndIncrement() ) < blocks.length ) convolve2BlockCUDA( blocks[ i ], deviceId, image, result, block, kernel2 ); } }); return cudaThread2; }
Example #3
Source File: ColocalisationTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * Gaussian Smooth of the input image using intermediate float format. * * @param <T> * @param img * @param sigma * @return */ public static <T extends RealType<T> & NativeType<T>> Img<T> gaussianSmooth(RandomAccessibleInterval<T> img, double[] sigma) { Interval interval = Views.iterable(img); ImgFactory<T> outputFactory = new ArrayImgFactory<>(Util.getTypeFromInterval(img)); final long[] dim = new long[img.numDimensions()]; img.dimensions(dim); Img<T> output = outputFactory.create(dim); final long[] pos = new long[img.numDimensions()]; Arrays.fill(pos, 0); Localizable origin = new Point(pos); ImgFactory<FloatType> tempFactory = new ArrayImgFactory<>(new FloatType()); RandomAccessible<T> input = Views.extendMirrorSingle(img); Gauss.inFloat(sigma, input, interval, output, origin, tempFactory); return output; }
Example #4
Source File: ColocalisationTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * This method creates a noise image that has a specified mean. Every pixel * has a value uniformly distributed around mean with the maximum spread * specified. * * @return IllegalArgumentException if specified means and spreads are not * valid */ public static <T extends RealType<T> & NativeType<T>> Img<T> produceMeanBasedNoiseImage(T type, int width, int height, double mean, double spread, double[] smoothingSigma, long seed) throws IllegalArgumentException { if (mean < spread || (mean + spread) > type.getMaxValue()) { throw new IllegalArgumentException( "Mean must be larger than spread, and mean plus spread must be smaller than max of the type"); } // create the new image ImgFactory<T> imgFactory = new ArrayImgFactory<>(type); Img<T> noiseImage = imgFactory.create(width, height); Random r = new Random(seed); for (T value : Views.iterable(noiseImage)) { value.setReal(mean + ((r.nextDouble() - 0.5) * spread)); } // TODO: call Ops filter.gauss instead return gaussianSmooth(noiseImage, smoothingSigma); }
Example #5
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see ImgOpener#openImgs(Reader, ImgFactory, SCIFIOConfig) */ public static <T extends RealType<T>> List<SCIFIOImgPlus<T>> openAll( final Reader reader, final T type, final ImgFactory<T> imgFactory, final SCIFIOConfig config) { final ImgOpener opener = opener(); List<SCIFIOImgPlus<T>> imgPlus = null; try { imgPlus = opener.openImgs(reader, imgFactory.imgFactory(type), config); register(imgPlus, opener); } catch (final ImgIOException e) { openError(reader.getMetadata().getSourceLocation(), e); } return imgPlus; }
Example #6
Source File: Downsample.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
public static < T extends RealType< T > > RandomAccessibleInterval< T > simple2x( final RandomAccessibleInterval<T> input, final ImgFactory< T > imgFactory, final boolean[] downsampleInDim ) { RandomAccessibleInterval< T > src = input; for ( int d = 0; d < input.numDimensions(); ++d ) if ( downsampleInDim[ d ] ) { final long dim[] = new long[ input.numDimensions() ]; for ( int e = 0; e < input.numDimensions(); ++e ) { if ( e == d ) dim[ e ] = src.dimension( e ) / 2; else dim[ e ] = src.dimension( e ); } final Img< T > img = imgFactory.create( dim, Views.iterable( input ).firstElement() ); simple2x( src, img, d ); src = img; } return src; }
Example #7
Source File: SlideBook6.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
protected ImgFactory<? extends NativeType<?>> selectImgFactory(final SlideBook6MetaData meta) { int[] dims = meta.imageSize(0); long maxNumPixels = dims[0]; maxNumPixels *= dims[1]; maxNumPixels *= dims[2]; String s = "Maximum number of pixels in any view: n=" + Long.toString(maxNumPixels) + " px "; if (maxNumPixels < Integer.MAX_VALUE) { IOFunctions.println(s + "< " + Integer.MAX_VALUE + ", using ArrayImg."); return new ArrayImgFactory<FloatType>(); } else { IOFunctions.println(s + ">= " + Integer.MAX_VALUE + ", using CellImg."); return new CellImgFactory<FloatType>(256); } }
Example #8
Source File: TestImageAccessor.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * This method creates a noise image that has a specified mean. * Every pixel has a value uniformly distributed around mean with * the maximum spread specified. * * @return a new noise image * @throws MissingPreconditionException if specified means and spreads are not valid */ public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> produceMeanBasedNoiseImage(T type, int width, int height, double mean, double spread, double[] smoothingSigma, long seed) throws MissingPreconditionException { if (mean < spread || (mean + spread) > type.getMaxValue()) { throw new MissingPreconditionException("Mean must be larger than spread, and mean plus spread must be smaller than max of the type"); } // create the new image ImgFactory<T> imgFactory = new ArrayImgFactory<T>(); RandomAccessibleInterval<T> noiseImage = imgFactory.create( new int[] {width, height}, type); // "Noise image"); Random r = new Random(seed); for (T value : Views.iterable(noiseImage)) { value.setReal( mean + ( (r.nextDouble() - 0.5) * spread ) ); } return gaussianSmooth(noiseImage, smoothingSigma); }
Example #9
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see ImgOpener#openImgs(Reader, ImgFactory, SCIFIOConfig) */ public static <T extends RealType<T>> List<SCIFIOImgPlus<T>> openAll( final Reader reader, final ImgFactory<T> imgFactory, final SCIFIOConfig config) { final ImgOpener opener = opener(); List<SCIFIOImgPlus<T>> imgPlus = null; try { imgPlus = opener.openImgs(reader, imgFactory, config); register(imgPlus, opener); } catch (final ImgIOException e) { openError(reader.getMetadata().getSourceLocation(), e); } return imgPlus; }
Example #10
Source File: TestImageAccessor.java From Colocalisation_Analysis with GNU General Public License v3.0 | 6 votes |
/** * Gaussian Smooth of the input image using intermediate float format. * @param <T> * @param img * @param sigma * @return */ public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> gaussianSmooth( RandomAccessibleInterval<T> img, double[] sigma) { Interval interval = Views.iterable(img); ImgFactory<T> outputFactory = new ArrayImgFactory<T>(Util.getTypeFromInterval(img)); final long[] dim = new long[ img.numDimensions() ]; img.dimensions(dim); RandomAccessibleInterval<T> output = outputFactory.create( dim ); final long[] pos = new long[ img.numDimensions() ]; Arrays.fill(pos, 0); Localizable origin = new Point(pos); ImgFactory<FloatType> tempFactory = new ArrayImgFactory<FloatType>(new FloatType()); RandomAccessible<T> input = Views.extendMirrorSingle(img); Gauss.inFloat(sigma, input, interval, output, origin, tempFactory); return output; }
Example #11
Source File: PhaseCorrelation2.java From BigStitcher with GNU General Public License v2.0 | 6 votes |
public static <T extends RealType<T>, S extends RealType<S>, R extends RealType<R>, C extends ComplexType<C>> RandomAccessibleInterval<R> calculatePCM( RandomAccessibleInterval<T> img1, RandomAccessibleInterval<S> img2, int[] extension, ImgFactory<R> factory, R type, ImgFactory<C> fftFactory, C fftType, ExecutorService service){ // TODO: Extension absolute per dimension in pixels, i.e. int[] extension // TODO: not bigger than the image dimension because the second mirroring is identical to the image Dimensions extSize = PhaseCorrelation2Util.getExtendedSize(img1, img2, extension); long[] paddedDimensions = new long[extSize.numDimensions()]; long[] fftSize = new long[extSize.numDimensions()]; FFTMethods.dimensionsRealToComplexFast(extSize, paddedDimensions, fftSize); RandomAccessibleInterval<C> fft1 = fftFactory.create(fftSize, fftType); RandomAccessibleInterval<C> fft2 = fftFactory.create(fftSize, fftType); FFT.realToComplex(Views.interval(PhaseCorrelation2Util.extendImageByFactor(img1, extension), FFTMethods.paddingIntervalCentered(img1, new FinalInterval(paddedDimensions))), fft1, service); FFT.realToComplex(Views.interval(PhaseCorrelation2Util.extendImageByFactor(img2, extension), FFTMethods.paddingIntervalCentered(img2, new FinalInterval(paddedDimensions))), fft2, service); RandomAccessibleInterval<R> pcm = calculatePCMInPlace(fft1, fft2, factory, type, service); return pcm; }
Example #12
Source File: LegacyStackImgLoader.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
/** * For a local initialization without the XML * * @param path * @param fileNamePattern * @param imgFactory * @param layoutTP - 0 == one, 1 == one per file, 2 == all in one file * @param layoutChannels - 0 == one, 1 == one per file, 2 == all in one file * @param layoutIllum - 0 == one, 1 == one per file, 2 == all in one file * @param layoutAngles - 0 == one, 1 == one per file, 2 == all in one file */ public LegacyStackImgLoader( final File path, final String fileNamePattern, final ImgFactory< ? extends NativeType< ? > > imgFactory, final int layoutTP, final int layoutChannels, final int layoutIllum, final int layoutAngles, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription ) { super(); this.path = path; this.fileNamePattern = fileNamePattern; this.layoutTP = layoutTP; this.layoutChannels = layoutChannels; this.layoutIllum = layoutIllum; this.layoutAngles = layoutAngles; this.sequenceDescription = sequenceDescription; this.init( imgFactory ); }
Example #13
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @deprecated Use {@link #open(Location, ImgFactory)}. */ @Deprecated public static <T extends RealType<T> & NativeType<T>> SCIFIOImgPlus<T> open( final Location source, final ImgFactory<T> imgFactory, @SuppressWarnings("unused") final T type) { return open(opener(), source, imgFactory); }
Example #14
Source File: Downsample.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public static < T extends RealType< T > > RandomAccessibleInterval< T > simple2x( final RandomAccessibleInterval<T> input, final ImgFactory< T > imgFactory ) { final boolean[] downsampleInDim = new boolean[ input.numDimensions() ]; for ( int d = 0; d < downsampleInDim.length; ++d ) downsampleInDim[ d ] = true; return simple2x( input, imgFactory, downsampleInDim ); }
Example #15
Source File: TestImageAccessor.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * Generates a Perlin noise image. It is based on Ken Perlin's * reference implementation (ImprovedNoise class) and a small * bit of Kas Thomas' sample code (http://asserttrue.blogspot.com/). */ public static <T extends RealType<T> & NativeType<T>> RandomAccessibleInterval<T> producePerlinNoiseImage(T type, int width, int height, double z, double scale) { // create the new image ImgFactory<T> imgFactory = new ArrayImgFactory<T>(); RandomAccessibleInterval<T> noiseImage = imgFactory.create( new int[] {width, height}, type); Cursor<T> noiseCursor = Views.iterable(noiseImage).localizingCursor(); double xOffset = Math.random() * (width*width); double yOffset = Math.random() * (height*height); while (noiseCursor.hasNext()) { noiseCursor.fwd(); double x = (noiseCursor.getDoublePosition(0) + xOffset) * scale; double y = (noiseCursor.getDoublePosition(1) + yOffset) * scale; float t = (float)ImprovedNoise.noise( x, y, z); // ImprovedNoise.noise returns a float in the range [-1..1], // whereas we want a float in the range [0..1], so: t = (1 + t) * 0.5f; noiseCursor.get().setReal(t); } //return gaussianSmooth(noiseImage, imgFactory, smoothingSigma); return noiseImage; }
Example #16
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see ImgOpener#openImgs(Reader, ImgFactory, SCIFIOConfig) */ public static <T extends RealType<T>> SCIFIOImgPlus<T> open( final Reader reader, final T type, final ImgFactory<T> imgFactory, final SCIFIOConfig config) { return first(openAll(reader, type, imgFactory, config)); }
Example #17
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see ImgOpener#openImgs(Location, ImgFactory, SCIFIOConfig) */ public static <T extends RealType<T> & NativeType<T>> List<SCIFIOImgPlus<T>> openAll(final Location source, final ImgFactory<T> imgFactory, final SCIFIOConfig config) { return openAll(opener(), source, imgFactory, config); }
Example #18
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** @deprecated Use {@link #openImgs(String, ImgFactory)}. */ @Deprecated public <T extends RealType<T> & NativeType<T>> List<SCIFIOImgPlus<T>> openImgs(final String source, final ImgFactory<T> imgFactory, @SuppressWarnings("unused") T type) throws ImgIOException { return openImgs(source, imgFactory); }
Example #19
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** @deprecated Use {@link #openImgs(String, ImgFactory)}. */ @Deprecated public <T extends RealType<T> & NativeType<T>> SCIFIOImgPlus<T> openImg( final String source, final ImgFactory<T> imgFactory) throws ImgIOException { return first(openImgs(source, imgFactory)); }
Example #20
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** @deprecated Use {@link #openImgs(String, ImgFactory, SCIFIOConfig)}. */ @Deprecated public <T extends RealType<T> & NativeType<T>> SCIFIOImgPlus<T> openImg( final String source, final ImgFactory<T> imgFactory, final SCIFIOConfig config) throws ImgIOException { return first(openImgs(source, imgFactory, config)); }
Example #21
Source File: Coloc_2.java From Colocalisation_Analysis with GNU General Public License v3.0 | 5 votes |
/** * This method duplicates the given images, but respects ROIs if present. * Meaning, a sub-picture will be created when source images are * ROI/MaskImages. * * @throws MissingPreconditionException */ protected RandomAccessibleInterval<T> createMaskImage( final RandomAccessibleInterval<T> image, final RandomAccessibleInterval<BitType> mask, final long[] offset, final long[] size) throws MissingPreconditionException { final long[] pos = new long[image.numDimensions()]; // sanity check if (pos.length != offset.length || pos.length != size.length) { throw new MissingPreconditionException( "Mask offset and size must be of same dimensionality like image."); } // use twin cursor for only one image final TwinCursor<T> cursor = new TwinCursor<>(image.randomAccess(), // image.randomAccess(), Views.iterable(mask).localizingCursor()); // prepare output image final ImgFactory<T> maskFactory = new ArrayImgFactory<>(); // Img<T> maskImage = maskFactory.create( size, name ); final RandomAccessibleInterval<T> maskImage = maskFactory.create(size, // image.randomAccess().get().createVariable()); final RandomAccess<T> maskCursor = maskImage.randomAccess(); // go through the visible data and copy it to the output while (cursor.hasNext()) { cursor.fwd(); cursor.localize(pos); // shift coordinates by offset for (int i = 0; i < pos.length; ++i) { pos[i] = pos[i] - offset[i]; } // write out to correct position maskCursor.setPosition(pos); maskCursor.get().set(cursor.getFirst()); } return maskImage; }
Example #22
Source File: StackImgLoaderLOCI.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public StackImgLoaderLOCI( final File path, final String fileNamePattern, final ImgFactory< ? extends NativeType< ? > > imgFactory, final int layoutTP, final int layoutChannels, final int layoutIllum, final int layoutAngles, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription ) { super( new LegacyStackImgLoaderLOCI( path, fileNamePattern, imgFactory, layoutTP, layoutChannels, layoutIllum, layoutAngles, sequenceDescription ) ); }
Example #23
Source File: SCIFIOCellImgFactory.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public <S> ImgFactory<S> imgFactory(final S type) throws IncompatibleTypeException { if (NativeType.class.isInstance(type)) return new SCIFIOCellImgFactory( (NativeType) type, factoryOptions); throw new IncompatibleTypeException(this, type.getClass() .getCanonicalName() + " does not implement NativeType."); }
Example #24
Source File: BoundingBoxGUI.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public < T extends ComplexType< T > & NativeType < T > > ImgFactory< T > getImgFactory( final T type ) { final ImgFactory< T > imgFactory; if ( this.getImgType() == 0 ) imgFactory = new ArrayImgFactory< T >(); else if ( this.getImgType() == 1 ) imgFactory = new ImagePlusImgFactory< T >(); else imgFactory = new CellImgFactory<T>( 256 ); return imgFactory; }
Example #25
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @deprecated Use {@link #open(String, ImgFactory)}. */ @Deprecated public static <T extends RealType<T> & NativeType<T>> SCIFIOImgPlus<T> openImg(final String source, final ImgFactory<T> imgFactory) { return open(source, imgFactory); }
Example #26
Source File: StackImgLoaderIJ.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public StackImgLoaderIJ( final File path, final String fileNamePattern, final ImgFactory< ? extends NativeType< ? > > imgFactory, final int layoutTP, final int layoutChannels, final int layoutIllum, final int layoutAngles, final AbstractSequenceDescription< ?, ?, ? > sequenceDescription ) { super( new LegacyStackImgLoaderIJ( path, fileNamePattern, imgFactory, layoutTP, layoutChannels, layoutIllum, layoutAngles, sequenceDescription ) ); }
Example #27
Source File: SlideBook6ImgLoader.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public SlideBook6ImgLoader( final File sldFile, final ImgFactory< ? extends NativeType< ? > > imgFactory, final AbstractSequenceDescription< ? , ?, ? > sequenceDescription ) { super( new LegacySlideBook6ImgLoader( sldFile, imgFactory, sequenceDescription ) ); }
Example #28
Source File: LegacyLightSheetZ1ImgLoader.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public LegacyLightSheetZ1ImgLoader( final File cziFile, final ImgFactory< ? extends NativeType< ? > > imgFactory, final AbstractSequenceDescription<?, ?, ?> sequenceDescription ) { super(); this.cziFile = cziFile; this.sequenceDescription = sequenceDescription; setImgFactory( imgFactory ); }
Example #29
Source File: IO.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
/** * @deprecated Use {@link #open(String, ImgFactory)}. */ @Deprecated public static <T extends RealType<T> & NativeType<T>> SCIFIOImgPlus<T> open( final String source, final ImgFactory<T> imgFactory, @SuppressWarnings("unused") final T type) { final ImgOpener opener = new ImgOpener(); return open(opener, resolve(source, opener.context()), imgFactory); }
Example #30
Source File: LightSheetZ1ImgLoader.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
public LightSheetZ1ImgLoader( final File cziFile, final ImgFactory< ? extends NativeType< ? > > imgFactory, final AbstractSequenceDescription<?, ?, ?> sequenceDescription ) { super( new LegacyLightSheetZ1ImgLoader( cziFile, imgFactory, sequenceDescription ) ); }