/** Starts the program. */
  public void runAlgorithm() {
    int[] destExtents = null;

    if (srcImage == null) {
      displayError("Source Image is null");

      return;
    }

    if (srcImage.getNDims() == 2) {
      makeKernels2D();
    } else if ((srcImage.getNDims() == 3) && (image25D == false)) {
      makeKernels3D();
    } else if ((srcImage.getNDims() == 3) && (image25D == true)) {
      makeKernels2D();
    }

    try {

      if (srcImage.getNDims() == 2) {
        destExtents = new int[2];
        destExtents[0] = srcImage.getExtents()[0]; // X dim
        destExtents[1] = srcImage.getExtents()[1]; // Y dim
      } else if (srcImage.getNDims() == 3) {
        destExtents = new int[3];
        destExtents[0] = srcImage.getExtents()[0]; // X dim
        destExtents[1] = srcImage.getExtents()[1]; // Y dim
        destExtents[2] = srcImage.getExtents()[2]; // Z dim
      }

      zXMask = new ModelImage(ModelImage.UBYTE, destExtents, " Edges");
    } catch (OutOfMemoryError e) {
      destImage = null;
      srcImage = null;
      zXMask.disposeLocal();
      zXMask = null;
      errorCleanUp("Algorithm EdgeLapSep : Out of memory", true);

      return;
    }

    if (destImage != null) { // NEW

      if (srcImage.getNDims() == 2) {
        calcStoreInDest2D(1, zeroDetectionType);
      } else if ((srcImage.getNDims() == 3) && (image25D == false)) {
        calcStoreInDest3D(zeroDetectionType);
      } else if ((srcImage.getNDims() == 3) && (image25D == true)) {
        calcStoreInDest2D(srcImage.getExtents()[2], zeroDetectionType);
      }
    }

    if (threadStopped) {
      finalize();

      return;
    }
  }
  /**
   * This function produces the EdgeLap of input image.
   *
   * @param detectionType the type of zero crossing detection to perform
   */
  private void calcStoreInDest3D(int detectionType) {
    int nImages;
    int length, totalLength;
    float[] buffer, xResultBuffer, yResultBuffer, zResultBuffer;
    int start;
    float[] sliceBuffer;

    try {
      destImage.setLock();
    } catch (IOException error) {
      errorCleanUp("Algorithm EdgeLapSep: Image(s) locked", false);

      return;
    }

    try {
      length = srcImage.getSliceSize();
      totalLength = srcImage.getSliceSize() * srcImage.getExtents()[2];
      nImages = srcImage.getExtents()[2];
      buffer = new float[totalLength];
      sliceBuffer = new float[length];
      srcImage.exportData(0, totalLength, buffer); // locks and releases lock

      // fireProgressStateChanged(srcImage.getImageName(), "Calculating Zero X-ings ...");
    } catch (IOException error) {
      buffer = null;
      sliceBuffer = null;
      xResultBuffer = null;
      yResultBuffer = null;
      zResultBuffer = null;
      errorCleanUp("Algorithm EdgeLapSep exportData: Image(s) locked", true);

      return;
    } catch (OutOfMemoryError e) {
      buffer = null;
      sliceBuffer = null;
      xResultBuffer = null;
      yResultBuffer = null;
      zResultBuffer = null;
      errorCleanUp("Algorithm EdgeLapSep: Out of memory", true);

      return;
    }

    // initProgressBar();
    fireProgressStateChanged(0, srcImage.getImageName(), "Convolving X dimension ...");

    /** Minimum and maximum progress value for the convolving part */
    int min = 0;
    int max = min + Math.round(100 / 2.0f);
    float stepPerDimension = ((float) (max - min)) / 3.0f;
    AlgorithmSeparableConvolver xConvolver = null;

    if (Math.round(stepPerDimension) > 1) {
      xConvolver =
          new AlgorithmSeparableConvolver(
              buffer, srcImage.getExtents(), GxxData, kExtents, false); // assume not color

      xConvolver.setProgressValues(generateProgressValues(min, min + Math.round(stepPerDimension)));
      linkProgressToAlgorithm(xConvolver);
    } else {
      xConvolver =
          new AlgorithmSeparableConvolver(
              buffer, srcImage.getExtents(), GxxData, kExtents, false); // assume not color
    }

    if (!entireImage) {
      xConvolver.setMask(mask);
    }

    xConvolver.run();
    xResultBuffer = xConvolver.getOutputBuffer();
    xConvolver.finalize();
    xConvolver = null;

    fireProgressStateChanged(
        min + Math.round(stepPerDimension), srcImage.getImageName(), "Convolving Y dimension...");

    AlgorithmSeparableConvolver yConvolver = null;

    if ((Math.round(stepPerDimension * 2) - Math.round(stepPerDimension)) > 1) {
      yConvolver =
          new AlgorithmSeparableConvolver(
              buffer, srcImage.getExtents(), GyyData, kExtents, false); // assume not color

      yConvolver.setProgressValues(
          generateProgressValues(
              min + Math.round(stepPerDimension), min + Math.round(stepPerDimension * 2)));

      linkProgressToAlgorithm(yConvolver);
    } else {
      yConvolver =
          new AlgorithmSeparableConvolver(
              buffer, srcImage.getExtents(), GyyData, kExtents, false); // assume not color
    }

    if (!entireImage) {
      yConvolver.setMask(mask);
    }

    yConvolver.run();
    yResultBuffer = yConvolver.getOutputBuffer();
    yConvolver.finalize();
    yConvolver = null;

    fireProgressStateChanged(
        min + Math.round(stepPerDimension * 2),
        srcImage.getImageName(),
        "Convolving Z dimension...");

    AlgorithmSeparableConvolver zConvolver = null;

    if ((Math.round(stepPerDimension * 3) - Math.round(stepPerDimension * 2)) > 1) {
      zConvolver =
          new AlgorithmSeparableConvolver(
              buffer, srcImage.getExtents(), GzzData, kExtents, false); // assume not color

      zConvolver.setProgressValues(
          generateProgressValues(min + Math.round(stepPerDimension * 2), max));

      linkProgressToAlgorithm(zConvolver);
    } else {
      zConvolver =
          new AlgorithmSeparableConvolver(
              buffer, srcImage.getExtents(), GzzData, kExtents, false); // assume not color
    }

    if (!entireImage) {
      zConvolver.setMask(mask);
    }

    zConvolver.run();
    zResultBuffer = zConvolver.getOutputBuffer();
    zConvolver.finalize();
    zConvolver = null;

    min = max;
    max = 100;

    float stepPerImage = ((float) (max - min)) / nImages;

    for (int s = 0; (s < nImages) && !threadStopped; s++) {
      fireProgressStateChanged(
          min + Math.round(stepPerImage * s),
          srcImage.getImageName(),
          "Calculating the edges of slice " + (s + 1) + "...");

      start = s * length;

      for (int i = start; (i < (start + length)) && !threadStopped; i++) {

        if (entireImage || mask.get(i)) {
          destImage.set(i, -(xResultBuffer[i] + yResultBuffer[i] + zResultBuffer[i]));
        } else {
          destImage.set(i, buffer[i]);
        }
      }

      try {
        destImage.exportDataNoLock(start, length, sliceBuffer);
      } catch (IOException error) {
        buffer = null;
        sliceBuffer = null;
        errorCleanUp("Algorithm EdgeLapSep exportData: " + error, true);

        return;
      }

      genZeroXMask(s, sliceBuffer, detectionType);
    }

    if (threadStopped) {
      finalize();

      return;
    }

    zXMask.calcMinMax();
    destImage.calcMinMax();
    destImage.releaseLock();

    setCompleted(true);
  }
  /**
   * This function produces the EdgeLap of input image.
   *
   * @param nImages number of images on which to find zero crossings. If 2D image then nImage = 1.
   *     If 3D image where each image is to processed independently then nImages equals the number
   *     of images in the volume.
   * @param detectionType the type of zero crossing detection to perform
   */
  private void calcStoreInDest2D(int nImages, int detectionType) {

    // int i, s, idx;
    int length;
    int start;
    float[] buffer, xResultBuffer, yResultBuffer;

    try {
      destImage.setLock();
    } catch (IOException error) {
      errorCleanUp("Algorithm EdgeLapSep: Image(s) locked", false);

      return;
    }

    try {
      length = srcImage.getSliceSize();
      buffer = new float[length];
      // fireProgressStateChanged(srcImage.getImageName(), "Calculating the Edge ...");
    } catch (OutOfMemoryError e) {
      buffer = null;
      errorCleanUp("Algorithm Edge Lap Sep: Out of memory", true);

      return;
    }

    fireProgressStateChanged(0, srcImage.getImageName(), "Calculating the Edge ...");

    float stepPerImage = 100f / nImages;

    // initProgressBar();

    for (int s = 0; (s < nImages) && !threadStopped; s++) {
      fireProgressStateChanged(
          Math.round(stepPerImage * s),
          srcImage.getImageName(),
          "Calculating the edges of slice " + (s + 1) + "...");
      start = s * length;

      try {
        srcImage.exportData(start, length, buffer); // locks and releases lock
      } catch (IOException error) {
        errorCleanUp("Algorithm EdgeLapSep: Image(s) locked", false);

        return;
      }

      int min = Math.round(stepPerImage * s);
      int max = min + Math.round(((float) (Math.round(stepPerImage * (s + 1)) - min)) / 2.0f);
      AlgorithmSeparableConvolver xConvolver = null;

      if ((max - min) > 1) {
        xConvolver =
            new AlgorithmSeparableConvolver(
                buffer,
                new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]},
                GxxData,
                kExtents,
                false);

        xConvolver.setProgressValues(generateProgressValues(min, max));
        linkProgressToAlgorithm(xConvolver);

      } else {
        xConvolver =
            new AlgorithmSeparableConvolver(
                buffer,
                new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]},
                GxxData,
                kExtents,
                false); // assume not color
      }

      if (!entireImage) {
        xConvolver.setMask(mask);
      }

      xConvolver.run();
      xResultBuffer = xConvolver.getOutputBuffer();
      xConvolver.finalize();
      xConvolver = null;

      min = max;
      max = Math.round(stepPerImage * (s + 1));

      AlgorithmSeparableConvolver yConvolver = null;

      if ((max - min) > 1) {
        yConvolver =
            new AlgorithmSeparableConvolver(
                buffer,
                new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]},
                GyyData,
                kExtents,
                false);

        yConvolver.setProgressValues(generateProgressValues(min, max));
        linkProgressToAlgorithm(yConvolver);

      } else {
        yConvolver =
            new AlgorithmSeparableConvolver(
                buffer,
                new int[] {srcImage.getExtents()[0], srcImage.getExtents()[1]},
                GyyData,
                kExtents,
                false); // assume not color
      }

      if (!entireImage) {
        yConvolver.setMask(mask);
      }

      yConvolver.run();
      yResultBuffer = yConvolver.getOutputBuffer();
      yConvolver.finalize();
      yConvolver = null;

      for (int i = 0, idx = start; (i < buffer.length) && !threadStopped; i++, idx++) {

        if (entireImage || mask.get(i)) {
          destImage.set(idx, -(xResultBuffer[i] + yResultBuffer[i]));
        } else {
          destImage.set(idx, buffer[i]);
        }
      }

      try {
        destImage.exportDataNoLock(start, length, buffer);
      } catch (IOException error) {
        errorCleanUp("Algorithm EdgeLapSep exportData: " + error, false);

        return;
      }

      genZeroXMask(s, buffer, detectionType);
    }

    if (threadStopped) {
      finalize();

      return;
    }

    zXMask.calcMinMax();
    destImage.calcMinMax();
    destImage.releaseLock();

    setCompleted(true);
  }
  /**
   * Generates a zero crossing mask for a 2D function. Sets a ModelImage to 255 if a zero crossing
   * is detected.
   *
   * @param slice the slice of the volume which we are working on (0 if from 2D image)
   * @param buffer array in which to find zero crossing
   * @param detectionType the type of zero crossing detection to perform
   */
  public void genZeroXMask(int slice, float[] buffer, int detectionType) {
    float x0, x1, x2, x3;
    int i0, i1, i2, i3;
    int i, j;
    int indexY;
    int length;

    int xDim = srcImage.getExtents()[0];
    int yDim = srcImage.getExtents()[1];

    length = xDim * yDim;

    int xxDim = xDim - 1;
    int yyDim = yDim - 1;
    float level = 0;
    int offset = slice * length;

    for (j = 0; j < yyDim; j++) {
      indexY = j * xDim;

      for (i = 0; i < xxDim; i++) {
        i0 = indexY + i;

        if (detectionType == MARCHING_SQUARES) {
          i1 = i0 + 1;
          i2 = i0 + xDim;
          i3 = i0 + 1 + xDim;

          x0 = buffer[i0];
          x1 = buffer[i1];
          x2 = buffer[i2];
          x3 = buffer[i3];

          if ((x0 >= level)
              && (x1 >= level)
              && (x2 >= level)
              && (x3 >= level)) { // case 0 - no edge
          } else if ((x0 >= level) && (x1 >= level) && (x2 < level) && (x3 >= level)) {

            // case 1 - edge in the lower left
            zXMask.set(offset + i2, 255);
          } else if ((x0 >= level) && (x1 >= level) && (x2 >= level) && (x3 < level)) {

            // case 2 - edge in the lower right
            zXMask.set(offset + i3, 255);
          } else if ((x0 >= level) && (x1 >= level) && (x2 < level) && (x3 < level)) {

            // case 3 - edge horizontally
            zXMask.set(offset + i2, 255);
            zXMask.set(offset + i3, 255);
          } else if ((x0 >= level) && (x1 < level) && (x2 >= level) && (x3 >= level)) {

            // case 4 - edge in the upper right
            zXMask.set(offset + i1, 255);
          } else if ((x0 >= level) && (x1 < level) && (x2 < level) && (x3 >= level)) {

            // case 5 - ambiguous case; either edge in upper right and lower left or
            // edge that goes from the upper right to the lower left
            zXMask.set(offset + i1, 255);
            zXMask.set(offset + i2, 255);
          } else if ((x0 >= level) && (x1 < level) && (x2 >= level) && (x3 < level)) {

            // case 6 - edge going vertically along the right
            zXMask.set(offset + i1, 255);
            zXMask.set(offset + i3, 255);
          } else if ((x0 >= level) && (x1 < level) && (x2 < level) && (x3 < level)) {

            // case 7 - edge in the upper left
            zXMask.set(offset + i0, 255);
          } else if ((x0 < level) && (x1 >= level) && (x2 >= level) && (x3 >= level)) {

            // case 8 - edge in the upper left
            zXMask.set(offset + i0, 255);
          } else if ((x0 < level) && (x1 >= level) && (x2 < level) && (x3 >= level)) {

            // case 9 - edge going vertically along the left
            zXMask.set(offset + i0, 255);
            zXMask.set(offset + i2, 255);
          } else if ((x0 < level) && (x1 >= level) && (x2 >= level) && (x3 < level)) {

            // case 10 - ambiguous case; either edge in upper left and lower right or
            // edge that goes from the upper left to the lower right
            zXMask.set(offset + i0, 255);
            zXMask.set(offset + i3, 255);
          } else if ((x0 < level) && (x1 >= level) && (x2 < level) && (x3 < level)) {

            // case 11 - edge in the upper right
            zXMask.set(offset + i1, 255);
          } else if ((x0 < level) && (x1 < level) && (x2 >= level) && (x3 >= level)) {

            // case 12 - edge going horizontally along the top
            zXMask.set(offset + i0, 255);
            zXMask.set(offset + i1, 255);
          } else if ((x0 < level) && (x1 < level) && (x2 < level) && (x3 >= level)) {

            // case 13 - edge in the lower right
            zXMask.set(offset + i3, 255);
          } else if ((x0 < level) && (x1 < level) && (x2 >= level) && (x3 < level)) {

            // case 14 - edge in the lower left
            zXMask.set(offset + i2, 255);
          } else if ((x0 < level)
              && (x1 < level)
              && (x2 < level)
              && (x3 < level)) { // case 15 - no edge
          }
        } else if (detectionType == NEGATIVE_EDGES) {

          if (buffer[i0] <= 1) {
            zXMask.set(offset + i0, 255);
          }
        } else if (detectionType == OLD_DETECTION) {
          i1 = i0 + 1;
          i2 = i0 + xDim;
          i3 = i0 + 1 + xDim;

          x0 = buffer[i0];
          x1 = buffer[i1];
          x2 = buffer[i2];
          x3 = buffer[i3];

          if ((x0 > level) && (x1 > level) && (x2 > level) && (x3 > level)) {
            zXMask.set(offset + i0, 0);
          } else if ((x0 < level) && (x1 < level) && (x2 < level) && (x3 < level)) {
            zXMask.set(offset + i0, 0);
          } else {
            zXMask.set(offset + i0, 255);
          }
        }
      }
    }

    FileInfoBase[] fileInfo = zXMask.getFileInfo();

    fileInfo[slice].setModality(srcImage.getFileInfo()[slice].getModality());
    fileInfo[slice].setFileDirectory(srcImage.getFileInfo()[slice].getFileDirectory());
    fileInfo[slice].setEndianess(srcImage.getFileInfo()[slice].getEndianess());
    fileInfo[slice].setUnitsOfMeasure(srcImage.getFileInfo()[slice].getUnitsOfMeasure());
    fileInfo[slice].setResolutions(srcImage.getFileInfo()[slice].getResolutions());
    fileInfo[slice].setExtents(zXMask.getExtents());
    fileInfo[slice].setMax(255);
    fileInfo[slice].setMin(0);
    fileInfo[slice].setPixelPadValue(srcImage.getFileInfo()[slice].getPixelPadValue());
    fileInfo[slice].setPhotometric(srcImage.getFileInfo()[slice].getPhotometric());
  }
예제 #5
0
  /** cat. */
  private void cat3D_4D_4D() {

    int length;
    int xDim, yDim;
    float[] buffer;
    int cFactor = 1;
    int i, j;
    float[] resols = new float[3];
    float[] origins = new float[3];
    FileInfoBase[] fileInfo = null;
    FileInfoDicom[] fileInfoDicom = null;
    int srcALength, srcBLength;

    try {
      fireProgressStateChanged(srcImage1.getImageName(), "Concatenating images ...");
      resols = new float[4];
      origins = new float[4];
      xDim = srcImage1.getExtents()[0];
      yDim = srcImage1.getExtents()[1];

      if (srcImage1.isColorImage()) {
        cFactor = 4;
      }

      length = cFactor * xDim * yDim;
      buffer = new float[length];

      int nImages;

      if (srcImage1.getNDims() > srcImage2.getNDims()) {
        nImages =
            (srcImage1.getExtents()[2] * srcImage1.getExtents()[3]) + srcImage2.getExtents()[2];

        for (i = 0;
            (i < (srcImage1.getExtents()[2] * srcImage1.getExtents()[3])) && !threadStopped;
            i++) {
          fireProgressStateChanged(Math.round((float) (i) / (nImages - 1) * 100));

          srcImage1.exportData(i * length, length, buffer);
          destImage.importData(i * length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        for (j = 0; (j < srcImage2.getExtents()[2]) && !threadStopped; j++) {
          fireProgressStateChanged(Math.round((float) (i + j) / (nImages - 1) * 100));

          srcImage2.exportData(j * length, length, buffer);
          destImage.importData((i + j) * length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        destImage.calcMinMax();
      } else {
        nImages =
            (srcImage2.getExtents()[2] * srcImage2.getExtents()[3]) + srcImage1.getExtents()[2];

        for (j = 0; (j < srcImage1.getExtents()[2]) && !threadStopped; j++) {
          fireProgressStateChanged(Math.round((float) (j) / (nImages - 1) * 100));

          srcImage1.exportData(j * length, length, buffer);
          destImage.importData(j * length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        for (i = 0;
            (i < (srcImage2.getExtents()[2] * srcImage2.getExtents()[3])) && !threadStopped;
            i++) {
          fireProgressStateChanged(Math.round((float) (i + j) / (nImages - 1) * 100));

          srcImage2.exportData(i * buffer.length, length, buffer);
          destImage.importData((i + j) * buffer.length, buffer, false);
        }

        if (threadStopped) {
          buffer = null;
          finalize();

          return;
        }

        destImage.calcMinMax();
      }
    } catch (IOException error) {
      buffer = null;
      destImage.disposeLocal(); // Clean up memory of result image
      destImage = null;
      errorCleanUp("Algorithm Concat. Images: Image(s) locked", true);

      return;
    } catch (OutOfMemoryError e) {
      buffer = null;
      destImage.disposeLocal(); // Clean up memory of result image
      destImage = null;
      errorCleanUp("Algorithm Concat. Images: Out of memory", true);

      return;
    }

    resols[0] = srcImage1.getFileInfo()[0].getResolutions()[0];
    resols[1] = srcImage1.getFileInfo()[0].getResolutions()[1];
    resols[2] = srcImage1.getFileInfo()[0].getResolutions()[2];
    resols[3] = srcImage1.getFileInfo()[0].getResolutions()[3];
    origins[0] = srcImage1.getFileInfo()[0].getOrigin()[0];
    origins[1] = srcImage1.getFileInfo()[0].getOrigin()[1];
    origins[2] = srcImage1.getFileInfo()[0].getOrigin()[2];
    origins[3] = srcImage1.getFileInfo()[0].getOrigin()[3];

    if ((srcImage1.getFileInfo()[0] instanceof FileInfoDicom)
        && (srcImage2.getFileInfo()[0] instanceof FileInfoDicom)) {
      fileInfoDicom = new FileInfoDicom[destImage.getExtents()[2] * destImage.getExtents()[3]];

      if (srcImage1.getNDims() > srcImage2.getNDims()) {
        srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3];

        for (i = 0; (i < srcALength) && !threadStopped; i++) {
          fileInfoDicom[i] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[i]).clone());
          fileInfoDicom[i].setOrigin(origins);
        }

        for (i = 0; (i < srcImage2.getExtents()[2]) && !threadStopped; i++) {
          fileInfoDicom[srcALength + i] =
              (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[i]).clone());
          fileInfoDicom[srcALength + i].setOrigin(origins);
        }
      } else {
        srcBLength = srcImage2.getExtents()[2] * srcImage2.getExtents()[3];

        for (i = 0; (i < srcImage1.getExtents()[2]) && !threadStopped; i++) {
          fileInfoDicom[i] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[i]).clone());
          fileInfoDicom[i].setOrigin(origins);
        }

        for (i = 0; (i < srcBLength) && !threadStopped; i++) {
          fileInfoDicom[srcImage1.getExtents()[2] + i] =
              (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[i]).clone());
          fileInfoDicom[srcImage1.getExtents()[2] + i].setOrigin(origins);
        }
      }

      destImage.setFileInfo(fileInfoDicom);
    } else {
      fileInfo = destImage.getFileInfo();

      for (i = 0;
          (i < (destImage.getExtents()[2] * destImage.getExtents()[3])) && !threadStopped;
          i++) {
        fileInfo[i].setModality(srcImage1.getFileInfo()[0].getModality());
        fileInfo[i].setFileDirectory(srcImage1.getFileInfo()[0].getFileDirectory());
        fileInfo[i].setEndianess(srcImage1.getFileInfo()[0].getEndianess());
        fileInfo[i].setUnitsOfMeasure(srcImage1.getFileInfo()[0].getUnitsOfMeasure());
        fileInfo[i].setResolutions(resols);
        fileInfo[i].setExtents(destImage.getExtents());
        fileInfo[i].setMax(destImage.getMax());
        fileInfo[i].setMin(destImage.getMin());
        fileInfo[i].setImageOrientation(srcImage1.getImageOrientation());
        fileInfo[i].setPixelPadValue(srcImage1.getFileInfo()[0].getPixelPadValue());
        fileInfo[i].setPhotometric(srcImage1.getFileInfo()[0].getPhotometric());
        fileInfo[i].setAxisOrientation(srcImage1.getAxisOrientation());
      }

      if (srcImage1.getFileInfo()[0] instanceof FileInfoImageXML) {

        if (srcImage1.getNDims() > srcImage2.getNDims()) {
          srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3];

          for (i = 0; (i < srcALength) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable());
            }
          }
        } else {

          for (i = 0; (i < srcImage1.getExtents()[2]) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage1.getFileInfo()[i]).getPSetHashtable());
            }
          }
        }
      }

      if (srcImage2.getFileInfo()[0] instanceof FileInfoImageXML) {

        if (srcImage1.getNDims() > srcImage2.getNDims()) {
          srcALength = srcImage1.getExtents()[2] * srcImage1.getExtents()[3];

          for (i = 0; (i < srcImage2.getExtents()[2]) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[srcALength + i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable());
            }
          }

        } else {
          srcBLength = srcImage2.getExtents()[2] * srcImage2.getExtents()[3];

          for (i = 0; (i < srcBLength) && !threadStopped; i++) {

            if (((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable() != null) {
              ((FileInfoImageXML) fileInfo[srcImage1.getExtents()[2] + i])
                  .setPSetHashtable(
                      ((FileInfoImageXML) srcImage2.getFileInfo()[i]).getPSetHashtable());
            }
          }
        }
      }
    }

    if (threadStopped) {
      buffer = null;
      finalize();

      return;
    }

    setCompleted(true);
    fileInfo = null;
    fileInfoDicom = null;
  }
예제 #6
0
  /** Starts the program. */
  public void runAlgorithm() {

    if ((srcImage1 == null) || (srcImage2 == null) || (destImage == null)) {
      displayError("Source Image(s) is null");
      setCompleted(false);

      return;
    }

    if (srcImage1.getType() != srcImage2.getType()) {
      displayError("Source Images must be of the same data type.");
      setCompleted(false);

      return;
    }

    float[] resols1 = srcImage1.getResolutions(0);
    float[] resols2 = srcImage2.getResolutions(0);

    if ((srcImage1.getNDims() == 2) && (srcImage2.getNDims() == 2)) {
      if (resols1[0] == resols2[0] && resols1[1] == resols2[1]) {
        cat2D_2D_3D();
      } else {
        displayError("Resolutions must match up");
        setCompleted(false);
        return;
      }

    } else if (((srcImage1.getNDims() == 2) && (srcImage2.getNDims() == 3))
        || ((srcImage1.getNDims() == 3) && (srcImage2.getNDims() == 2))) {
      if (resols1[0] == resols2[0] && resols1[1] == resols2[1]) {
        cat2D_3D_3D();
      } else {
        displayError("Resolutions must match up");
        setCompleted(false);
        return;
      }
    } else if ((srcImage1.getNDims() == 3)
        && (srcImage2.getNDims() == 3)
        && (destImage.getNDims() == 3)) {
      if (resols1[0] == resols2[0] && resols1[1] == resols2[1] && resols1[2] == resols2[2]) {
        cat3D_3D_3D();
      } else {
        displayError("Resolutions must match up");
        setCompleted(false);
        return;
      }
    } else if ((srcImage1.getNDims() == 3)
        && (srcImage2.getNDims() == 3)
        && (destImage.getNDims() == 4)) {
      if (resols1[0] == resols2[0] && resols1[1] == resols2[1] && resols1[2] == resols2[2]) {
        cat3D_3D_4D();
      } else {
        displayError("Resolutions must match up");
        setCompleted(false);
        return;
      }
    } else if (((srcImage1.getNDims() == 3) && (srcImage2.getNDims() == 4))
        || ((srcImage1.getNDims() == 4) && (srcImage2.getNDims() == 3))) {
      if (resols1[0] == resols2[0] && resols1[1] == resols2[1] && resols1[2] == resols2[2]) {
        cat3D_4D_4D();
      } else {
        displayError("Resolutions must match up");
        setCompleted(false);
        return;
      }

    } else if ((srcImage1.getNDims() == 4) && (srcImage2.getNDims() == 4)) {
      if (resols1[0] == resols2[0]
          && resols1[1] == resols2[1]
          && resols1[2] == resols2[2]
          && resols1[3] == resols2[3]) {
        cat4D_4D_4D();
      } else {
        displayError("Resolutions must match up");
        setCompleted(false);
        return;
      }
    } else {
      displayError("Source Image(s) dimensionality not supported.");
    }
  }
예제 #7
0
  /**
   * This function produces a new image that has been concatenated. Two 2D-images become one 3D
   * image.
   */
  private void cat2D_2D_3D() {

    int length;
    int xDim, yDim;
    int i;
    float[] buffer;
    int cFactor = 1;
    float[] resols = new float[3];
    FileInfoBase[] fileInfo = null;
    FileInfoDicom[] fileInfoDicom = null;

    try {
      resols = new float[3];
      xDim = srcImage1.getExtents()[0];
      yDim = srcImage1.getExtents()[1];

      if (srcImage1.isColorImage()) {
        cFactor = 4;
      }

      length = cFactor * xDim * yDim;
      buffer = new float[length];
      srcImage1.exportData(0, length, buffer);
      destImage.importData(0, buffer, false);
      srcImage2.exportData(0, length, buffer);
      destImage.importData(buffer.length, buffer, true);
    } catch (IOException error) {
      buffer = null;
      destImage.disposeLocal(); // Clean up memory of result image
      destImage = null;
      errorCleanUp("Algorithm Concat. Images: Image(s) locked", true);

      return;
    } catch (OutOfMemoryError e) {
      buffer = null;
      destImage.disposeLocal(); // Clean up memory of result image
      destImage = null;
      errorCleanUp("Algorithm Concat. Images: Out of memory", true);

      return;
    }

    resols[0] = srcImage1.getFileInfo()[0].getResolutions()[0];
    resols[1] = srcImage1.getFileInfo()[0].getResolutions()[1];
    resols[2] = 1;

    if ((srcImage1.getFileInfo()[0] instanceof FileInfoDicom)
        && (srcImage2.getFileInfo()[0] instanceof FileInfoDicom)) {
      fileInfoDicom = new FileInfoDicom[destImage.getExtents()[2]];
      fileInfoDicom[0] = (FileInfoDicom) (((FileInfoDicom) srcImage1.getFileInfo()[0]).clone());
      fileInfoDicom[1] = (FileInfoDicom) (((FileInfoDicom) srcImage2.getFileInfo()[0]).clone());
      destImage.setFileInfo(fileInfoDicom);
    } else {
      fileInfo = destImage.getFileInfo();

      for (i = 0; (i < destImage.getExtents()[2]) && !threadStopped; i++) {
        fileInfo[i].setModality(srcImage1.getFileInfo()[0].getModality());
        fileInfo[i].setFileDirectory(srcImage1.getFileInfo()[0].getFileDirectory());
        fileInfo[i].setEndianess(srcImage1.getFileInfo()[0].getEndianess());
        fileInfo[i].setUnitsOfMeasure(srcImage1.getFileInfo()[0].getUnitsOfMeasure());
        fileInfo[i].setResolutions(resols);
        fileInfo[i].setExtents(destImage.getExtents());
        fileInfo[i].setMax(destImage.getMax());
        fileInfo[i].setMin(destImage.getMin());
        fileInfo[i].setImageOrientation(srcImage1.getImageOrientation());
        fileInfo[i].setPixelPadValue(srcImage1.getFileInfo()[0].getPixelPadValue());
        fileInfo[i].setPhotometric(srcImage1.getFileInfo()[0].getPhotometric());
        fileInfo[i].setAxisOrientation(srcImage1.getAxisOrientation());
      }

      if (srcImage1.getFileInfo()[0] instanceof FileInfoImageXML) {

        if (((FileInfoImageXML) srcImage1.getFileInfo()[0]).getPSetHashtable() != null) {
          ((FileInfoImageXML) fileInfo[0])
              .setPSetHashtable(((FileInfoImageXML) srcImage1.getFileInfo()[0]).getPSetHashtable());
        }
      }

      if (srcImage2.getFileInfo()[0] instanceof FileInfoImageXML) {

        if (((FileInfoImageXML) srcImage2.getFileInfo()[0]).getPSetHashtable() != null) {
          ((FileInfoImageXML) fileInfo[1])
              .setPSetHashtable(((FileInfoImageXML) srcImage2.getFileInfo()[0]).getPSetHashtable());
        }
      }
    }

    if (threadStopped) {
      buffer = null;
      finalize();

      return;
    }

    setCompleted(true);

    fileInfo = null;
    fileInfoDicom = null;
  }