Search in sources :

Example 6 with ImageException

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

Example 7 with ImageException

use of cbit.image.ImageException in project vcell by virtualcell.

the class ByteImage method getPixelsCompressed.

/**
 * This method was created in VisualAge.
 * @return byte[]
 */
public byte[] getPixelsCompressed() throws ImageException {
    try {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        DeflaterOutputStream dos = new DeflaterOutputStream(bos);
        // DeflaterOutputStream dos = new DeflaterOutputStream(bos,new Deflater(5,false));
        dos.write(pixels, 0, pixels.length);
        dos.close();
        return bos.toByteArray();
    } catch (IOException e) {
        e.printStackTrace(System.out);
        throw new ImageException(e.getMessage());
    }
}
Also used : ImageException(cbit.image.ImageException) DeflaterOutputStream(java.util.zip.DeflaterOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Example 8 with ImageException

use of cbit.image.ImageException in project vcell by virtualcell.

the class Image method crop.

static Image crop(Image origImage, Rectangle rect) throws ImageException {
    Object inArray = origImage.getPixelArray();
    Object outArray = Array.newInstance(inArray.getClass().getComponentType(), rect.width * rect.height * origImage.getNumZ());
    for (int k = 0; k < origImage.getNumZ(); k++) {
        for (int j = 0; j < rect.height; j++) {
            for (int i = 0; i < rect.width; i++) {
                int inIndex = rect.x + i + (j + rect.y) * origImage.getNumX() + k * origImage.getNumX() * origImage.getNumY();
                int outIndex = i + j * rect.width + (k * rect.width * rect.height);
                Array.set(outArray, outIndex, Array.get(inArray, inIndex));
            }
        }
    }
    Extent croppedExtent = null;
    if (origImage.getExtent() != null) {
        croppedExtent = new Extent(origImage.getExtent().getX() * rect.width / origImage.getNumX(), origImage.getExtent().getY() * rect.height / origImage.getNumY(), origImage.getExtent().getZ());
    }
    Origin croppedOrigin = null;
    if (origImage.getOrigin() != null) {
        croppedOrigin = new Origin(calcOriginPosition(origImage.getOrigin().getX(), rect.x, origImage.getExtent().getX(), origImage.getNumX()), calcOriginPosition(origImage.getOrigin().getY(), rect.y, origImage.getExtent().getY(), origImage.getNumY()), // origImage.getOrigin().getY()+(rect.y*(origImage.getExtent().getY()/origImage.getNumY())),
        origImage.getExtent().getZ());
    }
    if (origImage instanceof UShortImage) {
        return new UShortImage((short[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    } else if (origImage instanceof ByteImage) {
        return new ByteImage((byte[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    } else if (origImage instanceof FloatImage) {
        return new FloatImage((float[]) outArray, croppedOrigin, croppedExtent, rect.width, rect.height, origImage.getNumZ());
    }
    throw new ImageException("Crop if Image type " + origImage.getClass().getName() + " not implemented.");
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent)

Example 9 with ImageException

use of cbit.image.ImageException in project vcell by virtualcell.

the class RegionImage method calculateRegions_New.

// 
// Calculate regions using single pass algorithm.  Creates information
// used to generate surfaces as well
// 
private void calculateRegions_New(VCImage vcImage, int dimension, Extent extent, Origin origin, ClientTaskStatusSupport clientTaskStatusSupport) throws ImageException {
    // Find linked pixel values in x,y,z and surface elements locations
    final int EMPTY_REGION = 0;
    final int FIRST_REGION = 1;
    final int ARRAY_SIZE_INCREMENT = 1000;
    byte[] imagePixels = vcImage.getPixels();
    int[] regionPixels = new int[imagePixels.length];
    BitSet xSurfElements = new BitSet(imagePixels.length);
    BitSet ySurfElements = new BitSet(imagePixels.length);
    BitSet zSurfElements = new BitSet(imagePixels.length);
    Vector<Integer>[] regionLinkArr = new Vector[ARRAY_SIZE_INCREMENT];
    int[] regionSizeArr = new int[ARRAY_SIZE_INCREMENT];
    Vector<Byte> regionImagePixelV = new Vector<Byte>();
    // 0 not used
    regionImagePixelV.add((byte) 0);
    byte currentImagePixel;
    int currentRegion;
    int masterIndex = 0;
    int nextAvailableRegion = FIRST_REGION;
    for (int zIndex = 0; zIndex < vcImage.getNumZ(); zIndex++) {
        if (clientTaskStatusSupport != null) {
            if (clientTaskStatusSupport.isInterrupted()) {
                return;
            }
        }
        int zForwardIndex = ((zIndex + 1) < vcImage.getNumZ() ? masterIndex + (vcImage.getNumX() * vcImage.getNumY()) : -1);
        for (int yIndex = 0; yIndex < vcImage.getNumY(); yIndex++) {
            int yForwardIndex = ((yIndex + 1) < vcImage.getNumY() ? masterIndex + vcImage.getNumX() : -1);
            currentImagePixel = imagePixels[masterIndex];
            if (regionPixels[masterIndex] != EMPTY_REGION) {
                currentRegion = regionPixels[masterIndex];
            } else {
                currentRegion = nextAvailableRegion;
                if (currentRegion >= regionLinkArr.length) {
                    // make more room for arrays
                    Vector<Integer>[] temp = new Vector[regionLinkArr.length + ARRAY_SIZE_INCREMENT];
                    System.arraycopy(regionLinkArr, 0, temp, 0, regionLinkArr.length);
                    regionLinkArr = temp;
                    int[] temp2 = new int[regionSizeArr.length + ARRAY_SIZE_INCREMENT];
                    System.arraycopy(regionSizeArr, 0, temp2, 0, regionSizeArr.length);
                    regionSizeArr = temp2;
                }
                regionPixels[masterIndex] = currentRegion;
                if (regionImagePixelV.size() != currentRegion) {
                    throw new ImageException("Mismatch between region and pixel buffer");
                }
                regionImagePixelV.add(currentImagePixel);
                nextAvailableRegion += 1;
            }
            for (int xIndex = 0; xIndex < vcImage.getNumX(); xIndex++) {
                if (imagePixels[masterIndex] == currentImagePixel) {
                    if (regionPixels[masterIndex] != EMPTY_REGION) {
                        if (currentRegion != regionPixels[masterIndex]) {
                            createLink(regionLinkArr, currentRegion, regionPixels, masterIndex);
                        }
                    } else {
                        regionPixels[masterIndex] = currentRegion;
                    }
                } else {
                    xSurfElements.set(masterIndex - 1);
                    currentImagePixel = imagePixels[masterIndex];
                    if (regionPixels[masterIndex] != EMPTY_REGION) {
                        currentRegion = regionPixels[masterIndex];
                    } else {
                        currentRegion = nextAvailableRegion;
                        if (currentRegion >= regionLinkArr.length) {
                            // make more room for arrays
                            Vector<Integer>[] temp = new Vector[regionLinkArr.length + ARRAY_SIZE_INCREMENT];
                            System.arraycopy(regionLinkArr, 0, temp, 0, regionLinkArr.length);
                            regionLinkArr = temp;
                            int[] temp2 = new int[regionSizeArr.length + ARRAY_SIZE_INCREMENT];
                            System.arraycopy(regionSizeArr, 0, temp2, 0, regionSizeArr.length);
                            regionSizeArr = temp2;
                        }
                        regionPixels[masterIndex] = currentRegion;
                        if (regionImagePixelV.size() != currentRegion) {
                            throw new ImageException("Mismatch between region and pixel buffer");
                        }
                        regionImagePixelV.add(currentImagePixel);
                        nextAvailableRegion += 1;
                    }
                }
                regionSizeArr[currentRegion] += 1;
                // }
                if (yForwardIndex != -1) {
                    if (imagePixels[yForwardIndex] == currentImagePixel) {
                        if (regionPixels[yForwardIndex] == EMPTY_REGION) {
                            regionPixels[yForwardIndex] = currentRegion;
                        } else if (currentRegion != regionPixels[yForwardIndex]) {
                            createLink(regionLinkArr, currentRegion, regionPixels, yForwardIndex);
                        }
                    } else {
                        ySurfElements.set(masterIndex);
                    }
                    yForwardIndex += 1;
                }
                if (zForwardIndex != -1) {
                    if (imagePixels[zForwardIndex] == currentImagePixel) {
                        if (regionPixels[zForwardIndex] == EMPTY_REGION) {
                            regionPixels[zForwardIndex] = currentRegion;
                        } else if (currentRegion != regionPixels[zForwardIndex]) {
                            createLink(regionLinkArr, currentRegion, regionPixels, zForwardIndex);
                        }
                    } else {
                        zSurfElements.set(masterIndex);
                    }
                    zForwardIndex += 1;
                }
                masterIndex += 1;
            }
        }
    }
    // System.out.println(xSurfElements.cardinality()+" "+ySurfElements.cardinality()+" "+zSurfElements.cardinality());
    // System.out.println("----------link time "+((System.currentTimeMillis()-startTime)/1000.0));
    // startTime = System.currentTimeMillis();
    // Distribute links
    Vector<Integer>[] collector = new Vector[nextAvailableRegion];
    for (int i = 1; i < nextAvailableRegion; /*regionSizeArr.length*/
    i++) {
        // 0 not used
        if (regionSizeArr[i] != 0) {
            collector[i] = (Vector) (regionLinkArr[i] != null ? regionLinkArr[i].clone() : null);
        }
    }
    for (int i = 1; i < nextAvailableRegion; /*regionSizeArr.length*/
    i++) {
        // 0 not used
        if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
            return;
        }
        // System.out.print("region="+i+" size="+regionSizeArr[i]);
        Vector<Integer> intV = regionLinkArr[i];
        for (int j = 0; intV != null && j < intV.size(); j++) {
            // System.out.print((j==0?" - ":" ")+intV.elementAt(j));
            // Collect
            Vector<Integer> collectIntV = collector[intV.elementAt(j)];
            if (collectIntV == null) {
                collectIntV = new Vector<Integer>();
                collector[intV.elementAt(j)] = collectIntV;
                if (regionLinkArr[intV.elementAt(j)] != null) {
                    collectIntV.addAll(regionLinkArr[intV.elementAt(j)]);
                }
            }
            if (!collectIntV.contains(i)) {
                collectIntV.add(i);
            }
        }
    // System.out.println();
    }
    // System.out.println("----------distribute link time "+((System.currentTimeMillis()-startTime)/1000.0));
    // startTime = System.currentTimeMillis();
    // for (int i = 1; i < collector.length; i++) {// 0 not used
    // if(regionSizeArr[i] != 0){
    // System.out.print("Collect region="+i+" size="+regionSizeArr[i]);
    // Vector<Integer> intV = collector[i];
    // for (int j = 0; intV!= null && j < intV.size();j++) {
    // System.out.print((j==0?" - ":" ")+intV.elementAt(j));
    // }
    // System.out.println();
    // }
    // }
    // Gather links into distinct regions
    // Map link-regions(implicit) to distinct-regions
    int[] linkRegionMap = new int[collector.length];
    int totalSize = 0;
    Vector<Vector<Integer>> regionsV = new Vector<Vector<Integer>>();
    Vector<Integer> regionsSizeV = new Vector<Integer>();
    BitSet checkFlagBS = new BitSet(collector.length);
    for (int i = 1; i < collector.length; i++) {
        // 0 not used
        if (clientTaskStatusSupport != null && clientTaskStatusSupport.isInterrupted()) {
            return;
        }
        if (checkFlagBS.get(i)) {
            continue;
        }
        checkFlagBS.set(i);
        Vector<Integer> holderV = new Vector<Integer>();
        holderV.add(i);
        if (collector[i] != null) {
            holderV.addAll(collector[i]);
        }
        int checkIndex = 0;
        // 
        boolean[] holderVContainsFlag = new boolean[collector.length];
        for (int j = 0; j < holderV.size(); j++) {
            holderVContainsFlag[holderV.elementAt(j)] = true;
        }
        // 
        while (true) {
            if (collector[holderV.elementAt(checkIndex)] != null) {
                Vector<Integer> newLinksV = collector[holderV.elementAt(checkIndex)];
                for (int j = 0; j < newLinksV.size(); j++) {
                    if (!checkFlagBS.get(newLinksV.elementAt(j)) && !holderVContainsFlag[newLinksV.elementAt(j)]) // !holderV.contains(newLinksV.elementAt(j))
                    {
                        holderV.add(newLinksV.elementAt(j));
                        holderVContainsFlag[newLinksV.elementAt(j)] = true;
                    }
                }
            }
            checkFlagBS.set(holderV.elementAt(checkIndex));
            checkIndex += 1;
            if (checkIndex == holderV.size()) {
                break;
            }
        }
        regionsV.add(holderV);
        if (regionsV.size() > 0x0000FFFF) {
            // unsigned short max, must match getShortEncodedRegionIndexImage()
            throw new ImageException("Error: image segmentation contains more than " + (0x0000FFFF) + " distinct regions.");
        }
        int regionSize = 0;
        byte pixelCheck = regionImagePixelV.elementAt(holderV.elementAt(0));
        for (int j = 0; j < holderV.size(); j++) {
            if (pixelCheck != regionImagePixelV.elementAt(holderV.elementAt(j))) {
                throw new ImageException("Linked regions have different image pixel values");
            }
            linkRegionMap[holderV.elementAt(j)] = regionsV.size() - 1;
            // System.out.print((j!=0?" ":"")+holderV.elementAt(j));
            regionSize += regionSizeArr[holderV.elementAt(j)];
            totalSize += regionSizeArr[holderV.elementAt(j)];
        }
        regionsSizeV.add(regionSize);
    // System.out.println();
    }
    if (totalSize != vcImage.getNumXYZ()) {
        throw new ImageException("Accumulated regions size does not equal image size");
    }
    // System.out.println("----------gather link distinct regions time "+((System.currentTimeMillis()-startTime)/1000.0));
    // startTime = System.currentTimeMillis();
    // //Create bitmasks of distinct regions
    // BitSet[] regionBitMaskBS = new BitSet[regionsV.size()];
    // for (int i = 0; i < regionBitMaskBS.length; i++) {
    // regionBitMaskBS[i] = new BitSet(regionPixels.length);
    // }
    // for (int i = 0; i < regionPixels.length; i++) {
    // regionBitMaskBS[linkRegionMap[regionPixels[i]]].set(i);
    // }
    // System.out.println("----------bitmask time "+((System.currentTimeMillis()-startTime)/1000.0));
    // startTime = System.currentTimeMillis();
    // Create RegionInfos
    regionInfos = new RegionInfo[regionsV.size()];
    for (int i = 0; i < regionsV.size(); i++) {
        regionInfos[i] = new RegionInfo(regionImagePixelV.elementAt(regionsV.elementAt(i).elementAt(0)) & 0x000000FF, regionsSizeV.elementAt(i), i, // regionBitMaskBS[i]
        null);
    }
    // System.out.println("----------regioninfo time "+((System.currentTimeMillis()-startTime)/1000.0));
    // startTime = System.currentTimeMillis();
    mapImageIndexToLinkRegion = regionPixels;
    mapLinkRegionToDistinctRegion = linkRegionMap;
    if (dimension != 0) {
        generateSurfaceCollection(regionsV.size(), // regionPixels,linkRegionMap,
        vcImage, xSurfElements, ySurfElements, zSurfElements, dimension, extent, origin);
    }
    if (surfaceCollection != null && debug_bCheckPolygonQuality) {
        verifyQuadVertexOrdering(debug_maxQuadAngle);
    }
    // Taubin smoothing
    if (surfaceCollection != null && filterCutoffFrequency < RegionImage.NO_SMOOTHING) {
        TaubinSmoothing taubinSmoothing = new TaubinSmoothingWrong();
        TaubinSmoothingSpecification taubinSpec = TaubinSmoothingSpecification.getInstance(filterCutoffFrequency);
        taubinSmoothing.smooth(surfaceCollection, taubinSpec);
    }
    // startTime = System.currentTimeMillis();
    if (surfaceCollection != null && debug_bCheckPolygonQuality) {
        verifyQuadVertexOrdering(debug_maxQuadAngle);
    }
// System.out.println("Total Num Regions = "+regionsV.size());
// System.out.println("Total Size = "+totalSize);
}
Also used : TaubinSmoothingWrong(cbit.vcell.geometry.surface.TaubinSmoothingWrong) ImageException(cbit.image.ImageException) BitSet(java.util.BitSet) TaubinSmoothingSpecification(cbit.vcell.geometry.surface.TaubinSmoothingSpecification) Vector(java.util.Vector) TaubinSmoothing(cbit.vcell.geometry.surface.TaubinSmoothing)

Example 10 with ImageException

use of cbit.image.ImageException in project vcell by virtualcell.

the class GeometryViewer method refreshSourceDataInfo.

/**
 * connEtoM2:  (Geometry.this --> ImagePlaneManagerPanel1.sourceDataInfo)
 * @param value cbit.vcell.geometry.Geometry
 */
/* WARNING: THIS METHOD WILL BE REGENERATED. */
private void refreshSourceDataInfo() {
    if (getGeometry() == null) {
        return;
    }
    GeometrySpec geometrySpec = getGeometry().getGeometrySpec();
    if (geometrySpec.getSampledImage().isDirty()) {
        return;
    }
    VCImage sampledImage = geometrySpec.getSampledImage().getCurrentValue();
    try {
        SourceDataInfo sdi = new SourceDataInfo(SourceDataInfo.INDEX_TYPE, sampledImage.getPixels(), geometrySpec.getExtent(), geometrySpec.getOrigin(), null, 0, sampledImage.getNumX(), 1, sampledImage.getNumY(), sampledImage.getNumX(), sampledImage.getNumZ(), sampledImage.getNumX() * sampledImage.getNumY());
        getImagePlaneManagerPanel1().setSourceDataInfo(sdi);
    } catch (ImageException e) {
        e.printStackTrace();
        DialogUtils.showErrorDialog(this, e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        DialogUtils.showErrorDialog(this, e.getMessage(), e);
    }
}
Also used : GeometrySpec(cbit.vcell.geometry.GeometrySpec) ImageException(cbit.image.ImageException) VCImage(cbit.image.VCImage) SourceDataInfo(cbit.image.SourceDataInfo) ImageException(cbit.image.ImageException)

Aggregations

ImageException (cbit.image.ImageException)34 IOException (java.io.IOException)11 Extent (org.vcell.util.Extent)11 VCImage (cbit.image.VCImage)10 SubVolume (cbit.vcell.geometry.SubVolume)9 SurfaceClass (cbit.vcell.geometry.SurfaceClass)9 PropertyVetoException (java.beans.PropertyVetoException)9 DataAccessException (org.vcell.util.DataAccessException)9 Geometry (cbit.vcell.geometry.Geometry)8 ImageSubVolume (cbit.vcell.geometry.ImageSubVolume)8 Expression (cbit.vcell.parser.Expression)8 VCImageUncompressed (cbit.image.VCImageUncompressed)7 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)7 BioModel (cbit.vcell.biomodel.BioModel)7 GeometryException (cbit.vcell.geometry.GeometryException)7 MathDescription (cbit.vcell.math.MathDescription)7 ExpressionException (cbit.vcell.parser.ExpressionException)7 Origin (org.vcell.util.Origin)7 UserCancelException (org.vcell.util.UserCancelException)7 KeyValue (org.vcell.util.document.KeyValue)7