コード例 #1
0
  @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))));
      }
    }
  }
コード例 #2
0
ファイル: AbstractCell.java プロジェクト: Jondeen/imglib
 /**
  * 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);
 }