/** {@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")); }
/** * 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()
/** * 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()
/** * 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()
/** 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()