use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class VFrap_ROIAssistPanel method createROISourceData.
private void createROISourceData(boolean bNew) throws Exception {
final ROI oldROI = frapData.getRoi(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_CELL.name());
// new short[oldROI.getISize().getXYZ()];
short[] roiSourceData = null;
if (roiSourceComboBox.getSelectedIndex() == 0) {
// timeAverage
if (roiTimeAverageDataShort == null) {
createScaledTimeAverageData();
}
roiSourceData = roiTimeAverageDataShort.clone();
} else {
final int timeIndex = roiSourceComboBox.getSelectedIndex() - 1;
roiSourceData = collectAllZAtOneTimepointIntoOneArray(frapData.getImageDataset(), timeIndex);
}
scaleDataInPlace(roiSourceData);
if (spatialEnhanceComboBox.getSelectedIndex() > 0) {
short[] enhacedBytes = new short[roiSourceData.length];
int radius = (spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_AVG_3X3) ? 1 : 0) + (spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_AVG_5x5) ? 2 : 0) + (spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_AVG_7x7) ? 3 : 0) + (spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_MEDIAN_3X3) ? 1 : 0) + (spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_MEDIAN_5x5) ? 2 : 0);
int pixelIndex = 0;
int accum = 0;
int convSize = (radius * 2 + 1) * (radius * 2 + 1);
int[] convPixels = new int[convSize];
for (int z = 0; z < oldROI.getISize().getZ(); z++) {
int zOffset = z * oldROI.getISize().getX() * oldROI.getISize().getY();
for (int y = 0; y < oldROI.getISize().getY(); y++) {
int yoffset = y * oldROI.getISize().getX();
for (int x = 0; x < oldROI.getISize().getX(); x++) {
accum = 0;
for (int xbox = -radius; xbox <= radius; xbox++) {
for (int ybox = -radius; ybox <= radius; ybox++) {
if (x + xbox >= 0 && x + xbox < oldROI.getISize().getX() && y + ybox >= 0 && y + ybox < oldROI.getISize().getY()) {
convPixels[accum] = 0x0000FFFF & roiSourceData[zOffset + yoffset + x + xbox + (ybox * oldROI.getISize().getX())];
} else {
convPixels[accum] = 0x0000FFFF & roiSourceData[zOffset + yoffset + x];
}
accum++;
}
}
if (spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_AVG_3X3) || spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_AVG_5x5) || spatialEnhanceComboBox.getSelectedItem().equals(ENHANCE_AVG_7x7)) {
accum = 0;
for (int i = 0; i < convPixels.length; i++) {
accum += convPixels[i];
}
} else {
Arrays.sort(convPixels);
accum = convPixels[convSize / 2] * convSize;
}
enhacedBytes[pixelIndex] |= ((accum / (convSize)) & 0x0000FFFF);
pixelIndex++;
}
}
}
roiSourceData = enhacedBytes;
}
final short[] finalROISourceData = new short[oldROI.getISize().getX() * oldROI.getISize().getY()];
System.arraycopy(roiSourceData, finalROISourceData.length * overlayEditorPanelJAI.getZ(), finalROISourceData, 0, finalROISourceData.length);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// }});
try {
overlayEditorPanelJAI.displaySpecialData(finalROISourceData, oldROI.getISize().getX(), oldROI.getISize().getY());
} catch (Exception e) {
throw new RuntimeException("Error displaying TimeAverage data. " + e.getMessage());
}
}
});
Integer oldThreshold = (bNew ? null : thresholdSliderIntensityLookup[thresholdSlider.getValue()]);
lastROISourceDataShort = roiSourceData;
TreeMap<Integer, Integer> condensedBins = getCondensedBins(lastROISourceDataShort, originalROI.getROIName());
Integer[] intensityIntegers = condensedBins.keySet().toArray(new Integer[0]);
thresholdSliderIntensityLookup = new int[intensityIntegers.length];
for (int i = 0; i < intensityIntegers.length; i++) {
thresholdSliderIntensityLookup[i] = intensityIntegers[i];
}
thresholdSlider.removeChangeListener(processTimepointChangeListener);
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// }});
thresholdSlider.setMaximum(thresholdSliderIntensityLookup.length - 1);
}
});
int newThresholdIndex = thresholdSliderIntensityLookup.length / 2;
if (bNew) {
newThresholdIndex = getHistogramIntensityAtHalfPixelCount(condensedBins);
newThresholdIndex = (originalROI.getROIName().equals(VFrap_ROISourceData.VFRAP_ROI_ENUM.ROI_CELL.name()) ? thresholdSliderIntensityLookup.length - newThresholdIndex - 1 : newThresholdIndex);
} else {
for (int i = 0; i < thresholdSliderIntensityLookup.length; i++) {
if (thresholdSliderIntensityLookup[i] >= oldThreshold) {
newThresholdIndex = i;
break;
}
}
}
final int finalNewThresholdIndex = newThresholdIndex;
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// }});
thresholdSlider.setValue(finalNewThresholdIndex);
processTimepointChangeListener.stateChanged(null);
}
});
thresholdSlider.addChangeListener(processTimepointChangeListener);
}
use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class VFrap_ROIAssistPanel method pickKeepRegionInfoFromCurrentROI.
private RegionInfo pickKeepRegionInfoFromCurrentROI() throws Exception {
if (lastRegionInfos == null) {
throw new Exception("No regionInfo to resolve");
}
final Vector<RegionInfo> roiRegionInfoV2 = new Vector<RegionInfo>();
for (int i = 0; i < lastRegionInfos.length; i++) {
if (lastRegionInfos[i].getPixelValue() == 1) {
roiRegionInfoV2.add(lastRegionInfos[i]);
}
}
if (roiRegionInfoV2.size() <= 1) {
throw new Exception("No regionInfo to resolve");
}
final RegionInfo[] regionInfoArr = roiRegionInfoV2.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";
}
ROI beforeROI = new ROI(frapData.getCurrentlyDisplayedROI());
int[] resultArr = null;
// SwingUtilities.invokeAndWait(new Runnable(){public void run(){//}});
try {
resultArr = /*DialogUtils.*/
showComponentOKCancelTableList(this, "Select ROI to Keep", new String[] { "ROI Size (pixel count)" }, rowData, ListSelectionModel.SINGLE_SELECTION, regionInfoArr, beforeROI.getPixelsXYZ());
} catch (UserCancelException e) {
resultArr = null;
}
// }});
if (resultArr != null && resultArr.length > 0) {
return (resultArr == null ? null : regionInfoArr[resultArr[0]]);
} else {
// SwingUtilities.invokeAndWait(new Runnable(){public void run(){//}});
frapData.addReplaceRoi(beforeROI);
applyROIButton.setEnabled(false);
resolveROIButton.setEnabled(true);
fillVoidsButton.setEnabled(false);
// }});
}
return null;
}
use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class VFrap_ROIAssistPanel method resolveCurrentROI.
private void resolveCurrentROI(RegionInfo keepRegion) throws Exception {
short[] removePixels = frapData.getCurrentlyDisplayedROI().getPixelsXYZ();
for (int i = 0; i < removePixels.length; i++) {
if (!keepRegion.isIndexInRegion(i)) {
removePixels[i] = 0;
}
}
final boolean hasInternalVoids = fillVoids(removePixels, true);
UShortImage ushortImage = new UShortImage(removePixels, frapData.getCurrentlyDisplayedROI().getRoiImages()[0].getOrigin(), frapData.getCurrentlyDisplayedROI().getRoiImages()[0].getExtent(), frapData.getCurrentlyDisplayedROI().getISize().getX(), frapData.getCurrentlyDisplayedROI().getISize().getY(), frapData.getCurrentlyDisplayedROI().getISize().getZ());
final ROI newCellROI = new ROI(ushortImage, frapData.getCurrentlyDisplayedROI().getROIName());
SwingUtilities.invokeAndWait(new Runnable() {
public void run() {
// }});
frapData.addReplaceRoi(newCellROI);
applyROIButton.setEnabled(!hasInternalVoids);
resolveROIButton.setEnabled(false);
fillVoidsButton.setEnabled(hasInternalVoids);
}
});
}
use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class AnnotatedImageDataset method setCurrentlyDisplayedROI.
public void setCurrentlyDisplayedROI(ROI argCurrentlyDisplayedROI, boolean bSave) {
ROI oldDisplayedROI = this.currentlyDisplayedROI;
this.currentlyDisplayedROI = argCurrentlyDisplayedROI;
if (bSave) {
propertyChangeSupport.firePropertyChange(PROPERTY_CHANGE_CURRENTLY_DISPLAYED_ROI_WITH_SAVE, oldDisplayedROI, currentlyDisplayedROI);
} else {
propertyChangeSupport.firePropertyChange(PROPERTY_CHANGE_CURRENTLY_DISPLAYED_ROI_WITHOUT_SAVE, oldDisplayedROI, currentlyDisplayedROI);
}
}
use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.
the class MicroscopyXmlReader method getROI.
/**
* This method returns a Biomodel object from a XML Element.
* Creation date: (3/13/2001 12:35:00 PM)
* @param param org.jdom.Element
* @return cbit.vcell.biomodel.BioModel
* @throws XmlParseException
*/
private ROI getROI(Element param) throws XmlParseException {
String roiName = param.getAttributeValue(MicroscopyXMLTags.ROITypeAttrTag);
List<Element> ushortImageElementList = param.getChildren(MicroscopyXMLTags.UShortImageTag);
Iterator<Element> imageElementIter = ushortImageElementList.iterator();
UShortImage[] images = new UShortImage[ushortImageElementList.size()];
int imageIndex = 0;
while (imageElementIter.hasNext()) {
images[imageIndex++] = getUShortImage(imageElementIter.next());
}
ROI roi = new ROI(images, roiName);
return roi;
}
Aggregations