Search in sources :

Example 46 with UShortImage

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

the class ROIMultiPaintManager method applyPixelClasses.

private void applyPixelClasses(VCPixelClass[] vcPixelClasses, Component parentComponent) {
    if (vcPixelClasses != null) {
        int backgroundIndex = -1;
        int[] pixelValMapPixelClassIndex = new int[256];
        Arrays.fill(pixelValMapPixelClassIndex, -1);
        String[][] rowData = new String[vcPixelClasses.length][1];
        for (int i = 0; i < vcPixelClasses.length; i++) {
            pixelValMapPixelClassIndex[vcPixelClasses[i].getPixel()] = i;
            rowData[i][0] = vcPixelClasses[i].getPixelClassName();
            if (vcPixelClasses[i].getPixel() == 0 && vcPixelClasses[i].getPixelClassName().equals(RESERVED_NAME_BACKGROUND)) {
                // choose background automatically
                backgroundIndex = i;
            }
        }
        // Create ROIs from VCPixelclasses
        // start 1 after background index color
        int roiCount = 1;
        int[] pixelClassIndexMaproiIndex = new int[vcPixelClasses.length];
        for (int i = 0; i < vcPixelClasses.length; i++) {
            if (i == backgroundIndex) {
                // background
                pixelClassIndexMaproiIndex[i] = 0;
                continue;
            }
            overlayEditorPanelJAI.addROIName(vcPixelClasses[i].getPixelClassName(), true, vcPixelClasses[0].getPixelClassName(), true, /*true,true,*/
            roiCount);
            pixelClassIndexMaproiIndex[i] = roiCount;
            roiCount++;
        }
        // fill in rois using pixel value and VCPixelClass mappings
        for (int zindex = 0; zindex < roiComposite.length; zindex++) {
            byte[] zdata = ((DataBufferByte) roiComposite[zindex].getRaster().getDataBuffer()).getData();
            UShortImage uShortImage = initImageDataSetChannels[0].getImage(zindex, 0, 0);
            for (int xyindex = 0; xyindex < zdata.length; xyindex++) {
                // unsigned short
                int pixelval = uShortImage.getPixels()[xyindex] & 0x000000FF;
                zdata[xyindex] = (byte) pixelClassIndexMaproiIndex[pixelValMapPixelClassIndex[pixelval]];
            }
        }
    }
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 47 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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)

Example 48 with UShortImage

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

the class ROIAssistPanel method fillVoidsAction.

private void fillVoidsAction() {
    final String CELL_ROI = "CELL_ROI";
    AsynchClientTask voidTask = new AsynchClientTask("Finding voids", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            short[] filledVoidsPixels = dataToThreshold.getCurrentlyDisplayedROI().getPixelsXYZ();
            boolean bVoidsExisted = fillVoids(filledVoidsPixels, false);
            if (!bVoidsExisted) {
                DialogUtils.showInfoDialog(ROIAssistPanel.this, "No internal voids were found, no changes were made.");
                throw UserCancelException.CANCEL_GENERIC;
            }
            UShortImage ushortImage = new UShortImage(filledVoidsPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
            ROI newCellROI = new ROI(ushortImage, originalROI.getROIName());
            hashTable.put(CELL_ROI, newCellROI);
        }
    };
    AsynchClientTask updateDisplayTask = new AsynchClientTask("Updating display", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            dataToThreshold.addReplaceRoi((ROI) hashTable.get(CELL_ROI));
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { voidTask, updateDisplayTask }, false, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 49 with UShortImage

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

the class ROIAssistPanel method processTimepoint.

private void processTimepoint() {
    final String NEW_ROI = "NEW_ROI";
    AsynchClientTask calcROI = new AsynchClientTask("Calculating ROI", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            short[] shortPixels = new short[enhancedDataToThresholdShort.length];
            for (int i = 0; i < enhancedDataToThresholdShort.length; i++) {
                shortPixels[i] = (short) (isSet(/*originalROI.getROIName(),*/
                enhancedDataToThresholdShort[i], thresholdSlider.getValue(), thresholdSliderIntensityLookup, (maskBitSet != null ? maskBitSet.get(i) : true)) ? 0xFFFF : 0);
            }
            UShortImage ushortImage = new UShortImage(shortPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
            final ROI newCellROI = new ROI(ushortImage, originalROI.getROIName());
            hashTable.put(NEW_ROI, newCellROI);
        }
    };
    AsynchClientTask displayROI = new AsynchClientTask("displayROI", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            dataToThreshold.addReplaceRoi((ROI) hashTable.get(NEW_ROI));
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { calcROI, displayROI }, false, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 50 with UShortImage

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

the class ROIMultiPaintManager method askApplyHighlightToROI.

private boolean askApplyHighlightToROI() {
    UShortImage[] roiZ = overlayEditorPanelJAI.getHighliteInfo().getRoiImages();
    boolean bOverWrite = true;
    // Check for existing ROI
    final String OVERWRITE_ALL = "Overwrite any existing Domain Regionss";
    final String KEEP_EXISTING = "Keep existing Domain Regions when overlapping";
    final String CANCEL_ROI_UPDATE = "Cancel";
    // boolean bHadAny = false;
    for (int i = 0; i < roiZ.length; i++) {
        boolean bDone = false;
        short[] pixels = roiZ[i].getPixels();
        byte[] compositePixels = ((DataBufferByte) roiComposite[i].getRaster().getDataBuffer()).getData();
        for (int j = 0; j < compositePixels.length; j++) {
            // bHadAny|= pixels[j] != 0;
            if (compositePixels[j] != 0 && pixels[j] != 0) /* && compositePixels[j] != (byte)roiColorIndex*/
            {
                bDone = true;
                String result = DialogUtils.showWarningDialog(overlayEditorPanelJAI, "Some areas of the new Domain Regions overlap with existing Domain Regions.", new String[] { OVERWRITE_ALL, KEEP_EXISTING, CANCEL_ROI_UPDATE }, OVERWRITE_ALL);
                if (result.equals(KEEP_EXISTING)) {
                    bOverWrite = false;
                } else if (result.equals(CANCEL_ROI_UPDATE)) {
                    throw UserCancelException.CANCEL_GENERIC;
                }
                break;
            }
        }
        if (bDone) {
            break;
        }
    }
    return bOverWrite;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Aggregations

UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)98 ROI (cbit.vcell.VirtualMicroscopy.ROI)26 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)20 Point (java.awt.Point)16 File (java.io.File)14 Extent (org.vcell.util.Extent)13 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)12 Origin (org.vcell.util.Origin)10 ImageException (cbit.image.ImageException)9 Element (org.jdom.Element)9 DataBufferByte (java.awt.image.DataBufferByte)8 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)7 ArrayList (java.util.ArrayList)7 ISize (org.vcell.util.ISize)7 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)6 ClientTaskStatusSupport (org.vcell.util.ClientTaskStatusSupport)6 UserCancelException (org.vcell.util.UserCancelException)6 ProfileDataElement (org.vcell.optimization.ProfileDataElement)5 ImportRawTimeSeriesFromVFrapOp (org.vcell.vmicro.op.ImportRawTimeSeriesFromVFrapOp)5 OptContext (org.vcell.vmicro.workflow.data.OptContext)5