Search in sources :

Example 1 with UShortImage

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;
}
Also used : ImageException(cbit.image.ImageException) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 2 with UShortImage

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);
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 3 with UShortImage

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);
        }
    }
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 4 with UShortImage

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());
}
Also used : ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 5 with UShortImage

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;
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) FRAPData(cbit.vcell.microscopy.FRAPData) BitSet(java.util.BitSet) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataJobEvent(cbit.rmi.event.DataJobEvent) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Random(java.util.Random) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataJobListener(cbit.rmi.event.DataJobListener)

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