Search in sources :

Example 16 with FloatImage

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

the class GenerateNormalizedPhotoactivationDataOp method generate.

public NormalizedPhotoactivationDataResults generate(ImageTimeSeries<UShortImage> rawImageTimeSeries, ROI backgroundROI_2D, Integer indexPostactivation, boolean backgroundSubtract, boolean normalizedByPreactivation) throws Exception {
    UShortImage preactivationImage = rawImageTimeSeries.getAllImages()[0];
    ISize isize = preactivationImage.getISize();
    int nX = isize.getX();
    int nY = isize.getY();
    int nZ = isize.getZ();
    int numTimes = rawImageTimeSeries.getSizeT();
    Extent extent = preactivationImage.getExtent();
    org.vcell.util.Origin origin = preactivationImage.getOrigin();
    if (indexPostactivation == 0) {
        throw new RuntimeException("no preactivation images found - indexOfFirstPostactivation is 0");
    }
    // 
    // find average "dark count" in background of pre-activation images (for background subtraction)
    // 
    float avgBackground = 0.0f;
    int numPreactivation = indexPostactivation;
    for (int i = 0; i < numPreactivation; i++) {
        avgBackground += getAverage(rawImageTimeSeries.getAllImages()[i], backgroundROI_2D);
    }
    avgBackground /= numPreactivation;
    // 
    // find averaged preactivation image (corrected for background).
    // 
    int numPostactivationImages = numTimes - numPreactivation;
    // holds new averaged image pixels
    float[] preactivationAveragePixels = new float[nX * nY * nZ];
    for (int i = 0; i < numPreactivation; i++) {
        short[] currPreactivationImage = rawImageTimeSeries.getAllImages()[i].getPixels();
        for (int j = 0; j < isize.getXYZ(); j++) {
            float intPixel = 0x0000ffff & ((int) currPreactivationImage[j]);
            preactivationAveragePixels[j] += intPixel / numPreactivation;
        }
    }
    FloatImage preactivationAverageImage = new FloatImage(preactivationAveragePixels, origin, extent, nX, nY, nZ);
    UShortImage firstPostactivationImage = rawImageTimeSeries.getAllImages()[indexPostactivation];
    // 
    // create normalized dataset
    // 
    // normalized postbleach = (origPostbleach - background)/(prebleach - background)
    // 
    FloatImage[] normalizedImages = new FloatImage[numPostactivationImages];
    double[] postactivationTimeStamps = new double[numPostactivationImages];
    for (int i = 0; i < numPostactivationImages; i++) {
        double[] origTimeStamps = rawImageTimeSeries.getImageTimeStamps();
        postactivationTimeStamps[i] = origTimeStamps[indexPostactivation + i] - origTimeStamps[indexPostactivation];
        float[] normalizedPixels = new float[isize.getXYZ()];
        normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
        short[] uncorrectedPixels = rawImageTimeSeries.getAllImages()[i + indexPostactivation].getPixels();
        for (int j = 0; j < isize.getXYZ(); j++) {
            int intUncorrectedPixel = 0x0000ffff & ((int) uncorrectedPixels[j]);
            float background = 0;
            if (backgroundSubtract) {
                background = avgBackground;
            }
            if (normalizedByPreactivation) {
                int intPreactivationAvgPixel = 0x0000ffff & ((int) preactivationAveragePixels[j]);
                normalizedPixels[j] = (intUncorrectedPixel - background) / (Math.max(1, intPreactivationAvgPixel - background));
            } else {
                normalizedPixels[j] = (intUncorrectedPixel - background);
            }
        }
        normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
    }
    ImageTimeSeries<FloatImage> normalizedData = new ImageTimeSeries<FloatImage>(FloatImage.class, normalizedImages, postactivationTimeStamps, nZ);
    NormalizedPhotoactivationDataResults results = new NormalizedPhotoactivationDataResults();
    results.normalizedPhotoactivationData = normalizedData;
    results.preactivationAverageImage = preactivationAverageImage;
    results.normalizedPostactivationImage = normalizedData.getAllImages()[0];
    return results;
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Example 17 with FloatImage

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

the class FitBleachSpotOp method main.

public static void main(String[] args) {
    try {
        int numX = 100;
        int numY = 100;
        double center_i = 52.44;
        double center_j = 51.39;
        double K = 30;
        double high = 0.9;
        double sigma2 = 4;
        float[] pixels = new float[numX * numY];
        Origin origin = new Origin(0, 0, 0);
        Extent extent = new Extent(1, 1, 1);
        FloatImage image = new FloatImage(pixels, origin, extent, numX, numY, 1);
        int index = 0;
        for (int j = 0; j < numY; j++) {
            for (int i = 0; i < numX; i++) {
                double radius = ((i - center_i) * (i - center_i) + (j - center_j) * (j - center_j));
                pixels[index++] = (float) (high - FastMath.exp(-K * FastMath.exp(-radius / sigma2)));
            }
        }
        double init_center_i = 50;
        double init_center_j = 50;
        double init_sigma2 = 2;
        GaussianFitResults fitResults = fitToGaussian(init_center_i, init_center_j, init_sigma2, image);
        System.out.println(fitResults);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Origin(org.vcell.util.Origin) FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) Extent(org.vcell.util.Extent)

Example 18 with FloatImage

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

the class GenerateNormalizedFrapDataOp method generate.

public NormalizedFrapDataResults generate(ImageTimeSeries<UShortImage> rawImageTimeSeries, ROI backgroundROI_2D, Integer indexPostbleach) throws Exception {
    UShortImage firstImage = rawImageTimeSeries.getAllImages()[0];
    ISize isize = firstImage.getISize();
    int nX = isize.getX();
    int nY = isize.getY();
    int nZ = isize.getZ();
    int numTimes = rawImageTimeSeries.getSizeT();
    Extent extent = firstImage.getExtent();
    org.vcell.util.Origin origin = firstImage.getOrigin();
    if (indexPostbleach == 0) {
        throw new RuntimeException("no prebleach images found - indexOfFirstPostbleach is 0");
    }
    // 
    // find average "dark count" in background of pre-bleach images (for background subtraction)
    // 
    float avgBackground = 0.0f;
    int numPrebleach = indexPostbleach;
    for (int i = 0; i < numPrebleach; i++) {
        avgBackground += getAverage(rawImageTimeSeries.getAllImages()[i], backgroundROI_2D);
    }
    avgBackground /= numPrebleach;
    // 
    // find averaged prebleach image (corrected for background).
    // 
    int numPostbleachImages = numTimes - numPrebleach;
    // holds new averaged image pixels
    float[] prebleachAveragePixels = new float[nX * nY * nZ];
    for (int i = 0; i < numPrebleach; i++) {
        short[] currPrebleachImage = rawImageTimeSeries.getAllImages()[i].getPixels();
        for (int j = 0; j < isize.getXYZ(); j++) {
            float intPixel = 0x0000ffff & ((int) currPrebleachImage[j]);
            prebleachAveragePixels[j] += intPixel / numPrebleach;
        }
    }
    FloatImage prebleachAverageImage = new FloatImage(prebleachAveragePixels, origin, extent, nX, nY, nZ);
    // 
    // create normalized dataset
    // 
    // normalized postbleach = (origPostbleach - background)/(prebleach - background)
    // 
    FloatImage[] normalizedImages = new FloatImage[numPostbleachImages];
    double[] postbleachTimeStamps = new double[numPostbleachImages];
    for (int i = 0; i < numPostbleachImages; i++) {
        double[] origTimeStamps = rawImageTimeSeries.getImageTimeStamps();
        postbleachTimeStamps[i] = origTimeStamps[indexPostbleach + i] - origTimeStamps[indexPostbleach];
        float[] normalizedPixels = new float[isize.getXYZ()];
        normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
        short[] uncorrectedPixels = rawImageTimeSeries.getAllImages()[i + indexPostbleach].getPixels();
        for (int j = 0; j < isize.getXYZ(); j++) {
            int intPixel = 0x0000ffff & ((int) uncorrectedPixels[j]);
            normalizedPixels[j] = (intPixel - avgBackground) / (Math.max(1, prebleachAveragePixels[j] - avgBackground));
        }
        normalizedImages[i] = new FloatImage(normalizedPixels, origin, extent, nX, nY, nZ);
    }
    ImageTimeSeries<FloatImage> normalizedData = new ImageTimeSeries<FloatImage>(FloatImage.class, normalizedImages, postbleachTimeStamps, nZ);
    NormalizedFrapDataResults results = new NormalizedFrapDataResults();
    results.normalizedFrapData = normalizedData;
    results.prebleachAverage = prebleachAverageImage;
    return results;
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Aggregations

FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)18 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)6 Extent (org.vcell.util.Extent)6 ROI (cbit.vcell.VirtualMicroscopy.ROI)5 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)5 ISize (org.vcell.util.ISize)4 Origin (org.vcell.util.Origin)4 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)4 ComputeMeasurementErrorOp (org.vcell.vmicro.op.ComputeMeasurementErrorOp)3 NormalizedSampleFunction (org.vcell.vmicro.workflow.data.NormalizedSampleFunction)3 SimDataBlock (cbit.vcell.simdata.SimDataBlock)2 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)2 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)2 File (java.io.File)2 KeyValue (org.vcell.util.document.KeyValue)2 User (org.vcell.util.document.User)2 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)2 FitBleachSpotOp (org.vcell.vmicro.op.FitBleachSpotOp)2 FitBleachSpotOpResults (org.vcell.vmicro.op.FitBleachSpotOp.FitBleachSpotOpResults)2 Generate2DOptContextOp (org.vcell.vmicro.op.Generate2DOptContextOp)2