Search in sources :

Example 51 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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 52 with UShortImage

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

the class OverlayEditorPanelJAI method displaySpecialData.

public void displaySpecialData(short[] specialData, int width, int height) throws Exception {
    if (specialData == null) {
        forceImage();
        return;
    }
    UShortImage specialUShortImage = new UShortImage(specialData, null, null, width, height, 1);
    BufferedImage specialBufferedImage = createUnderlyingImage(specialUShortImage);
    imagePane.setUnderlyingImage(specialBufferedImage, /* false,*/
    null);
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) BufferedImage(java.awt.image.BufferedImage)

Example 53 with UShortImage

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

the class VFrap_OverlayEditorPanelJAI method getImportROIMaskButton.

public JButton getImportROIMaskButton() {
    if (importROIMaskButton == null) {
        importROIMaskButton = new JButton(new ImageIcon(getClass().getResource("/images/importROI.gif")));
        importROIMaskButton.setPreferredSize(new Dimension(32, 32));
        importROIMaskButton.setMargin(new Insets(2, 2, 2, 2));
        importROIMaskButton.setToolTipText("Import ROI mask from file");
        importROIMaskButton.addActionListener(new ActionListener() {

            public void actionPerformed(final ActionEvent e) {
                File inputFile = null;
                try {
                    int option = openJFileChooser.showOpenDialog(VFrap_OverlayEditorPanelJAI.this);
                    if (option == JFileChooser.APPROVE_OPTION) {
                        inputFile = openJFileChooser.getSelectedFile();
                    } else {
                        throw UserCancelException.CANCEL_GENERIC;
                    }
                    if (!customROIImport.importROI(inputFile)) {
                        ImageDataset importImageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(inputFile.getAbsolutePath(), null);
                        if (importImageDataset.getISize().getX() * importImageDataset.getISize().getY() != getImagePane().getHighlightImage().getWidth() * getImagePane().getHighlightImage().getHeight()) {
                            throw new Exception("Imported ROI mask size (" + importImageDataset.getISize().getX() + "," + importImageDataset.getISize().getY() + ")" + " does not match current Frap DataSet size (" + getImagePane().getHighlightImage().getWidth() + "," + getImagePane().getHighlightImage().getHeight() + ")");
                        }
                        // BufferedImage roiMaskImage = BufferedImageReader.makeBufferedImageReader(iFormatReader).openImage(0);
                        UShortImage roiMaskImage = importImageDataset.getImage(0, 0, 0);
                        int maskColor = highlightColor.getRGB();
                        for (int y = 0; y < importImageDataset.getISize().getY(); y++) {
                            for (int x = 0; x < importImageDataset.getISize().getX(); x++) {
                                if ((roiMaskImage.getPixel(x, y, 0) & 0xFFFF) != 0) {
                                    getImagePane().getHighlightImage().setRGB(x, y, maskColor);
                                }
                            }
                        }
                        getImagePane().refreshImage();
                    }
                } catch (UserCancelException uce) {
                // Do Nothing
                } catch (Exception e1) {
                    e1.printStackTrace();
                    DialogUtils.showErrorDialog(VFrap_OverlayEditorPanelJAI.this, "Error importing ROI" + e1.getMessage());
                }
            }
        });
    }
    return importROIMaskButton;
}
Also used : ImageIcon(javax.swing.ImageIcon) Insets(java.awt.Insets) ActionListener(java.awt.event.ActionListener) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) UserCancelException(org.vcell.util.UserCancelException) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Dimension(java.awt.Dimension) File(java.io.File) CannotUndoException(javax.swing.undo.CannotUndoException) UserCancelException(org.vcell.util.UserCancelException)

Example 54 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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)

Example 55 with UShortImage

use of cbit.vcell.VirtualMicroscopy.UShortImage 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)

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