/**
   * Once all the necessary variables are set, call the Nonlocal Means filter algorithm based on
   * what type of image this is and whether or not there is a separate destination image.
   */
  protected void callAlgorithm() {
    String name = makeImageName(image.getImageName(), "_NonlocalMeans");
    int[] destExtents;

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

    if (displayLoc == NEW) {

      try {

        // Make result image of float type
        if (image.isColorImage()) {
          resultImage = new ModelImage(ModelImage.ARGB, destExtents, name);
        } else {
          resultImage = new ModelImage(ModelImage.FLOAT, destExtents, name);
        }

        // resultImage = (ModelImage)image.clone();
        // resultImage.setImageName(name);
        // Make algorithm
        nlMeansFilterAlgo =
            new AlgorithmNonlocalMeansFilter(
                resultImage,
                image,
                searchWindowSide,
                similarityWindowSide,
                noiseStandardDeviation,
                degreeOfFiltering,
                doRician,
                image25D);

        // This is very important. Adding this object as a listener allows the algorithm to
        // notify this object when it has completed of failed. See algorithm performed event.
        // This is made possible by implementing AlgorithmedPerformed interface
        nlMeansFilterAlgo.addListener(this);
        createProgressBar(image.getImageName(), nlMeansFilterAlgo);

        // Hide dialog
        setVisible(false);

        if (isRunInSeparateThread()) {

          // Start the thread as a low priority because we wish to still have user interface work
          // fast
          if (nlMeansFilterAlgo.startMethod(Thread.MIN_PRIORITY) == false) {
            MipavUtil.displayError("A thread is already running on this object");
          }
        } else {
          nlMeansFilterAlgo.run();
        }
      } catch (OutOfMemoryError x) {
        MipavUtil.displayError("Dialog Nonlocal Means Filter: unable to allocate enough memory");

        if (resultImage != null) {
          resultImage.disposeLocal(); // Clean up memory of result image
          resultImage = null;
        }

        return;
      }
    } else {

      try {

        // No need to make new image space because the user has choosen to replace the source image
        // Make the algorithm class
        nlMeansFilterAlgo =
            new AlgorithmNonlocalMeansFilter(
                null,
                image,
                searchWindowSide,
                similarityWindowSide,
                noiseStandardDeviation,
                degreeOfFiltering,
                doRician,
                image25D);

        // This is very important. Adding this object as a listener allows the algorithm to
        // notify this object when it has completed of failed. See algorithm performed event.
        // This is made possible by implementing AlgorithmedPerformed interface
        nlMeansFilterAlgo.addListener(this);
        createProgressBar(image.getImageName(), nlMeansFilterAlgo);

        // Hide the dialog since the algorithm is about to run.
        setVisible(false);

        // These next lines set the titles in all frames where the source image is displayed to
        // "locked - " image name so as to indicate that the image is now read/write locked!
        // The image frames are disabled and then unregisted from the userinterface until the
        // algorithm has completed.
        Vector<ViewImageUpdateInterface> imageFrames = image.getImageFrameVector();
        titles = new String[imageFrames.size()];

        for (int i = 0; i < imageFrames.size(); i++) {
          titles[i] = ((Frame) (imageFrames.elementAt(i))).getTitle();
          ((Frame) (imageFrames.elementAt(i))).setTitle("Locked: " + titles[i]);
          ((Frame) (imageFrames.elementAt(i))).setEnabled(false);
          userInterface.unregisterFrame((Frame) (imageFrames.elementAt(i)));
        }

        if (isRunInSeparateThread()) {

          // Start the thread as a low priority because we wish to still have user interface work
          // fast
          if (nlMeansFilterAlgo.startMethod(Thread.MIN_PRIORITY) == false) {
            MipavUtil.displayError("A thread is already running on this object");
          }
        } else {
          nlMeansFilterAlgo.run();
        }
      } catch (OutOfMemoryError x) {
        MipavUtil.displayError("Dialog Nonlocal Means Filter: unable to allocate enough memory");

        return;
      }
    }
  }
  /**
   * Once all the necessary variables are set, call the Concat algorithm based on what type of image
   * this is and whether or not there is a separate destination image.
   */
  protected void callAlgorithm() {
    int destExtents[] = new int[3];
    ModelImage destImage = null;

    destExtents[0] = subXDim;
    destExtents[1] = subYDim;
    destExtents[2] = numberOfImagesInMosaic;

    destImage =
        new ModelImage(
            image.getType(), destExtents, makeImageName(image.getImageName(), "_mosaic_to_slices"));

    try {

      // Make algorithm
      mathAlgo = new AlgorithmMosaicToSlices(image, destImage);

      // This is very important. Adding this object as a listener allows the algorithm to
      // notify this object when it has completed of failed. See algorithm performed event.
      // This is made possible by implementing AlgorithmedPerformed interface
      mathAlgo.addListener(this);

      createProgressBar(image.getImageName(), mathAlgo);

      // Hide dialog
      setVisible(false);

      if (displayLoc == REPLACE) {

        // These next lines set the titles in all frames where the source image is displayed to
        // "locked - " image name so as to indicate that the image is now read/write locked!
        // The image frames are disabled and then unregisted from the userinterface until the
        // algorithm has completed.
        Vector<ViewImageUpdateInterface> imageFrames = image.getImageFrameVector();
        titles = new String[imageFrames.size()];

        for (int i = 0; i < imageFrames.size(); i++) {
          titles[i] = ((Frame) (imageFrames.elementAt(i))).getTitle();
          ((Frame) (imageFrames.elementAt(i))).setTitle("Locked: " + titles[i]);
          ((Frame) (imageFrames.elementAt(i))).setEnabled(false);
          userInterface.unregisterFrame((Frame) (imageFrames.elementAt(i)));
        }
      }

      if (isRunInSeparateThread()) {

        // Start the thread as a low priority because we wish to still have user interface work
        // fast.
        if (mathAlgo.startMethod(Thread.MIN_PRIORITY) == false) {
          MipavUtil.displayError("A thread is already running on this object");
        }

      } else {

        mathAlgo.run();
      }
    } catch (OutOfMemoryError x) {
      System.gc();
      MipavUtil.displayError("Dialog Concatenation: unable to allocate enough memory");

      return;
    }
  }