Search in sources :

Example 51 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method fillVoids.

private boolean fillVoids(BufferedImage[] roiPixels, boolean bCheckOnly) throws Exception {
    if (true) {
        throw new IllegalArgumentException("Not yet implemented fully");
    }
    boolean bHadAnyInternalVoids = false;
    int xSize = roiPixels[0].getWidth();
    int ySize = roiPixels[0].getHeight();
    int zSize = roiPixels.length;
    int XYSIZE = xSize * ySize;
    boolean bUseZ = roiPixels.length > 1;
    VCImage checkImage = ROIMultiPaintManager.createVCImageFromBufferedImages(getImageDataSetChannel().getExtent(), roiComposite);
    RegionImage regionImage = new RegionImage(checkImage, 0, /*0 means generate no surfacecollection*/
    checkImage.getExtent(), getImageDataSetChannel().getAllImages()[0].getOrigin(), RegionImage.NO_SMOOTHING, progressWaitPopup);
    RegionInfo[] newRegionInfos = regionImage.getRegionInfos();
    for (int i = 0; i < newRegionInfos.length; i++) {
        if (newRegionInfos[i].getPixelValue() == 0) {
            boolean bInternalVoid = true;
            for (int z = 0; z < zSize; z++) {
                int zOffset = z * XYSIZE;
                for (int y = 0; y < ySize; y++) {
                    int yoffset = y * xSize;
                    int zyOffset = zOffset + yoffset;
                    for (int x = 0; x < xSize; x++) {
                        if (newRegionInfos[i].isIndexInRegion(zyOffset + x)) {
                            if (x == 0 || y == 0 | (bUseZ && z == 0) | x == (xSize - 1) || y == (ySize - 1) || (bUseZ && z == (zSize - 1))) {
                                bInternalVoid = false;
                                break;
                            }
                        }
                    }
                    if (!bInternalVoid) {
                        break;
                    }
                }
                if (!bInternalVoid) {
                    break;
                }
            }
            if (bInternalVoid) {
                bHadAnyInternalVoids = true;
                if (bCheckOnly) {
                    return bHadAnyInternalVoids;
                }
                for (int z = 0; z < zSize; z++) {
                    byte[] roiPixelsBytes = ((DataBufferByte) roiPixels[z].getRaster().getDataBuffer()).getData();
                    for (int xy = 0; xy < XYSIZE; xy++) {
                    // if(newRegionInfos[i].isIndexInRegion(j)){
                    // fillvoidPixels[j]|= 0xFFFF;
                    // }
                    }
                }
            }
        }
    }
    return bHadAnyInternalVoids;
}
Also used : RegionImage(cbit.vcell.geometry.RegionImage) VCImage(cbit.image.VCImage) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point)

Example 52 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method duplicateROIData.

private void duplicateROIData(final int newZSize) {
    final AsynchClientTask extrudeTask = new AsynchClientTask("Extruding...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            ISize origSize = getImageDataSetChannel().getISize();
            if (origSize.getZ() != 1 || newZSize < 1) {
                throw new IllegalArgumentException("Extrude assumes starting with 2D and new Z size >= 1.");
            }
            UShortImage[][] newUnderLayImageArr = new UShortImage[initImageDataSetChannels.length][newZSize];
            BufferedImage[] newROICompositeArr = new BufferedImage[newZSize];
            for (int i = 0; i < newZSize; i++) {
                for (int c = 0; c < initImageDataSetChannels.length; c++) {
                    // short[] zslice = new short[initImageDataSetChannels[c].getAllImages()[0].getPixels().length];
                    // System.arraycopy(initImageDataSetChannels[c].getAllImages()[0].getPixels(), 0, zslice, 0, zslice.length);
                    newUnderLayImageArr[c][i] = new UShortImage(// zslice,
                    initImageDataSetChannels[c].getAllImages()[0].getPixels().clone(), DEFAULT_ORIGIN, DEFAULT_EXTENT, initImageDataSetChannels[c].getAllImages()[0].getNumX(), initImageDataSetChannels[c].getAllImages()[0].getNumY(), 1);
                }
                newROICompositeArr[i] = new BufferedImage(roiComposite[0].getWidth(), roiComposite[0].getHeight(), BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
                System.arraycopy((byte[]) ((DataBufferByte) roiComposite[0].getRaster().getDataBuffer()).getData(), 0, (byte[]) ((DataBufferByte) newROICompositeArr[i].getRaster().getDataBuffer()).getData(), 0, origSize.getX() * origSize.getY());
            }
            for (int c = 0; c < initImageDataSetChannels.length; c++) {
                initImageDataSetChannels[c] = new ImageDataset(newUnderLayImageArr[c], null, newZSize);
            }
            roiComposite = newROICompositeArr;
            if (!(enhanceImageAmount == ROIMultiPaintManager.ENHANCE_NONE)) {
                getClientTaskStatusSupport().setMessage("smoothing...");
            }
            updateAuxiliaryInfo(origSize, getClientTaskStatusSupport());
        }
    };
    final AsynchClientTask updatePanelTask = getUpdateDisplayAfterCropTask();
    ClientTaskDispatcher.dispatch(overlayEditorPanelJAI, new Hashtable<String, Object>(), new AsynchClientTask[] { extrudeTask, updatePanelTask }, false, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Hashtable(java.util.Hashtable) ISize(org.vcell.util.ISize) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point)

Example 53 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class ROIMultiPaintManager method resizeXYByte.

public static PlanarImage resizeXYByte(byte[] byteArr, int numX, int numY, Float scaleX, Float scaleY) {
    BufferedImage bufferedImage = new BufferedImage(numX, numY, BufferedImage.TYPE_BYTE_INDEXED, getContrastIndexColorModel());
    byte[] byteData = ((DataBufferByte) bufferedImage.getRaster().getDataBuffer()).getData();
    System.arraycopy(byteArr, 0, byteData, 0, byteArr.length);
    PlanarImage planarImage = ScaleDescriptor.create(bufferedImage, scaleX, scaleY, 0f, 0f, new InterpolationNearest(), null);
    return planarImage;
// PaddedInfo paddedInfo = new PaddedInfo();
// paddedInfo.paddedArray = ((DataBufferByte)planarImage.getData().getDataBuffer()).getData();
// paddedInfo.paddedISize = new ISize(planarImage.getWidth(), planarImage.getHeight(), 1);
// return paddedInfo;
}
Also used : InterpolationNearest(javax.media.jai.InterpolationNearest) DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) PlanarImage(javax.media.jai.PlanarImage)

Example 54 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class OverlayEditorPanelJAI method saveUserChangesToROI.

public void saveUserChangesToROI() {
    short[] roiPixels = getImagePane().getHighlightImageWritebackImageBuffer();
    if (roiPixels != null) {
        BufferedImage highlightImage = imagePane.getHighlightImage();
        byte[] hiLiteArr = ((DataBufferByte) highlightImage.getRaster().getDataBuffer()).getData();
        for (int i = 0; i < roiPixels.length; i++) {
            roiPixels[i] = (hiLiteArr[i] == 0 ? 0 : (short) 0xffff);
        }
    }
}
Also used : DataBufferByte(java.awt.image.DataBufferByte) BufferedImage(java.awt.image.BufferedImage) Point(java.awt.Point)

Example 55 with DataBufferByte

use of java.awt.image.DataBufferByte in project vcell by virtualcell.

the class VFrap_OverlayEditorPanelJAI method createHighlightImageFromROI.

/**
 * Method createHighlightImageFromROI.
 * @return BufferedImage
 */
private BufferedImage createHighlightImageFromROI() {
    int[] cmap = new int[256];
    // colormap (grayscale)
    for (int i = 0; i < 256; i += 1) {
        if (i != 0) {
            cmap[i] = 0xFF000000 | highlightColor.getRGB();
        } else {
            cmap[1] = 0xFF000000;
        }
    }
    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);
    UShortImage roiImage = roi.getRoiImages()[getRoiImageIndex()];
    int width = roiImage.getNumX();
    int height = roiImage.getNumY();
    BufferedImage hiLiteImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, indexColorModel);
    byte[] hiLiteArr = ((DataBufferByte) hiLiteImage.getRaster().getDataBuffer()).getData();
    for (int i = 0; i < roiImage.getPixels().length; i++) {
        hiLiteArr[i] = (roiImage.getPixels()[i] != 0 ? (byte) highlightColor.getRed() : 0);
    }
    return hiLiteImage;
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) BufferedImage(java.awt.image.BufferedImage) IndexColorModel(java.awt.image.IndexColorModel)

Aggregations

DataBufferByte (java.awt.image.DataBufferByte)64 BufferedImage (java.awt.image.BufferedImage)38 Point (java.awt.Point)36 WritableRaster (java.awt.image.WritableRaster)18 DataBufferInt (java.awt.image.DataBufferInt)14 DataBuffer (java.awt.image.DataBuffer)13 DataBufferShort (java.awt.image.DataBufferShort)10 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)8 Rectangle (java.awt.Rectangle)8 SampleModel (java.awt.image.SampleModel)8 DataBufferUShort (java.awt.image.DataBufferUShort)7 IndexColorModel (java.awt.image.IndexColorModel)7 MultiPixelPackedSampleModel (java.awt.image.MultiPixelPackedSampleModel)7 Graphics2D (java.awt.Graphics2D)6 ComponentSampleModel (java.awt.image.ComponentSampleModel)6 UserCancelException (org.vcell.util.UserCancelException)6 UtilCancelException (org.vcell.util.UtilCancelException)6 SinglePixelPackedSampleModel (java.awt.image.SinglePixelPackedSampleModel)5 Hashtable (java.util.Hashtable)5 VCImage (cbit.image.VCImage)4