use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class NormalizedSampleFunction method toROI.
public ROI toROI(double threshold) {
short[] pixels = sampleImage.getBinaryPixels((float) threshold);
UShortImage roiImage;
try {
roiImage = new UShortImage(pixels, getOrigin(), getExtent(), getISize().getX(), getISize().getY(), 1);
} catch (ImageException e) {
e.printStackTrace();
throw new RuntimeException("failed to create image: " + e.getMessage(), e);
}
ROI roi = new ROI(roiImage, getName());
return roi;
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class NormalizedSampleFunction method fromROI.
public static NormalizedSampleFunction fromROI(ROI roi) throws ImageException {
if (roi.getISize().getZ() > 1) {
throw new RuntimeException("ROISampleFunction doesn't yet support 3D ROIs");
}
float[] normalizedPixels = new float[roi.getISize().getXYZ()];
int nonzeroPixelCount = roi.getNonzeroPixelsCount();
if (nonzeroPixelCount == 0) {
throw new RuntimeException("empty ROI \"" + roi.getROIName() + "\"");
}
float pixelValue = 1.0f;
for (int i = 0; i < normalizedPixels.length; i++) {
if (roi.getRoiImages()[0].getPixels()[i] > 0) {
normalizedPixels[i] = pixelValue;
}
}
UShortImage roiImage = roi.getRoiImages()[0];
FloatImage sample = new FloatImage(normalizedPixels, roiImage.getOrigin(), roiImage.getExtent(), roi.getISize().getX(), roi.getISize().getY(), roi.getISize().getZ());
return new NormalizedSampleFunction(roi.getROIName(), sample);
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FRAPSingleWorkspace method updateImages.
public void updateImages(DataVerifyInfo dataVerifyInfo) {
FRAPData fData = null;
FRAPStudy fStudy = getWorkingFrapStudy();
if (fStudy != null && fStudy.getFrapData() != null) {
fData = fStudy.getFrapData();
}
// set verify info
if (fData != null) {
ImageDataset oldImageSet = fData.getImageDataset();
UShortImage[] images = oldImageSet.getAllImages();
boolean isChanged = false;
if (dataVerifyInfo.getStartTimeIndex() > 0 || dataVerifyInfo.getEndTimeIndex() < (images.length - 1)) {
fData.chopImages(dataVerifyInfo.getStartTimeIndex(), dataVerifyInfo.getEndTimeIndex());
isChanged = true;
}
if (dataVerifyInfo.getImageSizeX() != images[0].getExtent().getX() || dataVerifyInfo.getImageSizeY() != images[0].getExtent().getY()) {
fData.changeImageExtent(dataVerifyInfo.getImageSizeX(), dataVerifyInfo.getImageSizeY());
isChanged = true;
}
if (isChanged) {
firePropertyChange(FRAPDATA_VERIFY_INFO_PROPERTY, null, fData);
}
}
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class NonGUIFRAPTest method checkExternalDataSameAsOriginal.
private static void checkExternalDataSameAsOriginal(FRAPStudy frapStudy, String testDirectoryPath) throws Exception {
ImageDataset imageDataset = frapStudy.getFrapData().getImageDataset();
ROI cellROI = frapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name());
ROI bleachROI = frapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name());
ROI backgroundROI = frapStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name());
// FileInputStream fis = new FileInputStream(getCanonicalFilename(testDirectoryPath, null));
// BufferedInputStream bis = new BufferedInputStream(fis);
// ZipInputStream zis = new ZipInputStream(bis);
// ZipEntry zipEntry = null;
// int timeIndex = 0;
// while((zipEntry =zis.getNextEntry()) != null){
// byte[] timePointData = new byte[(int)zipEntry.getSize()];
// int offset = 0;
// while((offset+= zis.read(timePointData,offset,timePointData.length-offset)) != timePointData.length){}
// short[] shortPixels = imageDataset.getImage(0, 0, timeIndex).getPixels();
// checkPixels(shortPixels, timePointData);
// timeIndex++;
// }
// zis.close();
ExternalDataFileContents extDataFileContents = readExternalDataContents(getCanonicalFilename(testDirectoryPath, null).getAbsolutePath(), getCanonicalFilename(testDirectoryPath, FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getAbsolutePath(), getCanonicalFilename(testDirectoryPath, FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getAbsolutePath(), getCanonicalFilename(testDirectoryPath, FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).getAbsolutePath());
ImageDataset imageData = extDataFileContents.imageData;
UShortImage[] allIDiskmages = imageData.getAllImages();
UShortImage[] allIFrapmages = imageDataset.getAllImages();
if (allIDiskmages.length != allIFrapmages.length) {
throw new Exception("different number of times");
}
for (int i = 0; i < allIDiskmages.length; i++) {
short[] allDiskPixels = allIDiskmages[i].getPixels();
short[] allFrapPixels = allIFrapmages[i].getPixels();
checkPixels(allDiskPixels, allFrapPixels);
}
checkPixels(extDataFileContents.cellROIData.getPixelsZ(0, 0), cellROI.getPixelsXYZ());
checkPixels(extDataFileContents.bleachROIData.getPixelsZ(0, 0), bleachROI.getPixelsXYZ());
checkPixels(extDataFileContents.backgroundROIData.getPixelsZ(0, 0), backgroundROI.getPixelsXYZ());
}
use of cbit.vcell.VirtualMicroscopy.UShortImage in project vcell by virtualcell.
the class FrapDataUtils method importFRAPDataFromVCellSimulationData.
public static FRAPData importFRAPDataFromVCellSimulationData(File vcellSimLogFile, String variableName, String bleachedMaskVarName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
// bleachedMaskVarName = "laserMask_cell";
VCSimulationIdentifier vcSimulationIdentifier = getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
DataSetControllerImpl dataSetControllerImpl = getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
final DataJobEvent[] bStatus = new DataJobEvent[] { null };
DataJobListener dataJobListener = new DataJobListener() {
public void dataJobMessage(DataJobEvent event) {
bStatus[0] = event;
if (progressListener != null) {
progressListener.setProgress((int) (event.getProgress() / 100.0 * .75));
}
}
};
dataSetControllerImpl.addDataJobListener(dataJobListener);
DataIdentifier[] dataIdentifiers = getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
DataIdentifier variableNameDataIdentifier = null;
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getName().equals(variableName)) {
variableNameDataIdentifier = dataIdentifiers[i];
break;
}
}
if (variableNameDataIdentifier == null) {
throw new IllegalArgumentException("Variable " + variableName + " not found.");
}
if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
throw new IllegalArgumentException("Variable " + variableName + " is not VOLUME type.");
}
double[] times = dataSetControllerImpl.getDataSetTimes(vcSimulationDataIdentifier);
CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
BitSet allBitset = new BitSet(cartesianMesh.getNumVolumeElements());
allBitset.set(0, cartesianMesh.getNumVolumeElements() - 1);
TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { variableName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(getDotUser(), true));
TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) dataSetControllerImpl.getTimeSeriesValues(null, vcSimulationDataIdentifier, timeSeriesJobSpec);
// wait for job to finish
while (bStatus[0] == null || bStatus[0].getEventTypeID() != DataJobEvent.DATA_COMPLETE) {
Thread.sleep(100);
}
double allTimesMin = tsJobResultsSpaceStats.getMinimums()[0][0];
double allTimesMax = allTimesMin;
for (int i = 0; i < times.length; i++) {
allTimesMin = Math.min(allTimesMin, tsJobResultsSpaceStats.getMinimums()[0][i]);
allTimesMax = Math.max(allTimesMax, tsJobResultsSpaceStats.getMaximums()[0][i]);
}
// double SCALE_MAX = maxIntensity.doubleValue();/*Math.pow(2,16)-1;*///Scale to 16 bits
double linearScaleFactor = 1;
if (maxIntensity != null) {
linearScaleFactor = maxIntensity.doubleValue() / allTimesMax;
}
System.out.println("alltimesMin=" + allTimesMin + " allTimesMax=" + allTimesMax + " linearScaleFactor=" + linearScaleFactor);
UShortImage[] scaledDataImages = new UShortImage[times.length];
Random rnd = new Random();
int shortMax = 65535;
// set messge to load variable
if (progressListener != null) {
progressListener.setMessage("Loading variable " + variableName + "...");
}
for (int i = 0; i < times.length; i++) {
double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, variableName, times[i]).getData();
short[] scaledDataShort = new short[rawData.length];
for (int j = 0; j < scaledDataShort.length; j++) {
double scaledRawDataJ = rawData[j] * linearScaleFactor;
if (bNoise) {
double ran = rnd.nextGaussian();
double scaledRawDataJ_withNoise = Math.max(0, (scaledRawDataJ + ran * Math.sqrt(scaledRawDataJ)));
scaledRawDataJ_withNoise = Math.min(shortMax, scaledRawDataJ_withNoise);
int scaledValue = (int) (scaledRawDataJ_withNoise);
scaledDataShort[j] &= 0x0000;
scaledDataShort[j] |= 0x0000FFFF & scaledValue;
} else {
int scaledValue = (int) (scaledRawDataJ);
scaledDataShort[j] &= 0x0000;
scaledDataShort[j] |= 0x0000FFFF & scaledValue;
}
}
scaledDataImages[i] = new UShortImage(scaledDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
if (progressListener != null) {
int progress = (int) (((i + 1) * 1.0 / times.length) * 100);
progressListener.setProgress(progress);
}
}
ImageDataset imageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
FRAPData frapData = new FRAPData(imageDataSet, new String[] { FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name() });
// get rois from log file
if (bleachedMaskVarName != null) {
// set message to load cell ROI variable
if (progressListener != null) {
progressListener.setMessage("Loading ROIs...");
}
double[] rawROIBleached = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, bleachedMaskVarName, 0).getData();
short[] scaledCellDataShort = new short[rawROIBleached.length];
short[] scaledBleachedDataShort = new short[rawROIBleached.length];
short[] scaledBackgoundDataShort = new short[rawROIBleached.length];
for (int j = 0; j < scaledCellDataShort.length; j++) {
boolean isCell = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume1");
boolean isBackground = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume0");
if (isCell) {
scaledCellDataShort[j] = 1;
}
if (isBackground) {
scaledBackgoundDataShort[j] = 1;
}
if (rawROIBleached[j] > 0.2) {
scaledBleachedDataShort[j] = 1;
}
}
UShortImage cellImage = new UShortImage(scaledCellDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
if (progressListener != null) {
progressListener.setProgress(100);
}
frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).setROIImages(new UShortImage[] { cellImage });
frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).setROIImages(new UShortImage[] { bleachedImage });
frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).setROIImages(new UShortImage[] { backgroundImage });
}
return frapData;
}
Aggregations