Java Code Examples for net.imglib2.IterableInterval#numDimensions()
The following examples show how to use
net.imglib2.IterableInterval#numDimensions() .
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: DefaultCenterOfGravity.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RealLocalizable calculate(final IterableInterval<T> input) { final int numDimensions = input.numDimensions(); final double[] output = new double[numDimensions]; final double[] intensityValues = new double[numDimensions]; final Cursor<T> c = input.localizingCursor(); while (c.hasNext()) { c.fwd(); for (int i = 0; i < output.length; i++) { output[i] += c.getDoublePosition(i) * c.get().getRealDouble(); intensityValues[i] += c.get().getRealDouble(); } } for (int i = 0; i < output.length; i++) { output[i] = output[i] / intensityValues[i]; } return new RealPoint(output); }
Example 2
Source File: CentroidII.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public RealLocalizable calculate(final IterableInterval<?> input) { int numDimensions = input.numDimensions(); double[] output = new double[numDimensions]; Cursor<?> c = input.localizingCursor(); double[] pos = new double[numDimensions]; while (c.hasNext()) { c.fwd(); c.localize(pos); for (int i = 0; i < output.length; i++) { output[i] += pos[i]; } } for (int i = 0; i < output.length; i++) { output[i] = output[i] / input.size(); } return new RealPoint(output); }
Example 3
Source File: DefaultCoordinatesEquation.java From imagej-ops with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void compute(final UnaryFunctionOp<long[], N> op, final IterableInterval<T> output) { final Cursor<T> c = output.localizingCursor(); final long[] pos = new long[output.numDimensions()]; // loop through all pixels, set the current position and call the op while (c.hasNext()) { c.fwd(); c.localize(pos); for (int i = 0; i < output.numDimensions(); i++) { op.calculate(pos); c.get().setReal(op.calculate(pos).floatValue()); } } }
Example 4
Source File: DefaultASCII.java From imagej-ops with BSD 2-Clause "Simplified" License | 5 votes |
public static <T extends RealType<T>> String ascii( final IterableInterval<T> image, final T min, final T max) { final long dim0 = image.dimension(0); final long dim1 = image.dimension(1); // TODO: Check bounds. final int w = (int) (dim0 + 1); final int h = (int) dim1; // span = max - min final T span = max.copy(); span.sub(min); // allocate ASCII character array final char[] c = new char[w * h]; for (int y = 1; y <= h; y++) { c[w * y - 1] = '\n'; // end of row } // loop over all available positions final Cursor<T> cursor = image.localizingCursor(); final int[] pos = new int[image.numDimensions()]; final T tmp = image.firstElement().copy(); while (cursor.hasNext()) { cursor.fwd(); cursor.localize(pos); final int index = w * pos[1] + pos[0]; // normalized = (value - min) / (max - min) tmp.set(cursor.get()); tmp.sub(min); final double normalized = tmp.getRealDouble() / span.getRealDouble(); final int charLen = CHARS.length(); final int charIndex = (int) (charLen * normalized); c[index] = CHARS.charAt(charIndex < charLen ? charIndex : charLen - 1); } return new String(c); }
Example 5
Source File: DefaultEquation.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public void compute(final String input, final IterableInterval<T> output) { final String equation = input + ";"; // evaluate the equation using Javascript! final ScriptLanguage js = scriptService.getLanguageByName("javascript"); final ScriptEngine engine = js.getScriptEngine(); final Bindings bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE); final Cursor<T> c = output.localizingCursor(); final long[] pos = new long[output.numDimensions()]; bindings.put("p", pos); bindings.put("c", c); if (engine instanceof Compilable) try { final String script = "importClass(Packages.java.lang.Double);\n" + "while (c.hasNext()) {\n" + " c.fwd();\n" + " c.localize(p);\n" + " o = " + equation + ";\n" + " try {\n" + " c.get().setReal(o);\n" + " } catch(e) {" + " c.get().setReal(Double.NaN);\n" + " }\n" + "}"; final Compilable compiler = (Compilable) engine; final CompiledScript compiled = compiler.compile(script); compiled.eval(bindings); } catch (final ScriptException e) { log.warn(e); // fallthru } try { while (c.hasNext()) { c.fwd(); c.localize(pos); final Object o = engine.eval(equation); final double d = o instanceof Number ? ((Number) o).doubleValue() : Double.NaN; c.get().setReal(d); } } catch (final ScriptException exc) { log.error(exc); } }