Java Code Examples for net.imglib2.IterableInterval#dimension()
The following examples show how to use
net.imglib2.IterableInterval#dimension() .
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: 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 2
Source File: ZernikeComputer.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public ZernikeMoment calculate(final IterableInterval<T> ii) { final double width2 = (ii.dimension(0) - 1) / 2.0; final double height2 = (ii.dimension(1) - 1) / 2.0; final double centerX = width2 + ii.min(0); final double centerY = height2 + ii.min(1); final double radius = Math.sqrt(width2 * width2 + height2 * height2); // Compute pascal's triangle for binomal coefficients: d[x][y] equals (x // over y) final double[][] d = computePascalsTriangle(order); // initialize zernike moment final ZernikeMoment moment = initZernikeMoment(order, repetition, d); // get the cursor of the iterable interval final Cursor<? extends RealType<?>> cur = ii.localizingCursor(); // run over iterable interval while (cur.hasNext()) { cur.fwd(); // get 2d centered coordinates final int x = (int) (cur.getIntPosition(0) - ii.min(0)); final int y = (int) (cur.getIntPosition(1) - ii.min(1)); final double xm = (x - centerX) / radius; final double ym = (y - centerY) / radius; final double r = Math.sqrt(xm * xm + ym * ym); if (r <= 1 && cur.get().getRealDouble() != 0.0) { // calculate theta for this position final double theta = Math.atan2(xm, ym); moment.getZm().add(multiplyExp(1, moment.getP().evaluate(r), theta, moment.getM())); } } // normalization normalize(moment.getZm(), moment.getN(), getNumberOfPixelsInUnitDisk(radius)); return moment; }
Example 3
Source File: CooccurrenceMatrix3D.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public double[][] calculate(final IterableInterval<T> input) { double[][] matrix = new double[nrGreyLevels][nrGreyLevels]; final Cursor<T> cursor = input.localizingCursor(); final Pair<T, T> minMax = minmax.calculate(input); double localMin = minMax.getA().getRealDouble(); double localMax = minMax.getB().getRealDouble(); final int[][][] pixels = new int[(int) input.dimension(2)][(int) input .dimension(1)][(int) input.dimension(0)]; final int minimumX = (int) input.min(0); final int minimumY = (int) input.min(1); final int minimumZ = (int) input.min(2); final double diff = localMax - localMin; while (cursor.hasNext()) { cursor.fwd(); pixels[cursor.getIntPosition(2) - minimumZ][cursor .getIntPosition(1) - minimumY][cursor .getIntPosition(0) - minimumX] = (int) (((cursor .get().getRealDouble() - localMin) / diff) * (nrGreyLevels - 1)); } final double orientationAtX = orientation.getValueAtDim(0) * distance; final double orientationAtY = orientation.getValueAtDim(1) * distance; final double orientationAtZ = orientation.getValueAtDim(2) * distance; int nrPairs = 0; for (int z = 0; z < pixels.length; z++) { for (int y = 0; y < pixels[z].length; y++) { for (int x = 0; x < pixels[z][y].length; x++) { // ignore pixels not in mask if (pixels[z][y][x] == Integer.MAX_VALUE) { continue; } // get second pixel final int sx = (int) (x + orientationAtX); final int sy = (int) (y + orientationAtY); final int sz = (int) (z + orientationAtZ); // second pixel in interval and mask if (sx >= 0 && sy >= 0 && sz >= 0 && sz < pixels.length && sy < pixels[sz].length && sx < pixels[sz][sy].length && pixels[sz][sy][sx] != Integer.MAX_VALUE) { matrix[pixels[z][y][x]][pixels[sz][sy][sx]]++; nrPairs++; } } } } // normalize matrix if (nrPairs > 0) { double divisor = 1.0 / nrPairs; for (int row = 0; row < matrix.length; row++) { for (int col = 0; col < matrix[row].length; col++) { matrix[row][col] *= divisor; } } } return matrix; }
Example 4
Source File: CooccurrenceMatrix2D.java From imagej-ops with BSD 2-Clause "Simplified" License | 4 votes |
@Override public double[][] calculate(final IterableInterval<T> input) { final double[][] output = new double[nrGreyLevels][nrGreyLevels]; final Cursor<? extends RealType<?>> cursor = input.localizingCursor(); final Pair<T, T> minMax = minmax.calculate(input); final double localMin = minMax.getA().getRealDouble(); final double localMax = minMax.getB().getRealDouble(); final int[][] pixels = new int[(int) input.dimension(1)][(int) input .dimension(0)]; for (int i = 0; i < pixels.length; i++) { Arrays.fill(pixels[i], Integer.MAX_VALUE); } final int minimumX = (int) input.min(0); final int minimumY = (int) input.min(1); final double diff = localMax - localMin; while (cursor.hasNext()) { cursor.fwd(); final int bin = (int) (((cursor.get().getRealDouble() - localMin) / diff) * (nrGreyLevels)); pixels[cursor.getIntPosition(1) - minimumY][cursor.getIntPosition(0) - minimumX] = bin < nrGreyLevels - 1 ? bin : nrGreyLevels - 1; } int nrPairs = 0; final int orientationAtX = orientation.getValueAtDim(0) * distance; final int orientationAtY = orientation.getValueAtDim(1) * distance; for (int y = 0; y < pixels.length; y++) { for (int x = 0; x < pixels[y].length; x++) { // ignore pixels not in mask if (pixels[y][x] == Integer.MAX_VALUE) { continue; } // // get second pixel final int sx = x + orientationAtX; final int sy = y + orientationAtY; // second pixel in interval and mask if (sx >= 0 && sy >= 0 && sy < pixels.length && sx < pixels[sy].length && pixels[sy][sx] != Integer.MAX_VALUE) { output[pixels[y][x]][pixels[sy][sx]]++; nrPairs++; } } } if (nrPairs > 0) { double divisor = 1.0 / nrPairs; for (int row = 0; row < output.length; row++) { for (int col = 0; col < output[row].length; col++) { output[row][col] *= divisor; } } } return output; }