示例#1
0
  @Before
  public void createSourceData() {
    dimensions = new long[] {48, 17, 102};

    numValues = 1;
    for (int d = 0; d < dimensions.length; ++d) numValues *= dimensions[d];

    intData = new int[numValues];
    intDataSum = 0;
    final Random random = new Random(0);
    for (int i = 0; i < numValues; ++i) {
      intData[i] = random.nextInt();
      intDataSum += intData[i];
    }

    intImg = new ListImgFactory<IntType>().create(dimensions, new IntType());

    final long[] pos = new long[dimensions.length];
    final RandomAccess<IntType> a = intImg.randomAccess();

    for (int i = 0; i < numValues; ++i) {
      IntervalIndexer.indexToPosition(i, dimensions, pos);
      a.setPosition(pos);
      a.get().set(intData[i]);
    }
  }
示例#2
0
  public AbstractCell(final int[] dimensions, final long[] min) {
    this.n = dimensions.length;
    this.dimensions = dimensions.clone();
    this.steps = new int[n];
    IntervalIndexer.createAllocationSteps(dimensions, steps);
    this.min = min.clone();

    max = new long[n];
    for (int d = 0; d < n; ++d) max[d] = min[d] + dimensions[d] - 1;

    int nPixels = dimensions[0];
    for (int d = 1; d < n; ++d) nPixels *= dimensions[d];
    numPixels = nPixels;
  }
示例#3
0
 int[] getImgAsInts(final Img<IntType> img) {
   final RandomAccess<IntType> a = img.randomAccess();
   final int N = (int) img.size();
   final int[] data = new int[N];
   final long[] dim = new long[img.numDimensions()];
   final long[] pos = new long[img.numDimensions()];
   img.dimensions(dim);
   for (int i = 0; i < N; ++i) {
     IntervalIndexer.indexToPosition(i, dim, pos);
     a.setPosition(pos);
     data[i] = a.get().get();
   }
   return data;
 }
  @Override
  public void map() {
    // more detailed documentation of the binary arithmetic can be found in
    // ArrayImgXYByteProjector

    double minCopy = min;
    int offset = 0;
    final long[] tmpPos = position.clone();
    tmpPos[0] = 0;
    tmpPos[1] = 0;

    offset = (int) IntervalIndexer.positionToIndex(tmpPos, dims);

    // copy the selected part of the source array (e.g. a xy plane at time t
    // in a video) into the target array.
    System.arraycopy(sourceArray, offset, targetArray, 0, targetArray.length);

    if (isSigned) {
      for (int i = 0; i < targetArray.length; i++) {
        // Short.MIN => 0 && Short.MAX => 65535 (2^16 - 1) => unsigned
        // short
        targetArray[i] = (short) (targetArray[i] - 0x8000);
      }
      // old => unsigned short minimum
      minCopy += 0x8000;
    }
    if (normalizationFactor != 1) {
      for (int i = 0; i < targetArray.length; i++) {
        // normalizedValue = (oldValue - min) * normalizationFactor
        // clamped to 0 .. 65535
        targetArray[i] =
            (short)
                Math.min(
                    65535,
                    Math.max(
                        0,
                        (Math.round(((targetArray[i] & 0xFFFF) - minCopy) * normalizationFactor))));
      }
    }
  }
示例#5
0
 public void indexToGlobalPosition(final int index, final long[] position) {
   IntervalIndexer.indexToPosition(index, dimensions, position);
   for (int d = 0; d < position.length; ++d) position[d] += min[d];
 }
示例#6
0
 public long indexToGlobalPosition(final int index, final int d) {
   return IntervalIndexer.indexToPosition(index, dimensions, steps, d) + min[d];
 }
示例#7
0
 /**
  * compute the index in the underlying flat array of this cell which corresponds to a local
  * position (i.e., relative to the origin of this cell).
  *
  * @param position a local position
  * @return corresponding index
  */
 public int localPositionToIndex(final long[] position) {
   return IntervalIndexer.positionToIndex(position, dimensions);
 }
示例#8
0
 @Override
 public void localize(final int[] position) {
   IntervalIndexer.indexToPosition(type.getIndex(), container.dim, position);
 }
示例#9
0
 @Override
 public int getIntPosition(final int dim) {
   return IntervalIndexer.indexToPosition(type.getIndex(), container.dim, dim);
 }
 @Override
 public void jumpFwd(final long i) {
   index += i;
   IntervalIndexer.indexToPosition(index, dimensions, position);
 }