/**
   * 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());
  }
예제 #2
0
  /** Sets up the GUI (panels, buttons, etc) and displays it on the screen. */
  private void init() {
    if (image.getFileInfo(0).getFileFormat() == FileUtility.DICOM) {
      FileInfoDicom dicomInfo = (FileInfoDicom) image.getFileInfo(0);
      FileDicomTagTable tagTable = dicomInfo.getTagTable();
      if (tagTable.getValue("0018,1310") != null) {
        // Acquisition matrix
        FileDicomTag tag = tagTable.get(new FileDicomKey("0018,1310"));
        Object[] values = tag.getValueList();
        int valNumber = values.length;
        if ((valNumber == 4) && (values instanceof Short[])) {
          int frequencyRows = ((Short) values[0]).intValue();
          Preferences.debug("frequencyRows = " + frequencyRows + "\n");
          int frequencyColumns = ((Short) values[1]).intValue();
          Preferences.debug("frequencyColumns = " + frequencyColumns + "\n");
          int phaseRows = ((Short) values[2]).intValue();
          Preferences.debug("phaseRows = " + phaseRows + "\n");
          int phaseColumns = ((Short) values[3]).intValue();
          Preferences.debug("phaseColumns = " + phaseColumns + "\n");
          if ((frequencyRows > 0) && (phaseRows == 0)) {
            subYDim = frequencyRows;
          } else if ((frequencyRows == 0) && (phaseRows > 0)) {
            subYDim = phaseRows;
          }
          if ((frequencyColumns > 0) && (phaseColumns == 0)) {
            subXDim = frequencyColumns;
          } else if ((frequencyColumns == 0) && (phaseColumns > 0)) {
            subXDim = phaseColumns;
          }
        }
      } // if (tagTable.getValue("0018,1310") != null)
      if (tagTable.getValue("0019,100A") != null) {
        FileDicomTag tag = tagTable.get(new FileDicomKey("0019,100A"));
        Object value = tag.getValue(false);
        if (value instanceof Short) {
          numberOfImagesInMosaic = ((Short) value).intValue();
          Preferences.debug("Number of images in mosaic = " + numberOfImagesInMosaic + "\n");
        }
      } // if (tagTable.getValue("0019,100A") != null)
    } // if (image.getFileInfo(0).getFileFormat() == FileUtility.DICOM)*/
    setForeground(Color.black);
    setTitle("Mosaic To 3D Volume");

    JPanel inputPanel = new JPanel(new GridBagLayout());
    inputPanel.setForeground(Color.black);

    inputPanel.setBorder(buildTitledBorder("Image"));

    JLabel labelUse = new JLabel("Image:");
    labelUse.setForeground(Color.black);
    labelUse.setFont(serif12);

    JLabel labelImage = new JLabel(image.getImageName());
    labelImage.setForeground(Color.black);
    labelImage.setFont(serif12);

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.gridheight = 1;
    gbc.gridwidth = 1;
    gbc.anchor = GridBagConstraints.WEST;
    gbc.weightx = 1;
    gbc.insets = new Insets(5, 5, 5, 5);
    inputPanel.add(labelUse, gbc);
    gbc.gridx = 1;
    gbc.fill = GridBagConstraints.HORIZONTAL;
    inputPanel.add(labelImage, gbc);

    JPanel dimensionPanel = new JPanel(new GridBagLayout());
    dimensionPanel.setForeground(Color.black);
    dimensionPanel.setBorder(buildTitledBorder("X and Y Dimensions of Result"));

    JLabel labelXDim = new JLabel("X dimension of slices");
    labelXDim.setForeground(Color.black);
    labelXDim.setFont(serif12);

    textXDim = new JTextField(10);
    if (subXDim != 0) {
      textXDim.setText(String.valueOf(subXDim));
    }
    textXDim.setFont(serif12);
    textXDim.setForeground(Color.black);

    JLabel labelYDim = new JLabel("Y dimension of slices");
    labelYDim.setForeground(Color.black);
    labelYDim.setFont(serif12);

    textYDim = new JTextField(10);
    if (subYDim != 0) {
      textYDim.setText(String.valueOf(subYDim));
    }
    textYDim.setFont(serif12);
    textYDim.setForeground(Color.black);

    JLabel labelNumberImages = new JLabel("Number of images in mosaic");
    labelNumberImages.setForeground(Color.black);
    labelNumberImages.setFont(serif12);

    textNumberImages = new JTextField(10);
    if (numberOfImagesInMosaic != 0) {
      textNumberImages.setText(String.valueOf(numberOfImagesInMosaic));
    }
    textNumberImages.setFont(serif12);
    textNumberImages.setForeground(Color.black);

    gbc.gridx = 0;
    gbc.gridy = 0;
    dimensionPanel.add(labelXDim, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textXDim, gbc);
    gbc.gridx = 0;
    gbc.gridy = 1;
    dimensionPanel.add(labelYDim, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textYDim, gbc);
    gbc.gridx = 0;
    gbc.gridy = 2;
    dimensionPanel.add(labelNumberImages, gbc);
    gbc.gridx = 1;
    dimensionPanel.add(textNumberImages, gbc);

    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.add(inputPanel, BorderLayout.NORTH);
    mainPanel.add(dimensionPanel, BorderLayout.CENTER);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JPanel buttonPanel = new JPanel();
    buttonPanel.add(buildButtons());

    getContentPane().add(mainPanel);
    getContentPane().add(buttonPanel, BorderLayout.SOUTH);
    pack();
    setVisible(true);
  }