Search in sources :

Example 31 with ROI

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

the class GenerateBleachRoiOp method generateBleachRoi.

public ROI generateBleachRoi(Image firstPostbleach, ROI cellROI_2D, Double bleachThreshold) throws ImageException {
    int numPixels = firstPostbleach.getNumXYZ();
    short[] scaledBleachedDataShort = new short[numPixels];
    short[] erodedCellUShort = cellROI_2D.getRoiImages()[0].getBinaryPixels(1);
    // input is already normalized to 1.0 ... if relative to max, then crazy values from outside cell can interfere.
    double bleachThresholdValue = bleachThreshold;
    double[] firstPostbleachImage = firstPostbleach.getDoublePixels();
    for (int j = 0; j < numPixels; j++) {
        boolean isCell = (erodedCellUShort[j] == 1);
        boolean isBleach = firstPostbleachImage[j] < bleachThresholdValue;
        if (isCell && isBleach) {
            scaledBleachedDataShort[j] = 1;
        }
    }
    UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, firstPostbleach.getOrigin(), firstPostbleach.getExtent(), firstPostbleach.getNumX(), firstPostbleach.getNumY(), firstPostbleach.getNumZ());
    ROI bleachedROI = new ROI(bleachedImage, "bleachedROI");
    return bleachedROI;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 32 with ROI

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

the class GenerateCellROIsFromRawPhotoactivationTimeSeriesOp method generate.

public GeometryRoisAndActivationTiming generate(ImageTimeSeries rawTimeSeriesImages, double cellThreshold) throws Exception {
    Image[] allImages = rawTimeSeriesImages.getAllImages();
    int numPixels = allImages[0].getNumXYZ();
    int numTimes = allImages.length;
    ImageStatistics[] imageStats = new ImageStatistics[numTimes];
    for (int i = 0; i < numTimes; i++) {
        imageStats[i] = allImages[i].getImageStatistics();
    }
    // 
    // find largest change in fluorescence (ratio of total[n+1]/total[n]
    // 
    int indexPostactivation = -1;
    double largestRatio = 0.0;
    for (int tIndex = 0; tIndex < numTimes - 1; tIndex++) {
        double currentRatio = imageStats[tIndex + 1].meanValue / imageStats[tIndex].meanValue;
        if (currentRatio > largestRatio) {
            largestRatio = currentRatio;
            indexPostactivation = tIndex + 1;
        }
    }
    double[] firstImagePixels = allImages[0].getDoublePixels();
    short[] scaledCellDataShort = new short[numPixels];
    short[] scaledBackgoundDataShort = new short[numPixels];
    short[] wholeDomainDataShort = new short[numPixels];
    // 
    // find cell and background by thresholding the first image
    // 
    double cellThresholdValue = cellThreshold * imageStats[0].maxValue;
    for (int j = 0; j < numPixels; j++) {
        boolean isCell = firstImagePixels[j] > cellThresholdValue;
        if (isCell) {
            scaledCellDataShort[j] = 1;
        } else {
            scaledBackgoundDataShort[j] = 1;
        }
    }
    UShortImage cellImage = new UShortImage(scaledCellDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    Arrays.fill(wholeDomainDataShort, (short) 1);
    UShortImage wholeDomainImage = new UShortImage(wholeDomainDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage reverseCell = UShortImage.fastDilate(cellImage, 10, wholeDomainImage);
    reverseCell.reverse();
    reverseCell.and(backgroundImage);
    backgroundImage = reverseCell;
    cellImage = new UShortImage(backgroundImage);
    cellImage.reverse();
    ROI cellROI = new ROI(cellImage, "cellROI");
    ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
    GeometryRoisAndActivationTiming results = new GeometryRoisAndActivationTiming();
    results.cellROI_2D = cellROI;
    results.backgroundROI_2D = backgroundROI;
    results.indexOfFirstPostactivation = indexPostactivation;
    return results;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Image(cbit.vcell.VirtualMicroscopy.Image) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 33 with ROI

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

the class MicroscopyXmlReader method getAnnotatedImageDataset.

public AnnotatedImageDataset getAnnotatedImageDataset(Element param, /*root, frapstudy element*/
ClientTaskStatusSupport progressListener) throws XmlParseException {
    // get frapData element
    Element frapDataElement = param.getChild(MicroscopyXMLTags.FRAPDataTag);
    Element imageDatasetElement = frapDataElement.getChild(MicroscopyXMLTags.ImageDatasetTag);
    ImageDataset imageDataset = null;
    if (imageDatasetElement != null) {
        imageDataset = getImageDataset(imageDatasetElement, progressListener);
    }
    Namespace ns = param.getNamespace();
    List<Element> roiList = frapDataElement.getChildren(MicroscopyXMLTags.ROITag);
    ROI[] rois = new ROI[0];
    int numROIs = roiList.size();
    if (numROIs > 0) {
        rois = new ROI[numROIs];
        Iterator<Element> roiIter = roiList.iterator();
        int index = 0;
        while (roiIter.hasNext()) {
            Element roiElement = roiIter.next();
            rois[index++] = getROI(roiElement);
        }
    }
    // reorder ROIs according to the order of FRAPData.VFRAP_ROI_ENUM
    ROI[] reorderedROIs = AnnotatedImageDataset.reorderROIs(rois);
    AnnotatedImageDataset annotatedImages = new AnnotatedImageDataset(imageDataset, reorderedROIs);
    // After loading all the ROI rings, the progress should set to 100.
    if (progressListener != null) {
        progressListener.setProgress(100);
    }
    return annotatedImages;
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Element(org.jdom.Element) ROI(cbit.vcell.VirtualMicroscopy.ROI) Namespace(org.jdom.Namespace)

Example 34 with ROI

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

the class ROIMultiPaintManager method highlightHistogramPixels.

private void highlightHistogramPixels(final DefaultListSelectionModel histSelection) {
    final String HISTO_HIGHLIGHT = "HISTO_HIGHLIGHT";
    AsynchClientTask histoROITask = new AsynchClientTask("Calculating histogram highlight...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ROI highlight = overlayEditorPanelJAI.getHighliteInfo();
            if (highlight == null) {
                highlight = createEmptyROI(new ISize(roiComposite[0].getWidth(), roiComposite[0].getHeight(), roiComposite.length));
            }
            for (int i = 0; i < highlight.getRoiImages().length; i++) {
                short[] pixels = highlight.getRoiImages()[i].getPixels();
                for (int j = 0; j < pixels.length; j++) {
                    int currPixelVal = getImageDataSetChannel().getAllImages()[i].getPixels()[j] & 0x0000FFFF;
                    if (histSelection != null && histSelection.isSelectedIndex(currPixelVal)) {
                        pixels[j] = (short) 0xFFFF;
                    } else {
                        pixels[j] = 0;
                    }
                }
            }
            hashTable.put(HISTO_HIGHLIGHT, highlight);
        }
    };
    AsynchClientTask updatedisplayTask = new AsynchClientTask("Updating display...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            overlayEditorPanelJAI.setHighliteInfo((ROI) hashTable.get(HISTO_HIGHLIGHT), OverlayEditorPanelJAI.FRAP_DATA_HISTOUPDATEHIGHLIGHT_PROPERTY);
        }
    };
    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { histoROITask, updatedisplayTask });
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ISize(org.vcell.util.ISize) ROI(cbit.vcell.VirtualMicroscopy.ROI) Point(java.awt.Point)

Example 35 with ROI

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

the class ROIAssistPanel method pickKeepRegionInfoFromCurrentROI.

private RegionInfo[] pickKeepRegionInfoFromCurrentROI() throws Exception {
    RegionInfo[] thresholdRegionInfos = calculateRegionInfos(dataToThreshold.getCurrentlyDisplayedROI().getPixelsXYZ());
    Vector<RegionInfo> roiRegionInfoV = new Vector<RegionInfo>();
    for (int i = 0; i < thresholdRegionInfos.length; i++) {
        if (thresholdRegionInfos[i].getPixelValue() == 1) {
            roiRegionInfoV.add(thresholdRegionInfos[i]);
        }
    }
    if (roiRegionInfoV.size() == 0) {
        DialogUtils.showInfoDialog(this, "There are no Regions Of Interest to resolve.");
        return null;
    }
    // Present list to pick from
    final RegionInfo[] regionInfoArr = roiRegionInfoV.toArray(new RegionInfo[0]);
    Arrays.sort(regionInfoArr, new Comparator<RegionInfo>() {

        public int compare(RegionInfo o1, RegionInfo o2) {
            return o2.getNumPixels() - o1.getNumPixels();
        }
    });
    final Object[][] rowData = new Object[regionInfoArr.length][1];
    for (int i = 0; i < regionInfoArr.length; i++) {
        rowData[i][0] = regionInfoArr[i].getNumPixels() + " pixels";
    }
    final ROI beforeROI = new ROI(dataToThreshold.getCurrentlyDisplayedROI());
    int[] resultArr = null;
    ListSelectionListener listSelectionListener = new ListSelectionListener() {

        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                try {
                    DefaultListSelectionModel defaultListSelectionModel = (DefaultListSelectionModel) e.getSource();
                    Vector<Integer> pickedIndexes = new Vector<Integer>();
                    if (!defaultListSelectionModel.isSelectionEmpty()) {
                        for (int i = defaultListSelectionModel.getMinSelectionIndex(); i <= defaultListSelectionModel.getMaxSelectionIndex(); i++) {
                            if (defaultListSelectionModel.isSelectedIndex(i)) {
                                pickedIndexes.add(i);
                            }
                        }
                    }
                    // beforeROI.getPixelsXYZ();
                    short[] pickedPixels = new short[beforeROI.getISize().getXYZ()];
                    for (int i = 0; i < pickedPixels.length; i++) {
                        for (int j = 0; j < pickedIndexes.size(); j++) {
                            if (regionInfoArr[pickedIndexes.elementAt(j)].isIndexInRegion(i)) {
                                pickedPixels[i] = 1;
                            }
                        }
                    }
                    ROI newCellROI = null;
                    if (pickedIndexes.size() == 0) {
                        newCellROI = beforeROI;
                    } else {
                        UShortImage ushortImage = new UShortImage(pickedPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
                        newCellROI = new ROI(ushortImage, originalROI.getROIName());
                    }
                    dataToThreshold.addReplaceRoi(newCellROI);
                } catch (Exception e2) {
                    e2.printStackTrace();
                    throw new RuntimeException("Error selecting resolved ROI", e2);
                }
            }
        }
    };
    try {
        resultArr = DialogUtils.showComponentOptionsTableList(this, "Select 1 or more pixel regions to keep in ROI", new String[] { "ROI Size (pixel count)" }, rowData, ListSelectionModel.MULTIPLE_INTERVAL_SELECTION, listSelectionListener, null, null, null).selectedTableRows;
    } catch (UserCancelException e) {
        resultArr = null;
    }
    if (resultArr != null && resultArr.length > 0) {
        RegionInfo[] pickedRegions = new RegionInfo[resultArr.length];
        for (int i = 0; i < resultArr.length; i++) {
            pickedRegions[i] = regionInfoArr[resultArr[i]];
        }
        // (resultArr == null?null:regionInfoArr[resultArr]);
        return pickedRegions;
    } else {
        dataToThreshold.addReplaceRoi(beforeROI);
    }
    return null;
}
Also used : ListSelectionEvent(javax.swing.event.ListSelectionEvent) UserCancelException(org.vcell.util.UserCancelException) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DefaultListSelectionModel(javax.swing.DefaultListSelectionModel) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI) UserCancelException(org.vcell.util.UserCancelException) ListSelectionListener(javax.swing.event.ListSelectionListener) Vector(java.util.Vector)

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