/** * 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. * * @param algorithm Algorithm that caused the event. */ public void algorithmPerformed(AlgorithmBase algorithm) { if (algorithm instanceof AlgorithmNonlocalMeansFilter) { image.clearMask(); if ((nlMeansFilterAlgo.isCompleted() == true) && (resultImage != null)) { updateFileInfo(image, resultImage); resultImage.clearMask(); // The algorithm has completed and produced a new image to be displayed. try { new ViewJFrameImage(resultImage, null, new Dimension(610, 200)); } catch (OutOfMemoryError error) { MipavUtil.displayError("Out of memory: unable to open new frame"); } } else if (resultImage == null) { // These next lines set the titles in all frames where the source image is displayed to // image name so as to indicate that the image is now unlocked! // The image frames are enabled and then registed to the userinterface. Vector<ViewImageUpdateInterface> imageFrames = image.getImageFrameVector(); for (int i = 0; i < imageFrames.size(); i++) { ((Frame) (imageFrames.elementAt(i))).setTitle(titles[i]); ((Frame) (imageFrames.elementAt(i))).setEnabled(true); if (((Frame) (imageFrames.elementAt(i))) != parentFrame) { userInterface.registerFrame((Frame) (imageFrames.elementAt(i))); } } if (parentFrame != null) { userInterface.registerFrame(parentFrame); } image.notifyImageDisplayListeners(null, true); } else if (resultImage != null) { // algorithm failed but result image still has garbage resultImage.disposeLocal(); // clean up memory resultImage = null; } } if (algorithm.isCompleted()) { insertScriptLine(); } // save the completion status for later setComplete(algorithm.isCompleted()); nlMeansFilterAlgo.finalize(); nlMeansFilterAlgo = null; dispose(); }
/** Construct the panel's GUI. */ private void initGUI() { PanelManager mainPanelManager = new PanelManager(this); PanelManager destPanelManager = new PanelManager("Destination"); PanelManager regionPanelManager = new PanelManager("Process"); ButtonGroup destinationGroup = new ButtonGroup(); ButtonGroup imageVOIGroup = new ButtonGroup(); newImageRadio = WidgetFactory.buildRadioButton("New image", true, destinationGroup); destPanelManager.add(newImageRadio); replaceImageRadio = WidgetFactory.buildRadioButton("Replace image", false, destinationGroup); destPanelManager.addOnNextLine(replaceImageRadio); // Only if the image is unlocked can it be replaced. if (srcImage.getLockStatus() == ModelStorageBase.UNLOCKED) { replaceImageRadio.setEnabled(true); if (ViewUserInterface.getReference().doForceInPlace()) { replaceImageRadio.setSelected(true); newImageRadio.setEnabled(false); } } else { replaceImageRadio.setEnabled(false); } wholeImageRadio = WidgetFactory.buildRadioButton("Whole image", true, imageVOIGroup); regionPanelManager.add(wholeImageRadio); voiRegionsRadio = WidgetFactory.buildRadioButton("VOI region(s)", false, imageVOIGroup); regionPanelManager.addOnNextLine(voiRegionsRadio); mainPanelManager.add(destPanelManager.getPanel()); mainPanelManager.add(regionPanelManager.getPanel()); }
/** 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; } }
/** dispose memory. */ public void disposeLocal() { if (mathAlgo != null) { mathAlgo.finalize(); mathAlgo = null; } if (image != null) { image.disposeLocal(); } image = null; if (resultImage != null) { resultImage.disposeLocal(); } resultImage = null; }
/** {@inheritDoc} */ protected void setGUIFromParams() { image = scriptParameters.retrieveInputImage(); parentFrame = image.getParentFrame(); if (!image.isColorImage()) { throw new ParameterException( AlgorithmParameters.getInputImageLabel(1), "Source Image must be Color"); } setBlueMin(scriptParameters.getParams().getInt("blue_min")); setRedMin(scriptParameters.getParams().getInt("red_min")); setRedFraction(scriptParameters.getParams().getFloat("red_fraction")); setMergingDistance(scriptParameters.getParams().getFloat("merging_distance")); setGreenMin(scriptParameters.getParams().getInt("green_min")); setGreenFraction(scriptParameters.getParams().getFloat("green_fraction")); setGreenRegionNumber(scriptParameters.getParams().getInt("green_region_number")); setTwoGreenLevels(scriptParameters.getParams().getBoolean("two_green_levels")); setBlueBoundaryFraction(scriptParameters.getParams().getFloat("blue_boundary_fraction")); setBlueSmooth(scriptParameters.getParams().getBoolean("blue_smooth")); setInterpolationDivisor(scriptParameters.getParams().getFloat("interpolation_divisor")); }
/** * Display string pass into the method. If the string is null no message is displayed. The * completed flag is set to <code>false</code> and the progress bar is disposed; * * @param strErr the string that is to be displayed. If the string is null no message is * displayed. * @param gcFlag if <code>true</code> call the garbage collector. */ public void errorCleanUp(String strErr, boolean gcFlag) { if (gcFlag == true) { System.gc(); } if (strErr != null) { displayError(strErr); } setCompleted(false); setThreadStopped(true); if (destImage != null) { destImage.releaseLock(); } if (srcImage != null) { srcImage.releaseLock(); } }
/** * Creates new dialog for distances within a cell from the geometric center using a plugin. * * @param theParentFrame Parent frame. * @param im Source image. */ public PlugInDialogCenterDistance2(Frame theParentFrame, ModelImage im) { super(theParentFrame, false); if (!im.isColorImage()) { MipavUtil.displayError("Source Image must be Color"); dispose(); return; } image = im; init(); }
/** * 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. * * @param algorithm Algorithm that caused the event. */ public void algorithmPerformed(AlgorithmBase algorithm) { imageA.clearMask(); if (algorithm instanceof PlugInAlgorithmISN) { if (isnAlgo.isCompleted() == true) { // The algorithm has completed and produced a new image to be displayed. updateFileInfo(imageA, resultImage); new ViewJFrameImage(resultImage, (ModelLUT) null); } } }
/** Calls the algorithm. */ protected void callAlgorithm() { try { resultImage = new ModelImage(imageA.getType(), imageA.getExtents(), (imageA.getImageName() + "_isn")); resultImage.copyFileTypeInfo(imageA); // Make algorithm isnAlgo = new PlugInAlgorithmISN(resultImage, imageA); // 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 isnAlgo.addListener(this); createProgressBar(imageA.getImageName(), " ...", isnAlgo); // Hide dialog setVisible(false); if (isRunInSeparateThread()) { // Start the thread as a low priority because we wish to still have user interface work // fast. if (isnAlgo.startMethod(Thread.MIN_PRIORITY) == false) { MipavUtil.displayError("A thread is already running on this object"); } } else { isnAlgo.run(); } } catch (OutOfMemoryError x) { System.gc(); MipavUtil.displayError("AlgorithmAbsoluteValue: unable to allocate enough memory"); return; } }
/** * Once all the necessary variables are set, call the Gaussian Blur algorithm based on what type * of image this is and whether or not there is a separate destination image. */ protected void callAlgorithm() { try { centerDistanceAlgo = new PlugInAlgorithmCenterDistance2( image, blueMin, redMin, redFraction, mergingDistance, greenMin, greenFraction, greenRegionNumber, twoGreenLevels, blueBoundaryFraction, blueSmooth, interpolationDivisor); // This is very important. Adding this object as a listener allows // the algorithm to // notify this object when it has completed or failed. See algorithm // performed event. // This is made possible by implementing AlgorithmedPerformed // interface centerDistanceAlgo.addListener(this); createProgressBar(image.getImageName(), " ...", centerDistanceAlgo); setVisible(false); // Hide dialog if (isRunInSeparateThread()) { // Start the thread as a low priority because we wish to still // have user interface work fast. if (centerDistanceAlgo.startMethod(Thread.MIN_PRIORITY) == false) { MipavUtil.displayError("A thread is already running on this object"); } } else { centerDistanceAlgo.run(); } } catch (OutOfMemoryError x) { MipavUtil.displayError("Center Distance: unable to allocate enough memory"); return; } } // end callAlgorithm()
/** * Returns the name of an image output by this algorithm, the image returned depends on the * parameter label given (which can be used to retrieve the image object from the image registry). * * @param imageParamName The output image parameter label for which to get the image name. * @return The image name of the requested output image parameter label. */ public String getOutputImageName(final String imageParamName) { if (imageParamName.equals(AlgorithmParameters.RESULT_IMAGE)) { if (getResultImage() != null) { // algo produced a new result image return getResultImage().getImageName(); } else { // algo was done in place return image.getImageName(); } } Preferences.debug( "Unrecognized output image parameter: " + imageParamName + "\n", Preferences.DEBUG_SCRIPTING); return null; }
/** * This method is required if the AlgorithmPerformed interface is implemented. It is called by the * algorithm when it has completed or failed to to complete, so that the dialog can be display the * result image and/or clean up. * * @param algorithm Algorithm that caused the event. */ public void algorithmPerformed(AlgorithmBase algorithm) { if (algorithm instanceof PlugInAlgorithmCenterDistance2) { image.clearMask(); if (algorithm.isCompleted()) { insertScriptLine(); } if (algorithm != null) { algorithm.finalize(); algorithm = null; } dispose(); } } // end AlgorithmPerformed()
/** {@inheritDoc} */ protected void setGUIFromParams() { image = scriptParameters.retrieveInputImage(); userInterface = ViewUserInterface.getReference(); parentFrame = image.getParentFrame(); if (scriptParameters.doOutputNewImage()) { setDisplayLocNew(); } else { setDisplayLocReplace(); } searchWindowSide = scriptParameters.getParams().getInt("search_window_side"); similarityWindowSide = scriptParameters.getParams().getInt("similarity_window_side"); noiseStandardDeviation = scriptParameters.getParams().getFloat("noise_standard_deviation"); degreeOfFiltering = scriptParameters.getParams().getFloat("degree_of_filtering"); doRician = scriptParameters.getParams().getBoolean("do_rician"); image25D = scriptParameters.doProcess3DAs25D(); }
/** {@inheritDoc} */ protected void setGUIFromParams() { image = scriptParameters.retrieveInputImage(1); userInterface = ViewUserInterface.getReference(); parentFrame = image.getParentFrame(); if (scriptParameters.doOutputNewImage()) { setDisplayLocNew(); } else { // replace processing not supported.. // setDisplayLocReplace(); setDisplayLocNew(); } subXDim = scriptParameters.getParams().getInt("sub_x_dim"); subYDim = scriptParameters.getParams().getInt("sub_y_dim"); numberOfImagesInMosaic = scriptParameters.getParams().getInt("number_of_images_in_mosaic"); }
/** * 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; } }
/** * 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; } } }
/** * 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; }
/** * 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); }
/** * Working ... This function is never used. It doesn't modify any parameters or data members and * returns void. * * @param image DOCUMENT ME! * @param doColor DOCUMENT ME! */ public void calculatePrincipleAxis(ModelImage image, boolean doColor) { int x, y, z; int n = 0; Matrix3f mat2 = new Matrix3f(); // Row,Col Matrix3f meanProduct = new Matrix3f(); Vector3f mean = new Vector3f(); // Column vector double voxVal = 0; double total = 0; double tot = 0; // Moments first and second order double mX = 0, mY = 0, mZ = 0, mXX = 0, mXY = 0, mXZ = 0, mYY = 0, mYZ = 0, mZZ = 0; float min = (float) image.getMin(); int xEnd = image.getExtents()[0]; int yEnd = image.getExtents()[1]; int zEnd = image.getExtents()[2]; int nLim = (int) Math.sqrt((double) xEnd * yEnd * zEnd); if (nLim < 1000) { nLim = 1000; } for (z = 0; z < zEnd; z++) { for (y = 0; y < yEnd; y++) { for (x = 0; x < xEnd; x++) { if (doColor) { voxVal = (double) (image.getFloatC(x, y, z, 1) + image.getFloatC(x, y, z, 2) + image.getFloatC(x, y, z, 3)); } else { voxVal = (double) (image.getFloat(x, y, z) - min); } mX += voxVal * x; mY += voxVal * y; mZ += voxVal * z; mXX += voxVal * x * x; mXY += voxVal * x * y; mXZ += voxVal * x * z; mYY += voxVal * y * y; mYZ += voxVal * y * z; mZZ += voxVal * z * z; tot += voxVal; n++; if (n > nLim) { // Lets not over run the buffers during summation n = 0; total += tot; mat2.M00 = (float) (mat2.M00 + mXX); mat2.M01 = (float) (mat2.M01 + mXY); mat2.M02 = (float) (mat2.M02 + mXZ); mat2.M11 = (float) (mat2.M11 + mYY); mat2.M12 = (float) (mat2.M12 + mYZ); mat2.M22 = (float) (mat2.M22 + mZZ); mean.X = (float) (mean.X + mX); mean.Y = (float) (mean.Y + mY); mean.Z = (float) (mean.Z + mZ); tot = 0; mX = 0; mY = 0; mZ = 0; mXX = 0; mXY = 0; mXZ = 0; mYY = 0; mYZ = 0; mZZ = 0; } } } } total += tot; if (Math.abs(total) < 1e-5) { total = 1.0f; } mat2.M00 = (float) ((mat2.M00 + mXX) / total); mat2.M01 = (float) ((mat2.M01 + mXY) / total); mat2.M02 = (float) ((mat2.M02 + mXZ) / total); mat2.M11 = (float) ((mat2.M11 + mYY) / total); mat2.M12 = (float) ((mat2.M12 + mYZ) / total); mat2.M22 = (float) ((mat2.M22 + mZZ) / total); mean.X = (float) ((mean.X + mX) / total); mean.Y = (float) ((mean.Y + mY) / total); mean.Z = (float) ((mean.Z + mZ) / total); // Now make it central (taking off the Center of Mass) meanProduct.MakeTensorProduct(mean, mean); mat2.M00 -= meanProduct.M00; mat2.M01 -= meanProduct.M01; mat2.M02 -= meanProduct.M02; mat2.M10 -= meanProduct.M10; mat2.M11 -= meanProduct.M11; mat2.M12 -= meanProduct.M12; mat2.M20 -= meanProduct.M20; mat2.M21 -= meanProduct.M21; mat2.M22 -= meanProduct.M22; }
/** 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); }
/** * 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()); }
/** 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."); } }
/** * Initializes the GUI by creating the components, placing them in the dialog, and displaying * them. */ private void init() { setForeground(Color.black); setTitle("Nonlocal Means Filter"); JPanel mainPanel; mainPanel = new JPanel(); mainPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3)); mainPanel.setLayout(new GridBagLayout()); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridwidth = 1; gbc.gridheight = 1; gbc.anchor = GridBagConstraints.WEST; gbc.weightx = 1; gbc.insets = new Insets(3, 3, 3, 3); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.HORIZONTAL; paramPanel = new JPanel(new GridBagLayout()); paramPanel.setForeground(Color.black); paramPanel.setBorder(buildTitledBorder("Parameters")); mainPanel.add(paramPanel, gbc); GridBagConstraints gbc2 = new GridBagConstraints(); gbc2.gridwidth = 1; gbc2.gridheight = 1; gbc2.anchor = GridBagConstraints.WEST; gbc2.weightx = 1; gbc2.insets = new Insets(3, 3, 3, 3); gbc2.gridx = 0; gbc2.gridy = 0; gbc2.fill = GridBagConstraints.HORIZONTAL; labelSearchWindowSide = createLabel("Search window side (odd)"); paramPanel.add(labelSearchWindowSide, gbc2); gbc2.gridx = 1; textSearchWindowSide = createTextField("15"); paramPanel.add(textSearchWindowSide, gbc2); gbc2.gridx = 0; gbc2.gridy = 1; labelSimilarityWindowSide = createLabel("Similarity window side (odd) "); paramPanel.add(labelSimilarityWindowSide, gbc2); gbc2.gridx = 1; textSimilarityWindowSide = createTextField("7"); paramPanel.add(textSimilarityWindowSide, gbc2); gbc2.gridx = 0; gbc2.gridy = 2; labelNoiseStandardDeviation = createLabel("Noise standard deviation "); paramPanel.add(labelNoiseStandardDeviation, gbc2); gbc2.gridx = 1; textNoiseStandardDeviation = createTextField("10.0"); paramPanel.add(textNoiseStandardDeviation, gbc2); gbc2.gridx = 0; gbc2.gridy = 3; labelDegree = createLabel("Degree of filtering "); labelDegree.setEnabled(doRician); paramPanel.add(labelDegree, gbc2); gbc2.gridx = 1; textDegree = createTextField("1.414"); textDegree.setEnabled(doRician); paramPanel.add(textDegree, gbc2); gbc2.gridx = 0; gbc2.gridy = 4; doRicianCheckBox = new JCheckBox("Deal with Rician noise in MRI"); doRicianCheckBox.setFont(serif12); doRicianCheckBox.setSelected(false); doRicianCheckBox.addActionListener(this); paramPanel.add(doRicianCheckBox, gbc2); if (image.getNDims() > 2) { gbc2.gridx = 0; gbc2.gridy = 5; gbc2.gridwidth = 2; image25DCheckBox = new JCheckBox("Process each slice independently (2.5D)"); image25DCheckBox.setFont(serif12); paramPanel.add(image25DCheckBox, gbc2); image25DCheckBox.setSelected(false); } // if (image.getNDims > 2) JPanel outputOptPanel = new JPanel(new GridLayout(1, 2)); destinationPanel = new JPanel(new BorderLayout()); destinationPanel.setForeground(Color.black); destinationPanel.setBorder(buildTitledBorder("Destination")); outputOptPanel.add(destinationPanel); destinationGroup = new ButtonGroup(); newImage = new JRadioButton("New image", true); newImage.setBounds(10, 16, 120, 25); newImage.setFont(serif12); destinationGroup.add(newImage); destinationPanel.add(newImage, BorderLayout.NORTH); replaceImage = new JRadioButton("Replace image", false); replaceImage.setFont(serif12); destinationGroup.add(replaceImage); destinationPanel.add(replaceImage, BorderLayout.CENTER); // Only if the image is unlocked can it be replaced. if (image.getLockStatus() == ModelStorageBase.UNLOCKED) { replaceImage.setEnabled(true); } else { replaceImage.setEnabled(false); } gbc.gridx = 0; gbc.gridy = 1; mainPanel.add(outputOptPanel, gbc); mainDialogPanel.add(mainPanel, BorderLayout.CENTER); mainDialogPanel.add(buildButtons(), BorderLayout.SOUTH); getContentPane().add(mainDialogPanel); pack(); setResizable(true); // setVisible(true); System.gc(); }
/** 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; }
/** * Use the GUI results to set up the variables needed to run the algorithm. * * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise. */ private boolean setVariables() { String tmpStr; tmpStr = textXDim.getText(); try { subXDim = Integer.parseInt(tmpStr); } catch (NumberFormatException e) { MipavUtil.displayError("New XDIM string is not a valid integer"); textXDim.requestFocus(); textXDim.selectAll(); return false; } if (subXDim < 3) { MipavUtil.displayError("New XDIM must be at least 3"); textXDim.requestFocus(); textXDim.selectAll(); return false; } else if (subXDim > image.getExtents()[0]) { MipavUtil.displayError("New XDIM cannot exceed " + image.getExtents()[0]); textXDim.requestFocus(); textXDim.selectAll(); return false; } tmpStr = textYDim.getText(); try { subYDim = Integer.parseInt(tmpStr); } catch (NumberFormatException e) { MipavUtil.displayError("New YDIM string is not a valid integer"); textYDim.requestFocus(); textYDim.selectAll(); return false; } if (subYDim < 3) { MipavUtil.displayError("New YDIM must be at least 3"); textYDim.requestFocus(); textYDim.selectAll(); return false; } else if (subYDim > image.getExtents()[1]) { MipavUtil.displayError("New YDIM cannot exceed " + image.getExtents()[1]); textYDim.requestFocus(); textYDim.selectAll(); return false; } tmpStr = textNumberImages.getText(); try { numberOfImagesInMosaic = Integer.parseInt(tmpStr); } catch (NumberFormatException e) { MipavUtil.displayError("New numberOfImagesInMosaic string is not a valid integer"); textNumberImages.requestFocus(); textNumberImages.selectAll(); return false; } if (numberOfImagesInMosaic < 1) { MipavUtil.displayError("New numberOfImagesInMosaic must be at least 1"); textNumberImages.requestFocus(); textNumberImages.selectAll(); return false; } else if (numberOfImagesInMosaic > (subXDim * subYDim)) { MipavUtil.displayError("New numberOfImagesInMosaic cannot exceed (newXDim) * (newYDim)"); textNumberImages.requestFocus(); textNumberImages.selectAll(); return false; } displayLoc = NEW; return true; }
/** * Use the GUI results to set up the variables needed to run the algorithm. * * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise. */ private boolean setVariables() { String tmpStr; System.gc(); if (replaceImage.isSelected()) { displayLoc = REPLACE; } else if (newImage.isSelected()) { displayLoc = NEW; } tmpStr = textSearchWindowSide.getText(); if (testParameter(tmpStr, 5, 101)) { searchWindowSide = Integer.valueOf(tmpStr).intValue(); } else { MipavUtil.displayError("Search window side must be between 5 and 101"); textSearchWindowSide.requestFocus(); textSearchWindowSide.selectAll(); return false; } if ((searchWindowSide % 2) == 0) { MipavUtil.displayError("Search window side must be an odd number"); textSearchWindowSide.requestFocus(); textSearchWindowSide.selectAll(); return false; } tmpStr = textSimilarityWindowSide.getText(); if (testParameter(tmpStr, 3, 99)) { similarityWindowSide = Integer.valueOf(tmpStr).intValue(); } else { MipavUtil.displayError("Similarity window side must be between 3 and 99"); textSimilarityWindowSide.requestFocus(); textSimilarityWindowSide.selectAll(); return false; } if ((similarityWindowSide % 2) == 0) { MipavUtil.displayError("Similarity window side must be an odd number"); textSimilarityWindowSide.requestFocus(); textSimilarityWindowSide.selectAll(); return false; } if (similarityWindowSide >= searchWindowSide) { MipavUtil.displayError("Similarity window side must be less than search window side"); textSimilarityWindowSide.requestFocus(); textSimilarityWindowSide.selectAll(); return false; } tmpStr = textNoiseStandardDeviation.getText(); if (testParameter(tmpStr, 0.001, 1000.0)) { noiseStandardDeviation = Float.valueOf(tmpStr).floatValue(); } else { MipavUtil.displayError("Radius must be between 0.001 and 1000.0"); textNoiseStandardDeviation.requestFocus(); textNoiseStandardDeviation.selectAll(); return false; } doRician = doRicianCheckBox.isSelected(); if (doRician) { tmpStr = textDegree.getText(); if (testParameter(tmpStr, 1.0, 10.0)) { degreeOfFiltering = Float.valueOf(tmpStr).floatValue(); } else { MipavUtil.displayError("Degree of filtering must be between 1.0 and 10.0"); textDegree.requestFocus(); textDegree.selectAll(); } } if (image.getNDims() > 2) { image25D = image25DCheckBox.isSelected(); } return true; }
/** * Use the GUI results to set up the variables needed to run the algorithm. * * @return <code>true</code> if parameters set successfully, <code>false</code> otherwise. */ private boolean setVariables() { String tmpStr; int i; int totLength = image.getExtents()[0]; for (i = 1; i < image.getNDims(); i++) { totLength *= image.getExtents()[i]; } tmpStr = greenMergingText.getText(); mergingDistance = Float.parseFloat(tmpStr); if (mergingDistance < 0.0f) { MipavUtil.displayError("Merging distance cannot be less than 0"); greenMergingText.requestFocus(); greenMergingText.selectAll(); return false; } tmpStr = redMinText.getText(); redMin = Integer.parseInt(tmpStr); if (redMin < 1) { MipavUtil.displayError("red minimum must be at least 1"); redMinText.requestFocus(); redMinText.selectAll(); return false; } else if (redMin > totLength) { MipavUtil.displayError("red minimum must not exceed " + totLength); redMinText.requestFocus(); redMinText.selectAll(); return false; } tmpStr = redFractionText.getText(); redFraction = Float.parseFloat(tmpStr); if (redFraction <= 0.0f) { MipavUtil.displayError("red fraction must be greater than zero"); redFractionText.requestFocus(); redFractionText.selectAll(); return false; } else if (redFraction > 1.0f) { MipavUtil.displayError("red fraction must not exceed one"); redFractionText.requestFocus(); redFractionText.selectAll(); return false; } tmpStr = greenMinText.getText(); greenMin = Integer.parseInt(tmpStr); if (greenMin < 1) { MipavUtil.displayError("green minimum must be at least 1"); greenMinText.requestFocus(); greenMinText.selectAll(); return false; } else if (greenMin > totLength) { MipavUtil.displayError("green minimum must not exceed " + totLength); greenMinText.requestFocus(); greenMinText.selectAll(); return false; } tmpStr = greenFractionText.getText(); greenFraction = Float.parseFloat(tmpStr); if (greenFraction <= 0.0f) { MipavUtil.displayError("green fraction must be greater than zero"); greenFractionText.requestFocus(); greenFractionText.selectAll(); return false; } else if (greenFraction > 1.0f) { MipavUtil.displayError("green fraction must not exceed one"); greenFractionText.requestFocus(); greenFractionText.selectAll(); return false; } tmpStr = blueMinText.getText(); blueMin = Integer.parseInt(tmpStr); if (blueMin <= 0) { MipavUtil.displayError("Number of blue pixels must be greater than 0"); blueMinText.requestFocus(); blueMinText.selectAll(); return false; } else if (blueMin > totLength) { MipavUtil.displayError("blue minimum must not exceed " + totLength); blueMinText.requestFocus(); blueMinText.selectAll(); return false; } if (oneButton.isSelected()) { greenRegionNumber = 1; } else if (twoButton.isSelected()) { greenRegionNumber = 2; } else if (threeButton.isSelected()) { greenRegionNumber = 3; } else { greenRegionNumber = 4; } twoGreenLevels = twoBox.isSelected(); tmpStr = blueValueText.getText(); blueBoundaryFraction = Float.parseFloat(tmpStr); if (blueBoundaryFraction < 0.0f) { MipavUtil.displayError("Blue boundary fraction cannot be less than 0.0"); blueValueText.requestFocus(); blueValueText.selectAll(); return false; } else if (blueBoundaryFraction > 1.0f) { MipavUtil.displayError("Blue boundary value cannot be greater than 1.0"); blueValueText.requestFocus(); blueValueText.selectAll(); return false; } blueSmooth = blueSmoothBox.isSelected(); tmpStr = interpolationText.getText(); interpolationDivisor = Float.parseFloat(tmpStr); if (interpolationDivisor <= 1.0f) { MipavUtil.displayError("Interpolation divisor must be greater than 1"); interpolationText.requestFocus(); interpolationText.selectAll(); return false; } return true; } // end setVariables()
/** Starts the program. */ public void runAlgorithm() { int i, j, k; if (srcImage == null) { displayError("Source Image is null"); finalize(); return; } if (threadStopped) { finalize(); return; } trueVOIs = srcImage.getVOIs(); nTrueVOIs = trueVOIs.size(); testVOIs = testImage.getVOIs(); nTestVOIs = testVOIs.size(); length = srcImage.getExtents()[0]; for (i = 1; i < srcImage.getNDims(); i++) { length *= srcImage.getExtents()[i]; } testLength = testImage.getExtents()[0]; for (i = 1; i < testImage.getNDims(); i++) { testLength *= testImage.getExtents()[i]; } if (length != testLength) { MipavUtil.displayError( srcImage.getImageName() + " and " + testImage.getImageName() + " are unequal in dimensions"); setCompleted(false); return; } trueMask = new short[length]; testMask = new short[length]; ViewUserInterface.getReference().setGlobalDataText(srcImage.getImageName() + " = true\n"); ViewUserInterface.getReference().setGlobalDataText(testImage.getImageName() + " = test\n"); for (i = 0; i < nTrueVOIs; i++) { if ((trueVOIs.VOIAt(i).getCurveType() == VOI.CONTOUR) || (trueVOIs.VOIAt(i).getCurveType() == VOI.POLYLINE)) { trueID = trueVOIs.VOIAt(i).getID(); for (j = 0; j < nTestVOIs; j++) { testID = testVOIs.VOIAt(j).getID(); if (trueID == testID) { for (k = 0; k < length; k++) { trueMask[k] = -1; testMask[k] = -1; } trueMask = srcImage.generateVOIMask(trueMask, i); testMask = testImage.generateVOIMask(testMask, j); absoluteTrue = 0; trueFound = 0; falseNegative = 0; falsePositive = 0; for (k = 0; k < length; k++) { if (trueMask[k] == trueID) { absoluteTrue++; if (testMask[k] == trueID) { trueFound++; } else { falseNegative++; } } // if (trueMask[k] == trueID) else { // trueMask[k] != trueID if (testMask[k] == trueID) { falsePositive++; } } // else trueMask[k] != trueID } // for (k = 0; k < length; k++) ViewUserInterface.getReference() .setGlobalDataText( "Statistics for VOIs with ID = " + String.valueOf(trueID) + "\n"); fnvf = (float) falseNegative / (float) absoluteTrue; ViewUserInterface.getReference() .setGlobalDataText( " False negative volume fraction = " + String.valueOf(fnvf) + "\n"); fpvf = (float) falsePositive / (float) absoluteTrue; ViewUserInterface.getReference() .setGlobalDataText( " False positive volume fraction = " + String.valueOf(fpvf) + "\n"); tpvf = (float) trueFound / (float) absoluteTrue; ViewUserInterface.getReference() .setGlobalDataText( " True Positive volume fraction = " + String.valueOf(tpvf) + "\n\n"); } // if (trueID == testID) } // for (j = 0; j < nTestVOIs; j++) } // if ((trueVOIs.VOIAt(i).getCurveType() == VOI.CONTOUR) } // for (i = 0; i < nTrueVOIs; i++) setCompleted(true); }
/** Sets up the GUI (panels, buttons, etc) and displays it on the screen. */ private void init() { DecimalFormat df; int xUnits; String unitStr; String distStr; setForeground(Color.black); setTitle("Center Distances version 2 07/14/08"); df = new DecimalFormat("0.000E0"); GridBagConstraints gbc = new GridBagConstraints(); int yPos = 0; gbc.gridwidth = 1; gbc.gridheight = 1; gbc.anchor = GridBagConstraints.WEST; gbc.weightx = 1; gbc.insets = new Insets(3, 3, 3, 3); gbc.fill = GridBagConstraints.HORIZONTAL; gbc.gridx = 0; gbc.gridy = yPos++; JPanel mainPanel = new JPanel(new GridBagLayout()); mainPanel.setForeground(Color.black); mainPanel.setBorder(buildTitledBorder("Input parameters")); blueMinLabel = new JLabel("Minimum number of blue pixels per nucleus"); blueMinLabel.setForeground(Color.black); blueMinLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(blueMinLabel, gbc); blueMinText = new JTextField(5); if (image.getNDims() == 2) { blueMinText.setText("1000"); } else { blueMinText.setText("20000"); } blueMinText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(blueMinText, gbc); redMinLabel = new JLabel("Minimum red pixel count"); redMinLabel.setForeground(Color.black); redMinLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(redMinLabel, gbc); redMinText = new JTextField(5); redMinText.setText("50"); redMinText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(redMinText, gbc); redFractionLabel = new JLabel("Fraction of red pixels to consider"); redFractionLabel.setForeground(Color.black); redFractionLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(redFractionLabel, gbc); redFractionText = new JTextField(5); redFractionText.setText("0.15"); redFractionText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(redFractionText, gbc); xUnits = image.getFileInfo(0).getUnitsOfMeasure()[0]; if (xUnits != Unit.UNKNOWN_MEASURE.getLegacyNum()) { unitStr = (Unit.getUnitFromLegacyNum(xUnits)).toString(); greenMergingLabel = new JLabel("Green merging radius around peak (" + unitStr + ")"); } else { greenMergingLabel = new JLabel("Green merging radius around peak"); } greenMergingLabel.setForeground(Color.black); greenMergingLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(greenMergingLabel, gbc); if (image.getNDims() == 2) { // mergingDistance = 8.0f * image.getFileInfo(0).getResolutions()[0]; mergingDistance = 0.0f; } else { // mergingDistance = 4.0f * image.getFileInfo(0).getResolutions()[0]; mergingDistance = 0.0f; } distStr = df.format(mergingDistance); greenMergingText = new JTextField(10); greenMergingText.setText(distStr); greenMergingText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(greenMergingText, gbc); greenMinLabel = new JLabel("Minimum green pixel count"); greenMinLabel.setForeground(Color.black); greenMinLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(greenMinLabel, gbc); greenMinText = new JTextField(5); greenMinText.setText("10"); greenMinText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(greenMinText, gbc); greenFractionLabel = new JLabel("Fraction of green pixels to consider"); greenFractionLabel.setForeground(Color.black); greenFractionLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(greenFractionLabel, gbc); greenFractionText = new JTextField(5); greenFractionText.setText("0.01"); greenFractionText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(greenFractionText, gbc); greenRegionsLabel = new JLabel("Green regions per cell"); greenRegionsLabel.setForeground(Color.black); greenRegionsLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(greenRegionsLabel, gbc); JPanel buttonPanel = new JPanel(new GridBagLayout()); greenGroup = new ButtonGroup(); oneButton = new JRadioButton("1", false); oneButton.setForeground(Color.black); oneButton.setFont(serif12); greenGroup.add(oneButton); gbc.gridx = 0; gbc.gridy = 0; buttonPanel.add(oneButton, gbc); twoButton = new JRadioButton("2", true); twoButton.setForeground(Color.black); twoButton.setFont(serif12); greenGroup.add(twoButton); gbc.gridx = 1; gbc.gridy = 0; buttonPanel.add(twoButton, gbc); threeButton = new JRadioButton("3", false); threeButton.setForeground(Color.black); threeButton.setFont(serif12); greenGroup.add(threeButton); gbc.gridx = 2; gbc.gridy = 0; buttonPanel.add(threeButton, gbc); fourButton = new JRadioButton("4", false); fourButton.setForeground(Color.black); fourButton.setFont(serif12); greenGroup.add(fourButton); gbc.gridx = 3; gbc.gridy = 0; buttonPanel.add(fourButton, gbc); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(buttonPanel, gbc); twoBox = new JCheckBox("Use 2 top gray levels in green segmentation", true); twoBox.setForeground(Color.black); twoBox.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos++; mainPanel.add(twoBox, gbc); blueValueLabel = new JLabel("Fraction of blue transition from image min to max at nucleus boundary"); blueValueLabel.setForeground(Color.black); blueValueLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(blueValueLabel, gbc); blueValueText = new JTextField(5); blueValueText.setText("0.15"); blueValueText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(blueValueText, gbc); blueSmoothBox = new JCheckBox("Smooth blue VOI contours with AlgorithmBSmooth", true); blueSmoothBox.setForeground(Color.black); blueSmoothBox.setFont(serif12); blueSmoothBox.addActionListener(this); gbc.gridx = 0; gbc.gridy = yPos++; mainPanel.add(blueSmoothBox, gbc); interpolationLabel = new JLabel("Number of interpolation points determined by divisor (> 1.0)"); interpolationLabel.setForeground(Color.black); interpolationLabel.setFont(serif12); gbc.gridx = 0; gbc.gridy = yPos; mainPanel.add(interpolationLabel, gbc); interpolationText = new JTextField(5); interpolationText.setText("24.0"); interpolationText.setFont(serif12); gbc.gridx = 1; gbc.gridy = yPos++; mainPanel.add(interpolationText, gbc); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(buildButtons(), BorderLayout.SOUTH); pack(); setVisible(true); setResizable(false); System.gc(); } // end init()