Esempio n. 1
0
  /*
   * Makes sure calculation of IJ1 channels is correctly invertible
   */
  @Test
  public void testRasterization() {
    final long[][] dimsList = {{1, 1, 1}, {1, 2, 3}, {2, 3, 4}, {5, 4, 3}, {4, 2, 7}};
    final AxisType[] axes = {Axes.CHANNEL, SCIFIOAxes.SPECTRA, SCIFIOAxes.FREQUENCY};
    for (long[] dims : dimsList) {
      // setup
      long numChannels = 1;
      for (long dim : dims) numChannels *= dim;

      // test from long index back to long index
      for (long channel = 0; channel < numChannels; channel++) {
        long[] channelPositions = new long[dims.length];
        LegacyUtils.fillChannelIndices(dims, axes, channel, channelPositions);
        long ij1Pos = LegacyUtils.calcIJ1ChannelPos(dims, axes, channelPositions);
        assertEquals(channel, ij1Pos);
      }

      // test from long[] index back to long[] index
      long[] channelPositions1 = new long[dims.length];
      long[] channelPositions2 = new long[dims.length];
      Extents extents = new Extents(dims);
      Position pos = extents.createPosition();
      while (pos.hasNext()) {
        pos.fwd();
        pos.localize(channelPositions1);
        long ij1Channel = LegacyUtils.calcIJ1ChannelPos(dims, axes, channelPositions1);
        LegacyUtils.fillChannelIndices(dims, axes, ij1Channel, channelPositions2);
        for (int i = 0; i < channelPositions1.length; i++)
          assertEquals(channelPositions1[i], channelPositions2[i]);
      }
    }
  }
Esempio n. 2
0
  /** Fills the output image from the input image doing coordinate transformations as needed */
  @Override
  public boolean process() {
    final Img<? extends RealType<?>> inputImage = dataset.getImgPlus();

    inputAccessor = inputImage.randomAccess();
    outputAccessor = outputImage.randomAccess();

    final long width = inputDimensions[0];
    final long height = inputDimensions[1];

    long rx, ry, rw, rh;

    if (flipper.isShapePreserving() && (bounds.width > 0) && (bounds.height > 0)) {
      rx = (long) bounds.x;
      ry = (long) bounds.y;
      rw = (long) bounds.width;
      rh = (long) bounds.height;
    } else {
      rx = 0;
      ry = 0;
      rw = width;
      rh = height;
    }

    final long[] planeDims = new long[inputImage.numDimensions() - 2];
    for (int i = 0; i < planeDims.length; i++) planeDims[i] = inputDimensions[i + 2];
    final Extents extents = new Extents(planeDims);
    final Position planePos = extents.createPosition();
    if (planeDims.length == 0) { // 2d Dataset
      processPlane(planePos, rx, ry, rw, rh);
    } else { // more than two dimensions
      while (planePos.hasNext()) {
        planePos.fwd();
        processPlane(planePos, rx, ry, rw, rh);
      }
    }
    return true;
  }