use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FRAPData method chopImages.
public void chopImages(int startTimeIndex, int endTimeIndex) {
UShortImage[] origImages = getImageDataset().getAllImages();
double[] origTimeSteps = getImageDataset().getImageTimeStamps();
int numOfZ = getImageDataset().getSizeZ();
int numOfC = getImageDataset().getSizeC();
int tolImgLen = (endTimeIndex - startTimeIndex + 1) * numOfZ * numOfC;
UShortImage[] newImages = new UShortImage[tolImgLen];
double[] newTimeSteps = new double[endTimeIndex - startTimeIndex + 1];
System.arraycopy(origImages, startTimeIndex * numOfZ * numOfC, newImages, 0, tolImgLen);
System.arraycopy(origTimeSteps, startTimeIndex, newTimeSteps, 0, (endTimeIndex - startTimeIndex + 1));
// shift time to start from 0, it's not necessary
// double firstTimePoint = newTimeSteps[0];
// for(int i = 0; i < newTimeSteps.length; i++)
// {
// newTimeSteps[i] = newTimeSteps[i] - firstTimePoint;
// }
ImageDataset imgDataset = new ImageDataset(newImages, newTimeSteps, numOfZ);
setImageDataset(imgDataset);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FRAPData method refreshDependentROIs.
protected void refreshDependentROIs() {
UShortImage cellROI_2D = null;
UShortImage bleachedROI_2D = null;
UShortImage dilatedROI_2D_1 = null;
UShortImage dilatedROI_2D_2 = null;
UShortImage dilatedROI_2D_3 = null;
UShortImage dilatedROI_2D_4 = null;
UShortImage dilatedROI_2D_5 = null;
UShortImage erodedROI_2D_0 = null;
UShortImage erodedROI_2D_1 = null;
UShortImage erodedROI_2D_2 = null;
try {
cellROI_2D = convertToUShortImage(binarize(getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getRoiImages()[0]), getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getRoiImages()[0].getOrigin(), getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getRoiImages()[0].getExtent());
bleachedROI_2D = convertToUShortImage(AndDescriptor.create(binarize(getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getRoiImages()[0]), binarize(cellROI_2D), null).createInstance(), getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getRoiImages()[0].getOrigin(), getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getRoiImages()[0].getExtent());
// writeUShortFile(cellROI_2D, new File("D:\\developer\\eclipse\\workspace\\cellROI_2D.bmp"));
// writeUShortFile(bleachedROI_2D, new File("D:\\developer\\eclipse\\workspace\\bleachedROI_2D.bmp"));
dilatedROI_2D_1 = fastDilate(bleachedROI_2D, 4, cellROI_2D);
// erodeDilate(bleachedROI_2D, createCircularBinaryKernel(8), cellROI_2D,false);
dilatedROI_2D_2 = fastDilate(bleachedROI_2D, 10, cellROI_2D);
// erodeDilate(bleachedROI_2D, createCircularBinaryKernel(16), cellROI_2D,false);
dilatedROI_2D_3 = fastDilate(bleachedROI_2D, 18, cellROI_2D);
// erodeDilate(bleachedROI_2D, createCircularBinaryKernel(24), cellROI_2D,false);
dilatedROI_2D_4 = fastDilate(bleachedROI_2D, 28, cellROI_2D);
// erodeDilate(bleachedROI_2D, createCircularBinaryKernel(32), cellROI_2D,false);
dilatedROI_2D_5 = fastDilate(bleachedROI_2D, 40, cellROI_2D);
// erodeDilate(bleachedROI_2D, createCircularBinaryKernel(40), cellROI_2D,false);
erodedROI_2D_0 = new UShortImage(bleachedROI_2D);
// The erode always causes problems if eroding without checking the bleached length and hight.
// we have to check the min length of the bleahed area to make sure erode within the length.
Rectangle bleachRect = bleachedROI_2D.getNonzeroBoundingBox();
int minLen = Math.min(bleachRect.height, bleachRect.width);
if ((minLen / 2.0) < 5) {
erodedROI_2D_1 = erodeDilate(bleachedROI_2D, createCircularBinaryKernel(1), bleachedROI_2D, true);
erodedROI_2D_2 = erodeDilate(bleachedROI_2D, createCircularBinaryKernel(2), bleachedROI_2D, true);
} else {
erodedROI_2D_1 = erodeDilate(bleachedROI_2D, createCircularBinaryKernel(2), bleachedROI_2D, true);
erodedROI_2D_2 = erodeDilate(bleachedROI_2D, createCircularBinaryKernel(5), bleachedROI_2D, true);
}
UShortImage reverseErodeROI_2D_1 = new UShortImage(erodedROI_2D_1);
reverseErodeROI_2D_1.reverse();
erodedROI_2D_0.and(reverseErodeROI_2D_1);
UShortImage reverseErodeROI_2D_2 = new UShortImage(erodedROI_2D_2);
reverseErodeROI_2D_2.reverse();
erodedROI_2D_1.and(reverseErodeROI_2D_2);
UShortImage reverseDilateROI_2D_4 = new UShortImage(dilatedROI_2D_4);
reverseDilateROI_2D_4.reverse();
dilatedROI_2D_5.and(reverseDilateROI_2D_4);
UShortImage reverseDilateROI_2D_3 = new UShortImage(dilatedROI_2D_3);
// writeUShortFile(dilatedROI_2D_3, new File("D:\\developer\\eclipse\\workspace\\dilatedROI_2D_3.bmp"));
reverseDilateROI_2D_3.reverse();
// writeUShortFile(reverseDilateROI_2D_3, new File("D:\\developer\\eclipse\\workspace\\dilatedROI_2D_3_reverse.bmp"));
// writeUShortFile(dilatedROI_2D_4, new File("D:\\developer\\eclipse\\workspace\\dilatedROI_2D_4.bmp"));
dilatedROI_2D_4.and(reverseDilateROI_2D_3);
// writeUShortFile(dilatedROI_2D_4, new File("D:\\developer\\eclipse\\workspace\\dilatedROI_2D_4_anded.bmp"));
UShortImage reverseDilateROI_2D_2 = new UShortImage(dilatedROI_2D_2);
reverseDilateROI_2D_2.reverse();
dilatedROI_2D_3.and(reverseDilateROI_2D_2);
UShortImage reverseDilateROI_2D_1 = new UShortImage(dilatedROI_2D_1);
reverseDilateROI_2D_1.reverse();
dilatedROI_2D_2.and(reverseDilateROI_2D_1);
UShortImage reverseBleach_2D = new UShortImage(bleachedROI_2D);
reverseBleach_2D.reverse();
dilatedROI_2D_1.and(reverseBleach_2D);
} catch (ImageException e) {
e.printStackTrace(System.out);
}
ROI roiBleachedRing1_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name());
if (roiBleachedRing1_2D == null) {
roiBleachedRing1_2D = new ROI(erodedROI_2D_2, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name());
addReplaceRoi(roiBleachedRing1_2D);
} else {
System.arraycopy(erodedROI_2D_2.getPixels(), 0, roiBleachedRing1_2D.getRoiImages()[0].getPixels(), 0, erodedROI_2D_2.getPixels().length);
}
ROI roiBleachedRing2_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING2.name());
if (roiBleachedRing2_2D == null) {
roiBleachedRing2_2D = new ROI(erodedROI_2D_1, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING2.name());
addReplaceRoi(roiBleachedRing2_2D);
} else {
System.arraycopy(erodedROI_2D_1.getPixels(), 0, roiBleachedRing2_2D.getRoiImages()[0].getPixels(), 0, erodedROI_2D_1.getPixels().length);
}
ROI roiBleachedRing3_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING3.name());
if (roiBleachedRing3_2D == null) {
roiBleachedRing3_2D = new ROI(erodedROI_2D_0, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING3.name());
addReplaceRoi(roiBleachedRing3_2D);
} else {
System.arraycopy(erodedROI_2D_0.getPixels(), 0, roiBleachedRing3_2D.getRoiImages()[0].getPixels(), 0, erodedROI_2D_0.getPixels().length);
}
ROI roiBleachedRing4_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING4.name());
if (roiBleachedRing4_2D == null) {
roiBleachedRing4_2D = new ROI(dilatedROI_2D_1, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING4.name());
addReplaceRoi(roiBleachedRing4_2D);
} else {
System.arraycopy(dilatedROI_2D_1.getPixels(), 0, roiBleachedRing4_2D.getRoiImages()[0].getPixels(), 0, dilatedROI_2D_1.getPixels().length);
}
ROI roiBleachedRing5_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING5.name());
if (roiBleachedRing5_2D == null) {
roiBleachedRing5_2D = new ROI(dilatedROI_2D_2, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING5.name());
addReplaceRoi(roiBleachedRing5_2D);
} else {
System.arraycopy(dilatedROI_2D_2.getPixels(), 0, roiBleachedRing5_2D.getRoiImages()[0].getPixels(), 0, dilatedROI_2D_2.getPixels().length);
}
ROI roiBleachedRing6_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING6.name());
if (roiBleachedRing6_2D == null) {
roiBleachedRing6_2D = new ROI(dilatedROI_2D_3, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING6.name());
addReplaceRoi(roiBleachedRing6_2D);
} else {
System.arraycopy(dilatedROI_2D_3.getPixels(), 0, roiBleachedRing6_2D.getRoiImages()[0].getPixels(), 0, dilatedROI_2D_3.getPixels().length);
}
ROI roiBleachedRing7_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING7.name());
if (roiBleachedRing7_2D == null) {
roiBleachedRing7_2D = new ROI(dilatedROI_2D_4, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING7.name());
addReplaceRoi(roiBleachedRing7_2D);
} else {
System.arraycopy(dilatedROI_2D_4.getPixels(), 0, roiBleachedRing7_2D.getRoiImages()[0].getPixels(), 0, dilatedROI_2D_4.getPixels().length);
}
ROI roiBleachedRing8_2D = getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING8.name());
if (roiBleachedRing8_2D == null) {
roiBleachedRing8_2D = new ROI(dilatedROI_2D_5, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING8.name());
addReplaceRoi(roiBleachedRing8_2D);
} else {
System.arraycopy(dilatedROI_2D_5.getPixels(), 0, roiBleachedRing8_2D.getRoiImages()[0].getPixels(), 0, dilatedROI_2D_5.getPixels().length);
}
}
use of cbit.vcell.VirtualMicroscopy.UShortImage 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();
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class VFrap_ROIAssistPanel method createScaledTimeAverageData.
private void createScaledTimeAverageData() throws Exception {
int numTimes = frapData.getImageDataset().getSizeT();
long[] timeSum = new long[frapData.getImageDataset().getISize().getXYZ()];
for (int t = 0; t < numTimes; t++) {
int pixelIndex = 0;
for (int z = 0; z < frapData.getImageDataset().getSizeZ(); z++) {
UShortImage timePointDataImage = frapData.getImageDataset().getImage(z, 0, t);
for (int y = 0; y < timePointDataImage.getNumY(); y++) {
for (int x = 0; x < timePointDataImage.getNumX(); x++) {
timeSum[pixelIndex] += timePointDataImage.getPixel(x, y, 0) & 0x0000FFFF;
pixelIndex++;
}
}
}
}
roiTimeAverageDataShort = new short[timeSum.length];
for (int i = 0; i < timeSum.length; i++) {
roiTimeAverageDataShort[i] |= ((int) (timeSum[i] / numTimes)) & 0x0000FFFF;
}
scaleDataInPlace(roiTimeAverageDataShort);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage 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();
}
Aggregations