Search in sources :

Example 11 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class DefineROI_SummaryPanel method setLoadInfo.

public void setLoadInfo(final FRAPStudy frapStudy) {
    if (frapStudy != null && frapStudy.getFrapData() != null) {
        // enable components to change values
        BeanUtils.enableComponents(getInfoPanel(), true);
        BeanUtils.enableComponents(getIndexPanel(), true);
        // set info panel
        ImageDataset imgDataset = frapStudy.getFrapData().getImageDataset();
        imgXTextField.setText(NumberUtils.formatNumber(imgDataset.getExtent().getX(), 15));
        imgYTextField.setText(NumberUtils.formatNumber(imgDataset.getExtent().getY(), 15));
        FRAPData fData = frapStudy.getFrapData();
        ROI cellROI = fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
        ROI bleachedROI = fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
        ROI backgroundROI = fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
        if (cellROI.getNonzeroPixelsCount() < 1) {
            cellROIUndefined.setSelected(true);
            cellROIDefined.setSelected(false);
        } else {
            cellROIUndefined.setSelected(false);
            cellROIDefined.setSelected(true);
        }
        if (bleachedROI.getNonzeroPixelsCount() < 1) {
            bleachROIUndefined.setSelected(true);
            bleachROIDefined.setSelected(false);
        } else {
            bleachROIUndefined.setSelected(false);
            bleachROIDefined.setSelected(true);
        }
        if (backgroundROI.getNonzeroPixelsCount() < 1) {
            bgROIUndefined.setSelected(true);
            bgROIDefined.setSelected(false);
        } else {
            bgROIUndefined.setSelected(false);
            bgROIDefined.setSelected(true);
        }
        // they are not editable
        imgXTextField.setEditable(false);
        imgYTextField.setEditable(false);
        cellROIDefined.setEnabled(false);
        cellROIUndefined.setEnabled(false);
        bleachROIDefined.setEnabled(false);
        bleachROIUndefined.setEnabled(false);
        bgROIDefined.setEnabled(false);
        bgROIUndefined.setEnabled(false);
        // set index panel
        startIndexCombo.removeAllItems();
        double[] timeSteps = frapStudy.getFrapData().getImageDataset().getImageTimeStamps();
        for (int i = 0; i < timeSteps.length; i++) {
            startIndexCombo.addItem(timeSteps[i] + "");
        }
        if (bleachROIDefined.isSelected()) {
            int index = (frapStudy.getStartingIndexForRecovery() == null ? FRAPDataAnalysis.calculateRecoveryIndex(frapStudy.getFrapData()) : frapStudy.getStartingIndexForRecovery());
            startIndexCombo.setSelectedIndex(index);
            startIndexAvaliableLabel.setText(START_IDX_AVAILABLE_STR);
        } else {
            startIndexCombo.setSelectedIndex(0);
            startIndexAvaliableLabel.setText(START_IDX_UNAVAILABLE_STR);
        }
    } else {
        imgXTextField.setText("");
        imgYTextField.setText("");
        cellROIDefined.setSelected(false);
        cellROIUndefined.setSelected(false);
        bleachROIDefined.setSelected(false);
        bleachROIUndefined.setSelected(false);
        bgROIDefined.setSelected(false);
        bgROIUndefined.setSelected(false);
        startIndexCombo.removeAllItems();
        startIndexCombo.addItem("     N/A     ");
        BeanUtils.enableComponents(getInfoPanel(), false);
        BeanUtils.enableComponents(getIndexPanel(), false);
    }
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) FRAPData(cbit.vcell.microscopy.FRAPData) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 12 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class VFrap_ROIAssistPanel method showComponentOKCancelTableList.

public int[] showComponentOKCancelTableList(final Component requester, String title, String[] columnNames, Object[][] rowData, int listSelectionModel_SelectMode, final RegionInfo[] regionInfoArr, final short[] multiObjectROIPixels) throws UserCancelException {
    DefaultTableModel tableModel = new DefaultTableModel() {

        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    tableModel.setDataVector(rowData, columnNames);
    final JTable table = new JTable(tableModel);
    table.setSelectionMode(listSelectionModel_SelectMode);
    JScrollPane scrollPane = new JScrollPane(table);
    table.setPreferredScrollableViewportSize(new Dimension(500, 250));
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                try {
                    int index = table.getSelectedRow();
                    // System.out.println("list index="+index);
                    RegionInfo keepRegion = regionInfoArr[index];
                    short[] removePixels = multiObjectROIPixels.clone();
                    for (int i = 0; i < removePixels.length; i++) {
                        if (!keepRegion.isIndexInRegion(i)) {
                            removePixels[i] = 0;
                        }
                    }
                    UShortImage ushortImage = new UShortImage(removePixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
                    final ROI newCellROI = new ROI(ushortImage, frapData.getCurrentlyDisplayedROI().getROIName());
                    frapData.addReplaceRoi(newCellROI);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    throw new RuntimeException("Error selecting resolved ROI", e2);
                }
            }
        }
    });
    ScopedExpressionTableCellRenderer.formatTableCellSizes(table);
    int result = DialogUtils.showComponentOKCancelDialog(requester, scrollPane, title);
    if (result != JOptionPane.OK_OPTION) {
        throw UserCancelException.CANCEL_GENERIC;
    }
    return table.getSelectedRows();
}
Also used : JScrollPane(javax.swing.JScrollPane) DefaultTableModel(javax.swing.table.DefaultTableModel) JTable(javax.swing.JTable) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Dimension(java.awt.Dimension) ROI(cbit.vcell.VirtualMicroscopy.ROI) UserCancelException(org.vcell.util.UserCancelException) ListSelectionListener(javax.swing.event.ListSelectionListener)

Example 13 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class VFrap_ROIAssistPanel method processTimepoint.

private void processTimepoint() {
    new Thread(new Runnable() {

        public void run() {
            try {
                boolean bInvert = !frapData.getCurrentlyDisplayedROI().getROIName().equals(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_CELL.name());
                short[] cellMask = null;
                if (bInvert) {
                    cellMask = frapData.getRoi(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_CELL.name()).getPixelsXYZ();
                }
                short[] shortPixels = new short[lastROISourceDataShort.length];
                for (int i = 0; i < lastROISourceDataShort.length; i++) {
                    shortPixels[i] = (short) (isSet(frapData.getCurrentlyDisplayedROI().getROIName(), lastROISourceDataShort[i], thresholdSlider.getValue(), thresholdSliderIntensityLookup, (cellMask == null ? true : cellMask[i] != 0)) ? 0xFFFF : 0);
                }
                UShortImage ushortImage = new UShortImage(shortPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
                ROI newCellROI = new ROI(ushortImage, frapData.getCurrentlyDisplayedROI().getROIName());
                final ROI forceValidROI = forceROIValid(newCellROI);
                SwingUtilities.invokeAndWait(new Runnable() {

                    public void run() {
                        // }});
                        frapData.addReplaceRoi(forceValidROI);
                    }
                });
            } catch (final Exception e2) {
                lastROISourceDataShort = null;
                e2.printStackTrace();
                SwingUtilities.invokeLater(new Runnable() {

                    public void run() {
                        // }});
                        DialogUtils.showErrorDialog(VFrap_ROIAssistPanel.this, "Error setting new ROI. " + e2.getMessage());
                    }
                });
            }
        }
    }).start();
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) UserCancelException(org.vcell.util.UserCancelException)

Example 14 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class VFrap_ROIAssistPanel method forceROIValid.

private ROI forceROIValid(ROI validateROI) throws Exception {
    if (validateROI.getROIName().equals(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name())) {
        lastRegionInfos = null;
        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                // }});
                applyROIButton.setEnabled(true);
                resolveROIButton.setEnabled(false);
                fillVoidsButton.setEnabled(false);
            }
        });
        return validateROI;
    }
    if (validateROI.getNonzeroPixelsCount() < 1) {
        return validateROI;
    }
    // 
    // Remove pixels touching only at corners
    // 
    short[] validatePixels = validateROI.getPixelsXYZ();
    // 
    // Remove noise objects
    // 
    lastRegionInfos = calculateRegionInfos(validatePixels);
    Vector<RegionInfo> roiRegionInfoV = new Vector<RegionInfo>();
    for (int i = 0; i < lastRegionInfos.length; i++) {
        if (lastRegionInfos[i].getPixelValue() == 1) {
            roiRegionInfoV.add(lastRegionInfos[i]);
        }
    // System.out.println(lastRegionInfos[i]);
    }
    // if(validateROI.getROIType().equals(RoiType.ROI_CELL) || validateROI.getROIType().equals(RoiType.ROI_BLEACHED)){
    if (roiRegionInfoV.size() > 1) {
        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                applyROIButton.setEnabled(false);
                resolveROIButton.setEnabled(true);
                fillVoidsButton.setEnabled(false);
            }
        });
    } else {
        final boolean hasInternalVoids = fillVoids(validatePixels, true);
        SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                // }});
                lastRegionInfos = null;
                applyROIButton.setEnabled(!hasInternalVoids);
                resolveROIButton.setEnabled(false);
                fillVoidsButton.setEnabled(hasInternalVoids);
            }
        });
    }
    UShortImage ushortImage = new UShortImage(validatePixels, validateROI.getRoiImages()[0].getOrigin(), validateROI.getRoiImages()[0].getExtent(), validateROI.getISize().getX(), validateROI.getISize().getY(), validateROI.getISize().getZ());
    ROI newROI = new ROI(ushortImage, validateROI.getROIName());
    if (newROI.compareEqual(validateROI)) {
        return validateROI;
    }
    return newROI;
}
Also used : RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Vector(java.util.Vector) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 15 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class VFrap_OverlayEditorPanelJAI method showROIAssist.

public void showROIAssist() {
    // shows up with automatica detected region of interest regardless of whatever is defined, users may lose defined ROI by accidentally clicking the ROI assistant.
    if (getRoiSouceData().getCurrentlyDisplayedROI() != null && getRoiSouceData().getCurrentlyDisplayedROI().getNonzeroPixelsCount() > 0) {
        String choice = DialogUtils.showWarningDialog(this, "Invoking the ROI assistant will override already defined '" + getRoiSouceData().getCurrentlyDisplayedROI().getROIName() + "'. Do you want to continue?", new String[] { UserMessage.OPTION_CONTINUE, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CANCEL);
        if (choice.equals(UserMessage.OPTION_CANCEL)) {
            return;
        }
    }
    // only check when doing roiAssist for bleached, this is actually used by VFRAP. (VCell has Cell ROI only)
    if (getRoiSouceData().getCurrentlyDisplayedROI().getROIName().equals(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()) && getRoiSouceData().getRoi(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_CELL.name()).getNonzeroPixelsCount() < 1) {
        DialogUtils.showInfoDialog(VFrap_OverlayEditorPanelJAI.this, "Cell ROI must be defined before using ROI Assist Tool to create Bleached ROI.");
        return;
    }
    ROI originalROI = null;
    try {
        originalROI = new ROI(roi);
    } catch (Exception ex) {
        ex.printStackTrace();
    // can't happen
    }
    getROIAssistPanel().init(originalROI, getRoiSouceData(), VFrap_OverlayEditorPanelJAI.this);
    setROIAssistVisible(true);
    adjustComponentsForVFRAP(SHOW_RIO_ASSISTANT);
}
Also used : ROI(cbit.vcell.VirtualMicroscopy.ROI) CannotUndoException(javax.swing.undo.CannotUndoException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

ROI (cbit.vcell.VirtualMicroscopy.ROI)72 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)26 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)10 ArrayList (java.util.ArrayList)10 UserCancelException (org.vcell.util.UserCancelException)10 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)9 ImageException (cbit.image.ImageException)8 Image (cbit.vcell.VirtualMicroscopy.Image)7 FRAPData (cbit.vcell.microscopy.FRAPData)7 BioModel (cbit.vcell.biomodel.BioModel)6 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)5 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)5 RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)5 File (java.io.File)5 Hashtable (java.util.Hashtable)5 Element (org.jdom.Element)5 Extent (org.vcell.util.Extent)5 VCImage (cbit.image.VCImage)4 VCImageUncompressed (cbit.image.VCImageUncompressed)4 Expression (cbit.vcell.parser.Expression)4