Search in sources :

Example 1 with ImageStatistics

use of cbit.vcell.VirtualMicroscopy.Image.ImageStatistics in project vcell by virtualcell.

the class ROIMultiPaintManager method calculateAllPixelValuesRangeChannels0.

private static OverlayEditorPanelJAI.AllPixelValuesRange[] calculateAllPixelValuesRangeChannels0(ImageDataset[] sourceImageDatasetChannels) {
    OverlayEditorPanelJAI.AllPixelValuesRange[] pixelValuesRangeChannels = new OverlayEditorPanelJAI.AllPixelValuesRange[sourceImageDatasetChannels.length];
    for (int c = 0; c < sourceImageDatasetChannels.length; c++) {
        UShortImage[] allImages = sourceImageDatasetChannels[c].getAllImages();
        double min = 0;
        double max = min;
        for (int i = 0; i < allImages.length; i++) {
            ImageStatistics imageStats = allImages[i].getImageStatistics();
            if (i == 0 || imageStats.minValue < min) {
                min = imageStats.minValue;
            }
            if (i == 0 || imageStats.maxValue > max) {
                max = imageStats.maxValue;
            }
        }
        pixelValuesRangeChannels[c] = new OverlayEditorPanelJAI.AllPixelValuesRange((int) min, (int) max);
    }
    return pixelValuesRangeChannels;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Point(java.awt.Point)

Example 2 with ImageStatistics

use of cbit.vcell.VirtualMicroscopy.Image.ImageStatistics in project vcell by virtualcell.

the class GenerateCellROIsFromRawFrapTimeSeriesOp method generate.

public GeometryRoisAndBleachTiming generate(ImageTimeSeries rawTimeSeriesImages, double cellThreshold) throws Exception {
    Image[] allImages = rawTimeSeriesImages.getAllImages();
    int numPixels = allImages[0].getNumXYZ();
    int numTimes = allImages.length;
    ImageStatistics[] imageStats = new ImageStatistics[numTimes];
    for (int i = 0; i < numTimes; i++) {
        imageStats[i] = allImages[i].getImageStatistics();
    }
    // 
    // find largest change in fluorescence (ratio of total[n]/total[n+1]
    // 
    int indexPostbleach = -1;
    double largestRatio = 0.0;
    for (int tIndex = 0; tIndex < numTimes - 1; tIndex++) {
        double currentRatio = imageStats[tIndex].meanValue / imageStats[tIndex + 1].meanValue;
        if (currentRatio > largestRatio) {
            largestRatio = currentRatio;
            indexPostbleach = tIndex + 1;
        }
    }
    double[] firstImagePixels = allImages[0].getDoublePixels();
    short[] scaledCellDataShort = new short[numPixels];
    short[] scaledBackgoundDataShort = new short[numPixels];
    short[] wholeDomainDataShort = new short[numPixels];
    // 
    // find cell and background by thresholding the first image
    // 
    double cellThresholdValue = cellThreshold * imageStats[0].maxValue;
    for (int j = 0; j < numPixels; j++) {
        boolean isCell = firstImagePixels[j] > cellThresholdValue;
        if (isCell) {
            scaledCellDataShort[j] = 1;
        } else {
            scaledBackgoundDataShort[j] = 1;
        }
    }
    UShortImage cellImage = new UShortImage(scaledCellDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    Arrays.fill(wholeDomainDataShort, (short) 1);
    UShortImage wholeDomainImage = new UShortImage(wholeDomainDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage reverseCell = UShortImage.fastDilate(cellImage, 15, wholeDomainImage);
    reverseCell.reverse();
    reverseCell.and(backgroundImage);
    backgroundImage = reverseCell;
    ROI cellROI = new ROI(cellImage, "cellROI");
    ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
    GeometryRoisAndBleachTiming results = new GeometryRoisAndBleachTiming();
    results.cellROI_2D = cellROI;
    results.backgroundROI_2D = backgroundROI;
    results.indexOfFirstPostbleach = indexPostbleach;
    return results;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Image(cbit.vcell.VirtualMicroscopy.Image) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 3 with ImageStatistics

use of cbit.vcell.VirtualMicroscopy.Image.ImageStatistics in project vcell by virtualcell.

the class GenerateCellROIsFromRawPhotoactivationTimeSeriesOp method generate.

public GeometryRoisAndActivationTiming generate(ImageTimeSeries rawTimeSeriesImages, double cellThreshold) throws Exception {
    Image[] allImages = rawTimeSeriesImages.getAllImages();
    int numPixels = allImages[0].getNumXYZ();
    int numTimes = allImages.length;
    ImageStatistics[] imageStats = new ImageStatistics[numTimes];
    for (int i = 0; i < numTimes; i++) {
        imageStats[i] = allImages[i].getImageStatistics();
    }
    // 
    // find largest change in fluorescence (ratio of total[n+1]/total[n]
    // 
    int indexPostactivation = -1;
    double largestRatio = 0.0;
    for (int tIndex = 0; tIndex < numTimes - 1; tIndex++) {
        double currentRatio = imageStats[tIndex + 1].meanValue / imageStats[tIndex].meanValue;
        if (currentRatio > largestRatio) {
            largestRatio = currentRatio;
            indexPostactivation = tIndex + 1;
        }
    }
    double[] firstImagePixels = allImages[0].getDoublePixels();
    short[] scaledCellDataShort = new short[numPixels];
    short[] scaledBackgoundDataShort = new short[numPixels];
    short[] wholeDomainDataShort = new short[numPixels];
    // 
    // find cell and background by thresholding the first image
    // 
    double cellThresholdValue = cellThreshold * imageStats[0].maxValue;
    for (int j = 0; j < numPixels; j++) {
        boolean isCell = firstImagePixels[j] > cellThresholdValue;
        if (isCell) {
            scaledCellDataShort[j] = 1;
        } else {
            scaledBackgoundDataShort[j] = 1;
        }
    }
    UShortImage cellImage = new UShortImage(scaledCellDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    Arrays.fill(wholeDomainDataShort, (short) 1);
    UShortImage wholeDomainImage = new UShortImage(wholeDomainDataShort, allImages[0].getOrigin(), allImages[0].getExtent(), allImages[0].getNumX(), allImages[0].getNumY(), allImages[0].getNumZ());
    UShortImage reverseCell = UShortImage.fastDilate(cellImage, 10, wholeDomainImage);
    reverseCell.reverse();
    reverseCell.and(backgroundImage);
    backgroundImage = reverseCell;
    cellImage = new UShortImage(backgroundImage);
    cellImage.reverse();
    ROI cellROI = new ROI(cellImage, "cellROI");
    ROI backgroundROI = new ROI(backgroundImage, "backgroundROI");
    GeometryRoisAndActivationTiming results = new GeometryRoisAndActivationTiming();
    results.cellROI_2D = cellROI;
    results.backgroundROI_2D = backgroundROI;
    results.indexOfFirstPostactivation = indexPostactivation;
    return results;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Image(cbit.vcell.VirtualMicroscopy.Image) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 4 with ImageStatistics

use of cbit.vcell.VirtualMicroscopy.Image.ImageStatistics in project vcell by virtualcell.

the class VFrap_OverlayEditorPanelJAI method calcMinMaxPixelValueRange.

private Range calcMinMaxPixelValueRange(ImageDataset argImageDataset) {
    UShortImage[] allImages = argImageDataset.getAllImages();
    double min = 0;
    double max = min;
    for (int i = 0; i < allImages.length; i++) {
        ImageStatistics imageStats = allImages[i].getImageStatistics();
        if (i == 0 || imageStats.minValue < min) {
            min = imageStats.minValue;
        }
        if (i == 0 || imageStats.maxValue > max) {
            max = imageStats.maxValue;
        }
    }
    if (max < SHORT_TO_BYTE_FACTOR) {
        return new Range(min, max);
    }
    return new Range(min / SHORT_TO_BYTE_FACTOR, max / SHORT_TO_BYTE_FACTOR);
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Range(org.vcell.util.Range) Point(java.awt.Point)

Example 5 with ImageStatistics

use of cbit.vcell.VirtualMicroscopy.Image.ImageStatistics in project vcell by virtualcell.

the class VFrap_OverlayEditorPanelJAI method createUnderlyingImage.

/**
 * Method createUnderlyingImage.
 * @param image UShortImage
 * @return BufferedImage
 */
private BufferedImage createUnderlyingImage(UShortImage image) {
    int[] cmap = new int[256];
    // colormap (grayscale)
    for (int i = 0; i < 256; i += 1) {
        int iv = (0x000000FF & i);
        cmap[i] = 0xFF000000 | iv << 16 | iv << 8 | i;
    }
    IndexColorModel indexColorModel = new java.awt.image.IndexColorModel(8, cmap.length, cmap, 0, false, /*false means NOT USE alpha*/
    -1, /*NO transparent single pixel*/
    java.awt.image.DataBuffer.TYPE_BYTE);
    int width = image.getNumX();
    int height = image.getNumY();
    ImageStatistics imageStats = image.getImageStatistics();
    short[] pixels = image.getPixels();
    BufferedImage underImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
    byte[] byteData = ((DataBufferByte) underImage.getRaster().getDataBuffer()).getData();
    for (int i = 0; i < byteData.length; i++) {
        byteData[i] = (imageStats.maxValue < SHORT_TO_BYTE_FACTOR ? (byte) pixels[i] : (byte) (((pixels[i] & 0x0000FFFF)) / SHORT_TO_BYTE_FACTOR));
    }
    return underImage;
}
Also used : ImageStatistics(cbit.vcell.VirtualMicroscopy.Image.ImageStatistics) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

ImageStatistics (cbit.vcell.VirtualMicroscopy.Image.ImageStatistics)7 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)4 Point (java.awt.Point)3 Image (cbit.vcell.VirtualMicroscopy.Image)2 ROI (cbit.vcell.VirtualMicroscopy.ROI)2 BufferedImage (java.awt.image.BufferedImage)1 DataBufferByte (java.awt.image.DataBufferByte)1 IndexColorModel (java.awt.image.IndexColorModel)1 Range (org.vcell.util.Range)1