Class JDialogProstateSegmentationRegBSpline3D

java.lang.Object
java.awt.Component
java.awt.Container
java.awt.Window
java.awt.Dialog
javax.swing.JDialog
gov.nih.mipav.view.dialogs.JDialogBase
gov.nih.mipav.view.renderer.WildMagic.ProstateFramework.JDialogProstateSegmentationRegBSpline3D
All Implemented Interfaces:
AlgorithmInterface, DialogDefaultsInterface, ActionListener, FocusListener, ItemListener, WindowListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, RootPaneContainer, WindowConstants

public class JDialogProstateSegmentationRegBSpline3D extends JDialogBase implements AlgorithmInterface
Semi-automatic MR Prostate segmentation - Registration and Fuzzy-C guided segmentation model. The algorithm uses B-Spline registration and Fuzzy-C to guide the MR prostate segmentation. Basic steps: 1) User open the axial, sagittal, coronal images in the MIPAV frame. 2) User manually outline the three contours on separate slices for each axial, sagittal, and coronal images to define the middle, the apex and the base of the prostate. 3) User click the OK button to let a fully automatic registration guided algorithm to segment the prostate of all the three images.
Author:
Ruida Cheng
See Also:
  • Field Details

    • UI

      private ViewUserInterface UI
      global user interface to get the three active images.
    • tracingSliceNumber

      private int tracingSliceNumber
      number of slices to trace, start from the apex and base VOIs
    • Axial

      private static int Axial
      Axial image type
    • Sagittal

      private static int Sagittal
      Sagittal image type
    • Coronal

      private static int Coronal
      Coronal image type
    • labelAxis

      private JLabel labelAxis
    • labelStartVOIAxial

      private JLabel labelStartVOIAxial
    • textFieldStartVOIAxial

      private JTextField textFieldStartVOIAxial
    • labelEndVOIAxial

      private JLabel labelEndVOIAxial
    • textFieldEndVOIAxial

      private JTextField textFieldEndVOIAxial
    • labelMidVOIAxial

      private JLabel labelMidVOIAxial
    • textFieldMidVOIAxial

      private JTextField textFieldMidVOIAxial
    • startVOIAxial

      int startVOIAxial
    • endVOIAxial

      int endVOIAxial
    • midVOIAxial

      int midVOIAxial
    • labelSagittal

      private JLabel labelSagittal
    • labelStartVOISagittal

      private JLabel labelStartVOISagittal
    • textFieldStartVOISagittal

      private JTextField textFieldStartVOISagittal
    • labelEndVOISagittal

      private JLabel labelEndVOISagittal
    • textFieldEndVOISagittal

      private JTextField textFieldEndVOISagittal
    • labelMidVOISagittal

      private JLabel labelMidVOISagittal
    • textFieldMidVOISagittal

      private JTextField textFieldMidVOISagittal
    • startVOISagittal

      int startVOISagittal
    • endVOISagittal

      int endVOISagittal
    • midVOISagittal

      int midVOISagittal
    • labelCoronal

      private JLabel labelCoronal
    • labelStartVOICoronal

      private JLabel labelStartVOICoronal
    • textFieldStartVOICoronal

      private JTextField textFieldStartVOICoronal
    • labelEndVOICoronal

      private JLabel labelEndVOICoronal
    • textFieldEndVOICoronal

      private JTextField textFieldEndVOICoronal
    • labelMidVOICoronal

      private JLabel labelMidVOICoronal
    • textFieldMidVOICoronal

      private JTextField textFieldMidVOICoronal
    • radioBSpline

      private JRadioButton radioBSpline
    • radioOAR

      private JRadioButton radioOAR
    • startVOICoronal

      private int startVOICoronal
    • endVOICoronal

      private int endVOICoronal
    • midVOICoronal

      private int midVOICoronal
    • imageAxial

      private ModelImage imageAxial
    • imageSagittal

      private ModelImage imageSagittal
    • imageCoronal

      private ModelImage imageCoronal
    • useBSpline

      private boolean useBSpline
      Flag to indicate to use B-Spline registration or OAR registration
  • Constructor Details

    • JDialogProstateSegmentationRegBSpline3D

      public JDialogProstateSegmentationRegBSpline3D(Frame theParentFrame)
      GUI interface for semi-automatic MR prostate segmentation.
      Parameters:
      theParentFrame - the MIPAV main frame.
  • Method Details

    • autoConfigVOIsNumbers

      public void autoConfigVOIsNumbers()
      After user manually draw the three VOIs on each axial, sagittal, coronal image, the drawn VOIs slices number is auto configured to appear in the dialog GUI interface.
    • configVOIsNumbers

      public void configVOIsNumbers(ModelImage image, int[] slices)
      Configure the mid, apex and base VOIs, sort them in order.
      Parameters:
      image - oringial MRI image
      slices - Slice array to store the mid, apex and base VOIs slice number.
    • actionPerformed

      public void actionPerformed(ActionEvent event)
      Just handle GUI button clicks event.
      Specified by:
      actionPerformed in interface ActionListener
      Overrides:
      actionPerformed in class JDialogBase
    • calculateVOIsVolume

      public void calculateVOIsVolume()
      Compute the VOIs binary mask based volumes.
    • printVolume

      public void printVolume(ModelImage srcImage, VOIVector voiVector, int viewOrientation)
      Print out the three VOIs volume in system console out.
      Parameters:
      srcImage - original MRI image
      voiVector - segmented resulting VOIs contours
      viewOrientation - view axis orientation: axial, or sagittal or coronal.
    • removeContourFromOtherOrientation

      public void removeContourFromOtherOrientation()
      User central gland contours projection to remove the extra interpolated VOIs contours at the apex and base. Parallel processing the algorithm with axial, sagittal and coronal images concurrently.
    • trimVOIsInSingleImage

      public Runnable trimVOIsInSingleImage(ModelImage image, int startVOI, int endVOI, Vector<WildMagic.LibFoundation.Mathematics.Vector3f> firstVOI, Vector<WildMagic.LibFoundation.Mathematics.Vector3f> secondVOI, int viewOrientation)
      In Dicom space, central contours projections to eliminate the extra contours at the apex and base. For example, axial image, project the sagittal, coronal VOIs onto the axial image Dicom space. The central gland part sagittal, coronal VOIs contours is projected on the axial image slices as points based contours. If there is no points on the corresponding axial image slice, however it has contour, the contour is eliminated.
      Parameters:
      image - original MRI image. i.e. axial image
      startVOI - apex VOI slice number
      endVOI - base VOI slice number
      firstVOI - sagittal image VOIs in Dicom space
      secondVOI - coronal image VOIs in Dicom space.
      viewOrientation - image axis orientation
      Returns:
    • removeVOIsInDicomSpace

      public void removeVOIsInDicomSpace(int zSlice, float zDicom, ModelImage image, Vector<WildMagic.LibFoundation.Mathematics.Vector3f> firstVOI, Vector<WildMagic.LibFoundation.Mathematics.Vector3f> secondVOI, int viewOrientation)
      Remove the extra VOIs contours in Dicom space.
      Parameters:
      zSlice - axial z slice number
      zDicom - z slice number corresponding Dicom value
      image - original MRI image
      firstVOI - sagittal VOI
      secondVOI - coronal VOI
      viewOrientation - view axis
    • convertVOIToDicomSpace

      public void convertVOIToDicomSpace(VOIVector src, Vector<WildMagic.LibFoundation.Mathematics.Vector3f> target, ModelImage image, int startSlice, int endSlice)
      Conver the VOIs from image space to Dicom space
      Parameters:
      src - source VOIs
      target - converted target VOIs
      image - original MRI image
      startSlice - starting slice
      endSlice - ending slice
    • createTask

      private Runnable createTask(ModelImage image, int midVOI, int startVOI, int endVOI, int axis)
      Parallel processing the automatic segmentation algorithm to all the three images concurrently.
      Parameters:
      image - original MRI image
      midVOI - mid slice VOI
      startVOI - apex slice VOI
      endVOI - base slice VOI
      axis - view axis
      Returns:
    • algorithmPerformed

      public void algorithmPerformed(AlgorithmBase algorithm)
      This method is required if the AlgorithmPerformed interface is implemented. It is called by the algorithms when it has completed or failed to to complete, so that the dialog can be display the result image and/or clean up.
      Specified by:
      algorithmPerformed in interface AlgorithmInterface
      Parameters:
      algorithm - Algorithm that caused the event.
    • pause

      public static void pause()
      Pauses the display until the user hits enter.
    • calculateCoherenceEnhancingDiffusion

      private ModelImage calculateCoherenceEnhancingDiffusion(ModelImage cropImage)
      Apply the coherence enhancing diffusion filter to the croppred MR image.
      Parameters:
      cropImage - cropped image
      Returns:
      the coherence enhancing diffusion image.
    • isVOIsCloseEnough

      private boolean isVOIsCloseEnough(int currentSlice, ModelImage resultImage, ModelImage refImage)
      Check the registration accuracy. Check to see if the registration runs into errors. Check criterion include VOI area, VOI center, etc. If area and center difference exceed specified threshold, registration runs into error.
      Parameters:
      currentSlice - current image slice
      resultImage - result image after registration
      refImage - registration reference slice
      Returns:
      true registration wrong, false, registration wrong.
    • segmentFromFuzzyC

      public void segmentFromFuzzyC(Vector<Vector<ModelImage>> imageStackFuzzyC, int currentSlice, ModelImage resultImage, ModelImage refImage, ModelImage testImage, int axis)
      Apply the Fuzzy-C means segmentation to CED image stack.
      Parameters:
      imageStackFuzzyC - Fuzzy-C segmentation result stack packed from each image slice. It contains 5 fuzzy-C member function classes.
      currentSlice - current slice number
      resultImage - result image
      refImage - reference image
      testImage - test image
      axis - axis orientation.
    • createVOIPointTable

      private void createVOIPointTable(JDialogProstateSegmentationRegBSpline3D.Edge voiTable, ModelImage resultImage)
      Create the VOI table in polar coodinate system. It will be used in the narrow band finding.
      Parameters:
      voiTable - result VOI points table.
      resultImage - result image after registration.
    • createImagePointTable

      public void createImagePointTable(JDialogProstateSegmentationRegBSpline3D.Edge imageTable, ModelImage resultImage)
      Convert each image pixel to polar coordinate system, saved them in a table.
      Parameters:
      imageTable - image table.
      resultImage - result image after registration.
    • findNarrowBand

      Find the narrow band regions around VOI contours.
      Parameters:
      voiTable - VOI table
      imageTable - image table
      narrowBandTable - narrow band region table.
    • drawNarrowBand

      public void drawNarrowBand(JDialogProstateSegmentationRegBSpline3D.Edge narrowBandTable, ModelImage resultImage)
      Draw the narrow band region. It is used for testing purpose.
      Parameters:
      narrowBandTable - narrow band region table.
      resultImage - result image after registration.
    • findRegion

      public void findRegion(JDialogProstateSegmentationRegBSpline3D.Edge imageTable, float theta1, float theta2, Vector<JDialogProstateSegmentationRegBSpline3D.PolarPoint> voiPointsInRange, JDialogProstateSegmentationRegBSpline3D.Edge narrowBandTable)
      Looking for the narrow band region.
      Parameters:
      imageTable - image table
      theta1 - upper limit
      theta2 - lower limit
      voiPointsInRange - Vois point table
      narrowBandTable - narrow band table.
    • inRange

      public boolean inRange(JDialogProstateSegmentationRegBSpline3D.Edge narrowBandTable, int x, int y)
      Check whether the given x, y pixel fall withing the narrow band region.
      Parameters:
      narrowBandTable - narrow band table
      x - pixel x coordinate
      y - pixel y coordinate
      Returns:
      in the range or not.
    • findVOIpointsInRange

      public void findVOIpointsInRange(JDialogProstateSegmentationRegBSpline3D.Edge imageTable, Vector<JDialogProstateSegmentationRegBSpline3D.PolarPoint> voiPointsInRange, int min, int max, JDialogProstateSegmentationRegBSpline3D.Edge voiTable)
      Tracing generated VOI tables, convert it from image coordinate to Polar coordinate.
      Parameters:
      imageTable - image table
      voiPointsInRange - VOI table in polar coordinate
      min - narrow band lower limit
      max - narrow band upper limit
      voiTable - voi table in image coordinate
    • morphologyPostProcessing

      public void morphologyPostProcessing(ModelImage maskImage, ModelImage resultImage, ModelImage testImage)
      Apply the morphology filter the generate binary mask image from Fuzz-C segmentation.
      Parameters:
      maskImage - generated binary mask image
      resultImage - resulting image
      testImage - intermediate image.
    • maskVOIFill

      public void maskVOIFill(ModelImage maskImage)
      Fill pixels inside VOI. Currently not being used. For testing purpose.
      Parameters:
      maskImage -
    • smoothVOI50

      public void smoothVOI50(ModelImage maskImage, ModelImage resultImage)
      Convert the mask image to VOI with 50 points
      Parameters:
      maskImage - binary mask image
      resultImage - result image
    • smoothVOI120

      public void smoothVOI120(ModelImage maskImage, ModelImage resultImage)
      Convert the mask image to VOI with 120 points.
      Parameters:
      maskImage - binary mask image
      resultImage - result image
    • maskToVOI

      public void maskToVOI(ModelImage maskImage, ModelImage testImage)
      Convert mask image to VOI
      Parameters:
      maskImage - binary mask image
      testImage - intermediate image.
    • IDobjects

      public void IDobjects(ModelImage maskImage)
      Eliminate the small binary mask components. Pixel numbers threshold based elimination.
      Parameters:
      maskImage -
    • particleSystem

      public void particleSystem(ModelImage maskImage)
      Particle system analysis.
      Parameters:
      maskImage - binary mask image
    • fillholes

      public void fillholes(ModelImage maskImage)
      Fill holes inside the binary mask image.
      Parameters:
      maskImage - binary mask image.
    • threshold

      public void threshold(ModelImage maskImage)
      Convert the mask image specified theshold values.
      Parameters:
      maskImage - binary mask image
    • isInsideVOI

      public boolean isInsideVOI(int pos, ModelImage img)
      check if given pixl location is inside VOI or not.
      Parameters:
      pos - pixl location
      img - given image
      Returns:
    • transformVOI

      public void transformVOI(ModelImage image, ModelImage resultImage, int[] boundingBox, int currentSlice)
      Transform the the resulting VOI from cropped image to oringal MR image.
      Parameters:
      image - original MR image
      resultImage - resulting image after segmentation
      boundingBox - cropped image bounding box
      currentSlice - current image slice
    • callAlgorithm

      public void callAlgorithm(ModelImage image, int midVOI, int startVOI, int endVOI, int axis)
      Single thread based segmentation, which takes up to 40 minutes. The currrent concurrent based segmentaion takes from 7 minutes to 10 minutes. The function is not called.
      Parameters:
      image -
      midVOI -
      startVOI -
      endVOI -
      axis -
    • sortImageVOIs

      public void sortImageVOIs(ModelImage image)
      Sorting image VOI
      Parameters:
      image - original MR image
    • sortImageVOIsInit

      public void sortImageVOIsInit(ModelImage image, int midVOI, int startVOI, int endVOI)
      Sort the original MR image's specified VOIs
      Parameters:
      image - original MR image
      midVOI - mid slice VOI
      startVOI - apex slice VOI
      endVOI - base slice VOI
    • sortCEDImageVOIs

      public void sortCEDImageVOIs(ModelImage coherenceEnhancingDiffusionImage, int midVOI, int startVOI, int endVOI)
      Sort the CED image VOIs
      Parameters:
      coherenceEnhancingDiffusionImage - CED image
      midVOI - mid slice VOI
      startVOI - apex slice VOI
      endVOI - base slice VOI
    • doFuzzyCmean

      public void doFuzzyCmean(ModelImage coherenceEnhancingDiffusionImage, Vector<Vector<ModelImage>> imageStackFuzzyC)
      Generate the Fuzzy-C means classes from the CED image
      Parameters:
      coherenceEnhancingDiffusionImage - CED image
      imageStackFuzzyC - Fuzzy-C means classes image stack.
    • getCentroids

      private float[] getCentroids(ModelImage srcImage, AlgorithmFuzzyCMeans fcmAlgo, float[] centroids)
      Gets the minimum and maximum of each image and initializes the centroids dialog appropriately.
      Returns:
      Flag indicating a successful get.
    • doRegistrationMid

      public void doRegistrationMid(ModelImage image, ModelImage coherenceEnhancingDiffusionImage, Vector<Vector<ModelImage>> imageStackFuzzyC, int midVOI, int startVOI, int endVOI, int[] boundingBox, int axis)
      The proposed model uses 2D registration to register 2D slices from the middle slice to the adjacent slice. It then generates a new VOI, and takes the VOI as the new initial estimate for the next slice in the series. This process is then iteratively propagated in both forward and backward directions.
      Parameters:
      image - original MR image
      coherenceEnhancingDiffusionImage - coherence enhance diffusion filter
      imageStackFuzzyC - Fuzzy-C segmentation stack
      midVOI - mid slice VOI
      startVOI - apex slice VOI
      endVOI - base slice VOI
      boundingBox - Cropped image bounding box
      axis - axis orientation
    • doRegistrationStart

      public void doRegistrationStart(ModelImage image, ModelImage coherenceEnhancingDiffusionImage, Vector<Vector<ModelImage>> imageStackFuzzyC, int startVOI, int[] boundingBox, int axis)
      Near the apex, apex contour starts as the initial estimate, and repeat the same process toward the end slices.
      Parameters:
      image - original MR image
      coherenceEnhancingDiffusionImage - coherence enhance diffusion filter
      imageStackFuzzyC - Fuzzy-C segmentation stack
      startVOI - apex starting slice VOI number
      boundingBox - Cropped image bounding box
      axis - axis orientation
    • doRegistrationEnd

      public void doRegistrationEnd(ModelImage image, ModelImage coherenceEnhancingDiffusionImage, Vector<Vector<ModelImage>> imageStackFuzzyC, int endVOI, int[] boundingBox, int axis)
      Near the base, base contour starts as the initial estimate, and repeat the same process toward the end slices.
      Parameters:
      image - original MR image
      coherenceEnhancingDiffusionImage - coherence enhance diffusion filter
      imageStackFuzzyC - Fuzzy-C segmentation stack
      boundingBox - Cropped image bounding box
      axis - axis orientation
      startVOI - apex starting slice VOI number
    • adjustVOIs

      public void adjustVOIs(ModelImage image)
      When user draws the 3 VOIs out of order, adjust the VOIs in ascending order
      Parameters:
      image - source image, axial, sagittal or coronal
    • cropROI

      public ModelImage cropROI(ModelImage image, int[] xBounds, int[] yBounds, int[] zBounds, int[] boundingBox, int midVOI)
      Crop MR image with specified X, Y, Z bounds Use the mid slice as the initial guidance to find the bounds.
      Parameters:
      image - Original MR image
      xBounds - X bounds
      yBounds - Y bounds
      zBounds - Z bounds
      boundingBox - Cropped region rounding box
      midVOI - mid slice VOI
      Returns:
    • init

      public void init()
      Create the dialog interface.