net.imglib2.exception.IncompatibleTypeException Java Examples
The following examples show how to use
net.imglib2.exception.IncompatibleTypeException.
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: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see LocalSauvolaThresholdIntegral * @see LocalSauvolaThreshold */ @Test public void testLocalSauvolaResultsConsistency() { Img<BitType> out2 = null; Img<BitType> out3 = null; try { out2 = in.factory().imgFactory(new BitType()).create(in, new BitType()); out3 = in.factory().imgFactory(new BitType()).create(in, new BitType()); } catch (IncompatibleTypeException exc) { exc.printStackTrace(); } // Default implementation ops.run(LocalSauvolaThreshold.class, out2, normalizedIn, new RectangleShape( 2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>( Boundary.SINGLE), 0.5, 0.5); // Integral image-based implementation ops.run(LocalSauvolaThresholdIntegral.class, out3, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.5, 0.5); testIterableIntervalSimilarity(out2, out3); }
Example #2
Source File: ImgOpener.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Reads in images using the given {@link Reader}. * * @param reader An initialized {@link Reader} to use for reading image data. * Must be wrapped by a {@link PlaneSeparator} filter. * @param type The {@link Type} T of the output {@link ImgPlus}es. * @param config {@link SCIFIOConfig} to use when opening the images * @return the images which were read * @throws ImgIOException if there is a problem reading the image data. */ public <T> List<SCIFIOImgPlus<T>> openImgs(final Reader reader, final T type, SCIFIOConfig config) throws ImgIOException { if (config == null) { config = new SCIFIOConfig().imgOpenerSetComputeMinMax(true); } final ImgFactoryHeuristic heuristic = getHeuristic(config); final ImgFactory<T> imgFactory; try { imgFactory = heuristic.createFactory(reader.getMetadata(), // config.imgOpenerGetImgModes(), type); } catch (final IncompatibleTypeException e) { throw new ImgIOException(e); } return openImgs(reader, imgFactory, config); }
Example #3
Source File: DefaultDatasetIOService.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public Metadata save(final Dataset dataset, final Location destination, final SCIFIOConfig config) throws IOException { @SuppressWarnings("rawtypes") final ImgPlus img = dataset.getImgPlus(); final Metadata metadata; final ImgSaver imageSaver = new ImgSaver(getContext()); try { metadata = imageSaver.saveImg(destination, img, config); } catch (ImgIOException | IncompatibleTypeException exc) { throw new IOException(exc); } final String name = destination.getName(); dataset.setName(name); dataset.setDirty(false); return metadata; }
Example #4
Source File: ImgSaver.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Entry {@link #writeImg} method. Gathers necessary metadata, creates default * configuration options if needed, and delegates to the appropriate * intermediate {@link #writeImg} method if able. */ private Metadata writeImg(final Location id, final Writer w, final SCIFIOImgPlus<?> img, final int imageIndex, SCIFIOConfig config) throws ImgIOException, IncompatibleTypeException { // Create the SCIFIOConfig if needed if (config == null) { config = new SCIFIOConfig(); } final int sliceCount = countSlices(img); if (w == null) { if (id == null) { throw new ImgIOException( "No output destination or pre-configured Writer was provided, and" + " no way to determine the desired output path. Default value:" + " ImgPlus's source."); } return writeImg(id, img, imageIndex, config, sliceCount); } return writeImg(w, id, img, imageIndex, config, sliceCount); }
Example #5
Source File: ImgSaver.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Intermediate {@link #writeImg} method. Creates a {@link Writer} for the * given id, based on the file extension. */ private Metadata writeImg(final Location id, final SCIFIOImgPlus<?> imgPlus, final int imageIndex, final SCIFIOConfig config, final int sliceCount) throws ImgIOException, IncompatibleTypeException { // Create a Writer for the given id Writer w = null; try { w = formatService.getWriterForLocation(id); } catch (final FormatException e) { throw new ImgIOException(e); } return writeImg(w, id, imgPlus, imageIndex, config, sliceCount); }
Example #6
Source File: DifferenceOf.java From SPIM_Registration with GNU General Public License v2.0 | 6 votes |
protected < T extends RealType< T > > void preSmooth( final RandomAccessibleInterval< T > img ) { if ( additionalSigmaX > 0.0 || additionalSigmaY > 0.0 || additionalSigmaZ > 0.0 ) { IOFunctions.println( "presmoothing image with sigma=[" + additionalSigmaX + "," + additionalSigmaY + "," + additionalSigmaZ + "]" ); try { Gauss3.gauss( new double[]{ additionalSigmaX, additionalSigmaY, additionalSigmaZ }, Views.extendMirrorSingle( img ), img ); } catch (IncompatibleTypeException e) { IOFunctions.println( "presmoothing failed: " + e ); e.printStackTrace(); } } }
Example #7
Source File: ImgSaver.java From scifio with BSD 2-Clause "Simplified" License | 6 votes |
/** * Terminal {@link #writeImg} method. Performs actual pixel output. */ private Metadata writeImg(final Writer w, final SCIFIOImgPlus<?> imgPlus, final int imageIndex, final int sliceCount) throws ImgIOException, IncompatibleTypeException { if (imgPlus.numDimensions() > 0) { final long startTime = System.currentTimeMillis(); // write pixels writePlanes(w, imageIndex, imgPlus); // Print time statistics final long endTime = System.currentTimeMillis(); final float time = (endTime - startTime) / 1000f; statusService.showStatus(sliceCount, sliceCount, w.getMetadata() .getDatasetName() + ": wrote " + sliceCount + " planes in " + time + " s"); } return w.getMetadata(); }
Example #8
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see LocalNiblackThresholdIntegral * @see LocalNiblackThreshold */ @Test public void testLocalNiblackResultsConsistency() { Img<BitType> out2 = null; Img<BitType> out3 = null; try { out2 = in.factory().imgFactory(new BitType()).create(in, new BitType()); out3 = in.factory().imgFactory(new BitType()).create(in, new BitType()); } catch (IncompatibleTypeException exc) { exc.printStackTrace(); } // Default implementation ops.run(LocalNiblackThreshold.class, out2, normalizedIn, new RectangleShape( 2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>( Boundary.SINGLE), 0.2, 1.0); // Integral image-based implementation ops.run(LocalNiblackThresholdIntegral.class, out3, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.2, 1.0); testIterableIntervalSimilarity(out2, out3); }
Example #9
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
/** * @see LocalMeanThresholdIntegral * @see LocalMeanThreshold */ @Test public void testLocalMeanResultsConsistency() { Img<BitType> out2 = null; Img<BitType> out3 = null; try { out2 = in.factory().imgFactory(new BitType()).create(in, new BitType()); out3 = in.factory().imgFactory(new BitType()).create(in, new BitType()); } catch (IncompatibleTypeException exc) { exc.printStackTrace(); } // Default implementation ops.run(LocalMeanThreshold.class, out2, in, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.0); // Integral image-based implementation ops.run(LocalMeanThresholdIntegral.class, out3, in, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>( Boundary.SINGLE), 0.0); testIterableIntervalSimilarity(out2, out3); }
Example #10
Source File: DefaultGaussRAI.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final RandomAccessibleInterval<T> input, final RandomAccessibleInterval<T> output) { if (outOfBounds == null) { outOfBounds = new OutOfBoundsMirrorFactory<>(Boundary.SINGLE); } final RandomAccessible<FloatType> eIn = // (RandomAccessible) Views.extend(input, outOfBounds); try { SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), eIn, output, threads.getExecutorService()); } catch (final IncompatibleTypeException e) { throw new RuntimeException(e); } }
Example #11
Source File: SourceInfoSerializer.java From paintera with GNU General Public License v2.0 | 6 votes |
public static void populate( final Consumer<SourceState<?, ?>> addState, final IntConsumer currentSourceIndex, final JsonObject serializedSourceInfo, final BiConsumer<Integer, SourceState<?, ?>> logSourceForDependencies, final Gson gson) throws IncompatibleTypeException, ClassNotFoundException, JsonParseException, UndefinedDependency, HasCyclicDependencies, IOException { final SourceState<?, ?>[] states = makeStates( serializedSourceInfo.get(SOURCES_KEY).getAsJsonArray(), logSourceForDependencies, gson ); Arrays .stream(states) .forEach(addState::accept); currentSourceIndex.accept(serializedSourceInfo.get(CURRENT_SOURCE_INDEX_KEY).getAsInt()); }
Example #12
Source File: ImgImgFactory.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public Img<V> createOutput(final Img<T> input) { try { return input.factory().imgFactory(resType).create(input, resType); } catch (final IncompatibleTypeException e) { throw new IllegalArgumentException(e); } }
Example #13
Source File: LocalThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** * @see LocalPhansalkarThresholdIntegral * @see LocalPhansalkarThreshold */ @Test public void testLocalPhansalkarResultsConsistency() { Img<BitType> out2 = null; Img<BitType> out3 = null; try { out2 = in.factory().imgFactory(new BitType()).create(in, new BitType()); out3 = in.factory().imgFactory(new BitType()).create(in, new BitType()); } catch (IncompatibleTypeException exc) { exc.printStackTrace(); } // Default implementation ops.run(LocalPhansalkarThreshold.class, out2, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.25, 0.5); // Integral image-based implementation ops.run(LocalPhansalkarThresholdIntegral.class, out3, normalizedIn, new RectangleShape(2, false), new OutOfBoundsMirrorFactory<ByteType, Img<ByteType>>(Boundary.SINGLE), 0.25, 0.5); testIterableIntervalSimilarity(out2, out3); }
Example #14
Source File: ApplyManualThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Test public void testApplyThreshold() throws IncompatibleTypeException { final Img<BitType> out = bitmap(); final UnsignedShortType threshold = new UnsignedShortType(30000); ops.run(ApplyManualThreshold.class, out, in, threshold); assertCount(out, 54); }
Example #15
Source File: DefaultGaussRA.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
@Override public void compute(final RandomAccessible<T> input, final RandomAccessibleInterval<T> output) { try { SeparableSymmetricConvolution.convolve(Gauss3.halfkernels(sigmas), input, output, threads.getExecutorService()); } catch (final IncompatibleTypeException e) { throw new RuntimeException(e); } }
Example #16
Source File: GaussTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
/** Tests the Gaussian. */ @Test public void gaussRegressionTest() { final Img<ByteType> in = generateByteArrayTestImg(true, new long[] { 10, 10 }); final Img<ByteType> out1 = ops.create().img(in, Util.getTypeFromInterval(in)); final double sigma = 5; final Img<ByteType> out2 = ops.create().img(in, Util.getTypeFromInterval(in)); ops.run(GaussRAISingleSigma.class, out1, in, sigma); try { Gauss3.gauss(sigma, Views.extendMirrorSingle(in), out2); } catch (IncompatibleTypeException e) { throw new RuntimeException(e); } // compare outputs final Cursor<ByteType> c1 = out1.cursor(); final Cursor<ByteType> c2 = out2.cursor(); while (c1.hasNext()) { org.junit.Assert.assertEquals(c1.next().getRealDouble(), c2.next() .getRealDouble(), 0); } }
Example #17
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 #18
Source File: MVDeconInput.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
/** * init all views * * @return the same instance again for convenience * @throws IncompatibleTypeException */ public MVDeconInput init( final PSFTYPE iterationType ) throws IncompatibleTypeException { for ( final MVDeconFFT view : views ) view.init( iterationType, views ); return this; }
Example #19
Source File: ContentBased.java From SPIM_Registration with GNU General Public License v2.0 | 5 votes |
protected Img< FloatType > approximateEntropy( final RandomAccessibleInterval< FloatType > input, final ImgFactory< ComplexFloatType > imgFactory, final double[] sigma1, final double[] sigma2 ) { // the result ImgFactory<FloatType> f; try { f = imgFactory.imgFactory( new FloatType() ); } catch (IncompatibleTypeException e) { f = new ArrayImgFactory< FloatType >(); } final Img< FloatType > conv = f.create( input, new FloatType() ); // compute I*sigma1 FFTConvolution< FloatType > fftConv = new FFTConvolution<FloatType>( input, createGaussianKernel( sigma1 ), conv, imgFactory ); fftConv.convolve(); // compute ( I - I*sigma1 )^2 final Cursor< FloatType > c = conv.cursor(); final RandomAccess< FloatType > r = input.randomAccess(); while ( c.hasNext() ) { c.fwd(); r.setPosition( c ); final float diff = c.get().get() - r.get().get(); c.get().set( diff * diff ); } // compute ( ( I - I*sigma1 )^2 ) * sigma2 fftConv = new FFTConvolution<FloatType>( conv, createGaussianKernel( sigma2 ), imgFactory ); fftConv.convolve(); // normalize to [0...1] FusionHelper.normalizeImage( conv ); return conv; }
Example #20
Source File: DefaultImgFactoryHeuristic.java From scifio with BSD 2-Clause "Simplified" License | 5 votes |
@Override public <T> ImgFactory<T> createFactory(final Metadata m, final ImgMode[] imgModes, final T type) throws IncompatibleTypeException { if (!(type instanceof NativeType)) return new ListImgFactory<>(type); @SuppressWarnings({ "cast", "rawtypes", "unchecked" }) final ImgFactory<T> result = // (ImgFactory<T>) createNativeFactory(m, imgModes, (NativeType) type); return result; }
Example #21
Source File: PhaseCorrelation2.java From BigStitcher with GNU General Public License v2.0 | 5 votes |
public static <T extends ComplexType<T> & NativeType<T>, S extends ComplexType<S> & NativeType <S>, R extends RealType<R>> RandomAccessibleInterval<R> calculatePCM( RandomAccessibleInterval<T> fft1, RandomAccessibleInterval<S> fft2, ImgFactory<R> factory, R type, ExecutorService service){ long[] paddedDimensions = new long[fft1.numDimensions()]; long[] realSize = new long[fft1.numDimensions()]; FFTMethods.dimensionsComplexToRealFast(fft1, paddedDimensions, realSize); RandomAccessibleInterval<R> res = factory.create(realSize, type); final T typeT = Views.iterable(fft1).firstElement().createVariable(); final S typeS = Views.iterable(fft2).firstElement().createVariable(); RandomAccessibleInterval< T > fft1Copy; RandomAccessibleInterval< S > fft2Copy; try { fft1Copy = factory.imgFactory( typeT ).create(fft1, typeT ); fft2Copy = factory.imgFactory( typeS ).create(fft2, typeS ); } catch ( IncompatibleTypeException e ) { throw new RuntimeException( "Cannot instantiate Img for type " + typeS.getClass().getSimpleName() + " or " + typeT.getClass().getSimpleName() ); } calculatePCM(fft1, fft1Copy, fft2, fft2Copy, res, service); return res; }
Example #22
Source File: DefaultImgFactoryHeuristic.java From scifio with BSD 2-Clause "Simplified" License | 4 votes |
private <T extends NativeType<T>> ImgFactory<T> createNativeFactory( final Metadata m, final ImgMode[] imgModes, final T type) throws IncompatibleTypeException { // Max size of a plane of a PlanarImg, or total dataset for ArrayImg. // 2GB. final long maxSize = ArrayUtils.safeMultiply64(2, 1024, 1024, 1024); final long availableMem = // (long) (MemoryTools.totalAvailableMemory() * MEMORY_THRESHOLD); long datasetSize = m.getDatasetSize(); // check for overflow if (datasetSize <= 0) datasetSize = Long.MAX_VALUE; // divide by 1024 to compare to max_size and avoid overflow final long planeSize = m.get(0).getAxisLength(Axes.X) * // m.get(0).getAxisLength(Axes.Y) * // FormatTools.getBytesPerPixel(m.get(0).getPixelType()); final boolean fitsInMemory = availableMem > datasetSize; // loop over ImgOptions in preferred order final List<ImgMode> modes = new ArrayList<>(Arrays.asList(imgModes)); modes.add(ImgMode.AUTO); for (final ImgMode mode : modes) { switch (mode) { case AUTO: if (!fitsInMemory) return new SCIFIOCellImgFactory<>(type); if (datasetSize < maxSize) return new ArrayImgFactory<>(type); // FIXME: No CellImgFactory right now. // Isn't guaranteed to handle all images well (e.g. RGB). //if (planeSize < maxSize) return new PlanarImgFactory<>(type); //return new CellImgFactory<>(type); return new PlanarImgFactory<>(type); case ARRAY: if (datasetSize < maxSize && fitsInMemory) return new ArrayImgFactory<>(type); break; case PLANAR: if (planeSize < maxSize && fitsInMemory) return new PlanarImgFactory<>(type); break; case CELL: // FIXME: No CellImgFactory right now. // Isn't guaranteed to handle all images well (e.g. RGB). //if (fitsInMemory) return new CellImgFactory<>(type); //return new SCIFIOCellImgFactory<>(type); return new SCIFIOCellImgFactory<>(type); } } // No compatible modes. throw new IncompatibleTypeException(this, "Cannot create ImgFactory of type " + type.getClass().getName()); }
Example #23
Source File: SourceInfoSerializer.java From paintera with GNU General Public License v2.0 | 4 votes |
public static SourceState<?, ?>[] makeStates( final JsonArray serializedStates, final BiConsumer<Integer, SourceState<?, ?>> logSourceForDependencies, final Gson gson) throws ClassNotFoundException, UndefinedDependency, HasCyclicDependencies, IncompatibleTypeException, JsonParseException, IOException { final int numStates = serializedStates.size(); final TIntHashSet[] dependsOn = new TIntHashSet[numStates]; LOG.debug("Deserializing {}", serializedStates); for (int i = 0; i < numStates; ++i) { final JsonObject map = serializedStates.get(i).getAsJsonObject().get(STATE_KEY).getAsJsonObject(); LOG.debug("Deserializing state {}: {}", i, map); final int[] depends = Optional .ofNullable(serializedStates.get(i).getAsJsonObject().get(DEPENDS_ON_KEY)) .map(el -> gson.fromJson(el, int[].class)) .orElseGet(() -> new int[] {}); if (Arrays.stream(depends).filter(d -> d < 0 || d >= numStates).count() > 0) { throw new UndefinedDependency(depends, numStates); } dependsOn[i] = new TIntHashSet(depends); } if (hasCycles(dependsOn)) { throw new HasCyclicDependencies(dependsOn); } final SourceState<?, ?>[] sourceStates = new SourceState[numStates]; for (int i = 0; i < numStates && Arrays.stream(sourceStates).filter(s -> s == null).count() > 0; ++i) { for (int k = 0; k < numStates; ++k) { if (sourceStates[k] == null) { final SourceState<?, ?>[] dependencies = IntStream .of(dependsOn[k].toArray()) .mapToObj(m -> sourceStates[m]) .toArray(SourceState[]::new); if (Stream.of(dependencies).noneMatch(Objects::isNull)) { final JsonObject state = serializedStates.get(k).getAsJsonObject(); @SuppressWarnings("unchecked") final Class<? extends SourceState<?, ?>> clazz = (Class<? extends SourceState<?, ?>>) Class.forName(state.get(STATE_TYPE_KEY).getAsString()); LOG.debug("Deserializing state={}, class={}", state, clazz); if (LabelSourceState.class.equals(clazz)) { LOG.debug("Trying to de-serialize deprecated LabelSourceState into ConnectomicsLabelState"); sourceStates[k] = gson.fromJson(state.get(STATE_KEY), (Type) clazz); } else if (RawSourceState.class.equals(clazz)) { LOG.debug("Trying to de-serialize deprecated RawSourceState into ConnectomicsRawState"); sourceStates[k] = gson.fromJson(state.get(STATE_KEY), (Type) clazz); } else if (ChannelSourceState.class.equals(clazz)) { LOG.debug("Trying to de-serialize deprecated ChannelSourceState into ConnectomicsChannelState"); sourceStates[k] = gson.fromJson(state.get(STATE_KEY), (Type) clazz); } else sourceStates[k] = gson.fromJson(state.get(STATE_KEY), clazz); logSourceForDependencies.accept(k, sourceStates[k]); } } } } if (Arrays.stream(sourceStates).anyMatch(Objects::isNull)) { throw new RuntimeException("Unable to deserialize all source states"); } return sourceStates; }
Example #24
Source File: Convolve.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@SuppressWarnings({ "unchecked", "rawtypes" }) @Override public void run() { // TODO: get the dimension indices from the image dependent on the // selected // axes -> OR: just map the kernel dimension labels to the image // dimension // labels final int[] axisIndices = new int[] { 0, 1 }; // number of indicies must be conform with the dimensionality of axes if (axes.length != axisIndices.length) { throw new IllegalArgumentException( "The number of selected dimension doesn't conforms with the kernel size."); } if (asFloat) { try { out = (ImgPlus) in.factory().imgFactory(new FloatType()) .create(in, new FloatType()); } catch (final IncompatibleTypeException e) { throw new IllegalArgumentException(e); } } else { out = (ImgPlus<O>) in.factory().create(in, in.firstElement().createVariable()); } final Op op = ops.op(Ops.Filter.Convolve.class, out, in, kernel); if (in.numDimensions() > kernel.numDimensions()) { if (op instanceof UnaryComputerOp) { // if the selected convolve op is a function and the kernel dimensions // doesn't match the input image dimensions, than we can still convolve // each slice individually ops.run(Ops.Slice.class, out, in, op, axisIndices); } else { throw new IllegalArgumentException( "The input image has more dimensions than the kernel!"); } } else if (in.numDimensions() == kernel.numDimensions()) { // no 'slicing' necessary ops.run(op, out, in, kernel); } }
Example #25
Source File: DefaultTubeness.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void compute(final RandomAccessibleInterval<T> input, final IterableInterval<DoubleType> tubeness) { cancelReason = null; final int numDimensions = input.numDimensions(); // Sigmas in pixel units. final double[] sigmas = new double[numDimensions]; for (int d = 0; d < sigmas.length; d++) { final double cal = d < calibration.length ? calibration[d] : 1; sigmas[d] = sigma / cal; } /* * Hessian. */ // Get a suitable image factory. final long[] gradientDims = new long[numDimensions + 1]; final long[] hessianDims = new long[numDimensions + 1]; for (int d = 0; d < numDimensions; d++) { hessianDims[d] = input.dimension(d); gradientDims[d] = input.dimension(d); } hessianDims[numDimensions] = numDimensions * (numDimensions + 1) / 2; gradientDims[numDimensions] = numDimensions; final Dimensions hessianDimensions = FinalDimensions.wrap(hessianDims); final FinalDimensions gradientDimensions = FinalDimensions.wrap( gradientDims); final ImgFactory<DoubleType> factory = ops().create().imgFactory( hessianDimensions); final Img<DoubleType> hessian = factory.create(hessianDimensions, new DoubleType()); final Img<DoubleType> gradient = factory.create(gradientDimensions, new DoubleType()); final Img<DoubleType> gaussian = factory.create(input, new DoubleType()); // Handle multithreading. final int nThreads = Runtime.getRuntime().availableProcessors(); final ExecutorService es = threadService.getExecutorService(); try { // Hessian calculation. HessianMatrix.calculateMatrix(Views.extendBorder(input), gaussian, gradient, hessian, new OutOfBoundsBorderFactory<>(), nThreads, es, sigma); statusService.showProgress(1, 3); if (isCanceled()) return; // Hessian eigenvalues. final RandomAccessibleInterval<DoubleType> evs = TensorEigenValues .calculateEigenValuesSymmetric(hessian, TensorEigenValues .createAppropriateResultImg(hessian, factory, new DoubleType()), nThreads, es); statusService.showProgress(2, 3); if (isCanceled()) return; final AbstractUnaryComputerOp<Iterable<DoubleType>, DoubleType> method; switch (numDimensions) { case 2: method = new Tubeness2D(sigma); break; case 3: method = new Tubeness3D(sigma); break; default: System.err.println("Cannot compute tubeness for " + numDimensions + "D images."); return; } ops().transform().project(tubeness, evs, method, numDimensions); statusService.showProgress(3, 3); return; } catch (final IncompatibleTypeException | InterruptedException | ExecutionException e) { e.printStackTrace(); return; } }
Example #26
Source File: AbstractThresholdTest.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
protected Img<BitType> bitmap() throws IncompatibleTypeException { return in.factory().imgFactory(new BitType()).create(in, new BitType()); }
Example #27
Source File: MVDeconFFT.java From SPIM_Registration with GNU General Public License v2.0 | 4 votes |
public void setKernel( final ArrayImg< FloatType, ? > kernel ) throws IncompatibleTypeException { this.kernel1 = kernel; init( iterationType, views ); setCurrentIteration( -1 ); }
Example #28
Source File: ImgSaver.java From scifio with BSD 2-Clause "Simplified" License | 3 votes |
/** * As {@link #saveImg(Location, SCIFIOImgPlus, int)} with configuration * options. * * @param destination * @param img * @param config Configuration information to use for this write. * @throws ImgIOException * @throws IncompatibleTypeException */ public Metadata saveImg(final String destination, final SCIFIOImgPlus<?> img, final int imageIndex, final SCIFIOConfig config) throws ImgIOException, IncompatibleTypeException { return saveImg(resolve(destination), img, imageIndex, config); }
Example #29
Source File: ImgSaver.java From scifio with BSD 2-Clause "Simplified" License | 3 votes |
/** * As {@link #saveImg(Location, SCIFIOImgPlus, int)} with configuration * options. * * @param id * @param img * @param config Configuration information to use for this write. * @throws ImgIOException * @throws IncompatibleTypeException */ public Metadata saveImg(final Location id, final SCIFIOImgPlus<?> img, final int imageIndex, final SCIFIOConfig config) throws ImgIOException, IncompatibleTypeException { return writeImg(id, null, img, imageIndex, config); }
Example #30
Source File: ContentBased.java From SPIM_Registration with GNU General Public License v2.0 | 3 votes |
public static void main( String[] args ) throws IncompatibleTypeException { new ImageJ(); ImagePlus imp = new ImagePlus( "/Users/preibischs/workspace/TestLucyRichardson/src/resources/dros-1.tif" ); Img< FloatType > img = ImageJFunctions.wrap( imp ); final double[] sigma1 = new double[]{ 20, 20 }; final double[] sigma2 = new double[]{ 30, 30 }; ContentBased< FloatType > cb = new ContentBased<FloatType>( img, img.factory().imgFactory( new ComplexFloatType() ), sigma1, sigma2 ); ImageJFunctions.show( cb.getContentBasedImg() ); }