Search in sources :

Example 56 with UShortImage

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

the class VFrap_OverlayEditorPanelJAI method updateLabel.

/**
 * Updates cursor probe label. * @param x int
 * @param y int
 */
protected void updateLabel(int inx, int iny) {
    if (imageDataset == null) {
        return;
    }
    float zoom = imagePane.getZoom();
    if ((inx / zoom) >= imageDataset.getISize().getX() || (iny / zoom) >= imageDataset.getISize().getY()) {
        inx = -1;
        iny = -1;
    }
    int x = (int) (inx / zoom);
    int y = (int) (iny / zoom);
    UShortImage[] images = imageDataset.getAllImages();
    sb.setLength(0);
    boolean bMultipleZ = imageDataset.getSizeZ() > 1;
    if (bMultipleZ) {
        sb.append("; Z=");
        sb.append(getZ() + 1);
        sb.append("/");
        sb.append(imageDataset.getSizeZ());
    }
    if (imageDataset.getSizeT() > 1) {
        sb.append((bMultipleZ ? "; " : "") + "T=");
        sb.append(imageDataset.getImageTimeStamps()[getT()]);
        // add the indicator to show it is the no. x image among total images.
        sb.append("  (" + (getT() + 1) + "" + "/" + imageDataset.getImageTimeStamps().length + ")");
    }
    // BufferedImage image = ImageTools.makeImage(images[ndx].getPixels(), images[ndx].getNumX(), images[ndx].getNumY());
    // int w = image == null ? -1 : image.getWidth();
    // int h = image == null ? -1 : image.getHeight();
    int w = imageDataset == null ? -1 : imageDataset.getISize().getX();
    int h = imageDataset == null ? -1 : imageDataset.getISize().getY();
    if (x >= w)
        x = w - 1;
    if (y >= h)
        y = h - 1;
    if (x >= 0 && y >= 0 && inx >= 0 && iny >= 0 && x < imageDataset.getISize().getX() && y < imageDataset.getISize().getY()) {
        if (images.length > 1)
            sb.append("; ");
        sb.append("X=");
        sb.append(x);
        if (w > 0) {
            sb.append("/");
            sb.append(w);
        }
        sb.append("; Y=");
        sb.append(y);
        if (h > 0) {
            sb.append("/");
            sb.append(h);
        }
        sb.append("; zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
        sb.append("; contr(" + imagePane.getContrastDescription() + ")");
        if (imageDataset != null) {
            // Raster r = image.getRaster();
            // double[] pix = r.getPixel(x, y, (double[]) null);
            short[] pix = null;
            try {
                pix = new short[imageDataset.getSizeC()];
                for (int i = 0; i < pix.length; i++) {
                    pix[i] = imageDataset.getImage(getZ(), i, getT()).getPixel(x, y, 0);
                }
            } catch (Exception e) {
                pix = null;
                e.printStackTrace();
            // do nothing
            }
            sb.append("; value" + (isOriginalValueScaled() ? "(scld)" : ""));
            if (pix != null) {
                sb.append(pix.length > 1 ? "s=(" : "=");
                for (int i = 0; i < pix.length; i++) {
                    if (i > 0)
                        sb.append(", ");
                    sb.append((pix[i] & 0x0000FFFF));
                }
                if (pix.length > 1)
                    sb.append(")");
            } else {
                sb.append(" error");
            }
            if (isOriginalValueScaled()) {
                sb.append("; value(orig)");
                if (pix != null) {
                    sb.append(pix.length > 1 ? "s=(" : "=");
                    for (int i = 0; i < pix.length; i++) {
                        if (i > 0)
                            sb.append(", ");
                        sb.append(NumberUtils.formatNumber((((pix[i] & 0x0000FFFF)) - originalOffsetFactor) / originalScaleFactor, 6));
                    }
                    if (pix.length > 1)
                        sb.append(")");
                } else {
                    sb.append(" error");
                }
            }
        // sb.append(" udnerly="+Integer.toHexString(imagePane.getUnderlyingImage().getRGB(x, y)));
        }
    } else {
        sb.append("; zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
        sb.append("; contr(" + imagePane.getContrastDescription() + ")");
    }
    sb.append(" ");
    textLabel.setText(sb.toString());
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Point(java.awt.Point) CannotUndoException(javax.swing.undo.CannotUndoException) UserCancelException(org.vcell.util.UserCancelException)

Example 57 with UShortImage

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

the class VFrap_ROIAssistPanel method resolveCurrentROI.

private void resolveCurrentROI(RegionInfo keepRegion) throws Exception {
    short[] removePixels = frapData.getCurrentlyDisplayedROI().getPixelsXYZ();
    for (int i = 0; i < removePixels.length; i++) {
        if (!keepRegion.isIndexInRegion(i)) {
            removePixels[i] = 0;
        }
    }
    final boolean hasInternalVoids = fillVoids(removePixels, true);
    UShortImage ushortImage = new UShortImage(removePixels, frapData.getCurrentlyDisplayedROI().getRoiImages()[0].getOrigin(), frapData.getCurrentlyDisplayedROI().getRoiImages()[0].getExtent(), frapData.getCurrentlyDisplayedROI().getISize().getX(), frapData.getCurrentlyDisplayedROI().getISize().getY(), frapData.getCurrentlyDisplayedROI().getISize().getZ());
    final ROI newCellROI = new ROI(ushortImage, frapData.getCurrentlyDisplayedROI().getROIName());
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            // }});
            frapData.addReplaceRoi(newCellROI);
            applyROIButton.setEnabled(!hasInternalVoids);
            resolveROIButton.setEnabled(false);
            fillVoidsButton.setEnabled(hasInternalVoids);
        }
    });
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 58 with UShortImage

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

the class ClientRequestManager method createFDOSWithChannels.

public static FieldDataFileOperationSpec createFDOSWithChannels(ImageDataset[] imagedataSets, Integer saveOnlyThisTimePointIndex) {
    final FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    // [time][var][data]
    int numXY = imagedataSets[0].getISize().getX() * imagedataSets[0].getISize().getY();
    int numXYZ = imagedataSets[0].getSizeZ() * numXY;
    fdos.variableTypes = new VariableType[imagedataSets.length];
    fdos.varNames = new String[imagedataSets.length];
    short[][][] shortData = new short[(saveOnlyThisTimePointIndex != null ? 1 : imagedataSets[0].getSizeT())][imagedataSets.length][numXYZ];
    for (int c = 0; c < imagedataSets.length; c += 1) {
        fdos.variableTypes[c] = VariableType.VOLUME;
        fdos.varNames[c] = "Channel" + c;
        for (int t = 0; t < imagedataSets[c].getSizeT(); t += 1) {
            if (saveOnlyThisTimePointIndex != null && saveOnlyThisTimePointIndex.intValue() != t) {
                continue;
            }
            int zOffset = 0;
            for (int z = 0; z < imagedataSets[c].getSizeZ(); z += 1) {
                UShortImage ushortImage = imagedataSets[c].getImage(z, 0, t);
                System.arraycopy(ushortImage.getPixels(), 0, shortData[(saveOnlyThisTimePointIndex != null ? 0 : t)][c], zOffset, numXY);
                // shortData[t][c] = ushortImage.getPixels();
                zOffset += numXY;
            }
        }
    }
    fdos.shortSpecData = shortData;
    fdos.times = imagedataSets[0].getImageTimeStamps();
    if (fdos.times == null) {
        fdos.times = new double[imagedataSets[0].getSizeT()];
        for (int i = 0; i < fdos.times.length; i += 1) {
            fdos.times[i] = i;
        }
    }
    fdos.origin = (imagedataSets[0].getAllImages()[0].getOrigin() != null ? imagedataSets[0].getAllImages()[0].getOrigin() : new Origin(0, 0, 0));
    fdos.extent = (imagedataSets[0].getExtent() != null) ? (imagedataSets[0].getExtent()) : (new Extent(1, 1, 1));
    fdos.isize = imagedataSets[0].getISize();
    return fdos;
}
Also used : BngUnitOrigin(org.vcell.model.bngl.BngUnitSystem.BngUnitOrigin) Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 59 with UShortImage

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

the class OverlayEditorPanelJAI method createHighlightImageFromROI.

/**
 * Method createHighlightImageFromROI.
 * @return BufferedImage
 */
private BufferedImage createHighlightImageFromROI(ROI highlightImageROI) {
    UShortImage roiImage = highlightImageROI.getRoiImages()[getRoiImageIndex()];
    int width = roiImage.getNumX();
    int height = roiImage.getNumY();
    BufferedImage hiLiteImage = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_INDEXED, getHiliteColorModel());
    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)

Example 60 with UShortImage

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

the class OverlayEditorPanelJAI method updateLabel.

/**
 * Updates cursor probe label. * @param x int
 * @param y int
 */
private void updateLabel(int inx, int iny) {
    if (imageDataset == null) {
        return;
    }
    float zoom = imagePane.getZoom();
    if ((inx / zoom) >= imageDataset.getISize().getX() || (iny / zoom) >= imageDataset.getISize().getY()) {
        inx = -1;
        iny = -1;
    }
    int x = (int) (inx / zoom);
    int y = (int) (iny / zoom);
    UShortImage[] images = imageDataset.getAllImages();
    sb.setLength(0);
    boolean bMultipleZ = imageDataset.getSizeZ() > 1;
    if (bMultipleZ) {
        sb.append("; Z=");
        sb.append(getZ() + 1);
        sb.append("/");
        sb.append(imageDataset.getSizeZ());
        if (calcCoords != null) {
            sb.append(" " + NumberUtils.formatNumber(calcCoords.calcZ(getZ()), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentZ(), 6));
        }
    }
    if (imageDataset.getSizeT() > 1) {
        sb.append((bMultipleZ ? "; " : "") + "T=");
        sb.append(imageDataset.getImageTimeStamps()[getT()]);
    }
    int w = imageDataset == null ? -1 : imageDataset.getISize().getX();
    int h = imageDataset == null ? -1 : imageDataset.getISize().getY();
    if (x >= w)
        x = w - 1;
    if (y >= h)
        y = h - 1;
    if (x >= 0 && y >= 0 && inx >= 0 && iny >= 0 && x < imageDataset.getISize().getX() && y < imageDataset.getISize().getY()) {
        if (images.length > 1)
            sb.append("; ");
        sb.append("X=");
        sb.append(x);
        if (w > 0) {
            sb.append("/");
            sb.append(w);
            if (calcCoords != null) {
                sb.append(" " + NumberUtils.formatNumber(calcCoords.calcX(inx), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentX(), 6));
            }
        }
        sb.append("; Y=");
        sb.append(y);
        if (h > 0) {
            sb.append("/");
            sb.append(h);
            if (calcCoords != null) {
                sb.append(" " + NumberUtils.formatNumber(calcCoords.calcY(iny), 6) + "/" + NumberUtils.formatNumber(calcCoords.extentY(), 6));
            }
        }
        sb.append("; zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
        sb.append("; contr(" + imagePane.getContrastDescription() + ")");
        if (imageDataset != null) {
            short[] pix = null;
            try {
                pix = new short[imageDataset.getSizeC()];
                for (int i = 0; i < pix.length; i++) {
                    pix[i] = imageDataset.getImage(getZ(), i, getT()).getPixel(x, y, 0);
                }
            } catch (Exception e) {
                pix = null;
                e.printStackTrace();
            // do nothing
            }
            sb.append("; value(img)" + (isOriginalValueScaled() ? "(scld)" : ""));
            if (pix != null) {
                if (histogramPanel.isVisible()) {
                    histogramPanel.setSpecialValue((int) (pix[0] & 0x0000FFFF));
                }
                sb.append(pix.length > 1 ? "s=(" : "=");
                for (int i = 0; i < pix.length; i++) {
                    if (i > 0)
                        sb.append(", ");
                    sb.append((int) (pix[i] & 0x0000FFFF));
                }
                if (pix.length > 1)
                    sb.append(")");
            } else {
                sb.append(" error");
            }
            if (isOriginalValueScaled()) {
                sb.append("; value(img)(orig)");
                if (pix != null) {
                    sb.append(pix.length > 1 ? "s=(" : "=");
                    for (int i = 0; i < pix.length; i++) {
                        if (i > 0)
                            sb.append(", ");
                        sb.append(NumberUtils.formatNumber((((int) (pix[i] & 0x0000FFFF)) - originalOffsetFactor) / originalScaleFactor, 6));
                    }
                    if (pix.length > 1)
                        sb.append(")");
                } else {
                    sb.append(" error");
                }
            }
        }
        if (allROICompositeImageArr != null) {
            // System.out.println(getZ()+" "+x+" "+y);
            DataBufferByte dataBufferByte = (DataBufferByte) (allROICompositeImageArr[getZ()].getRaster().getDataBuffer());
            sb.append(" val(roi)=" + dataBufferByte.getData()[y * allROICompositeImageArr[0].getWidth() + x]);
        }
    } else {
        sb.append((sb.length() != 0 ? "; " : "") + "zoom(" + NumberUtils.formatNumber(imagePane.getZoom(), 3) + ")");
        sb.append("; contr(" + imagePane.getContrastDescription() + ")");
        if (histogramPanel.isVisible()) {
            histogramPanel.setSpecialValue(null);
        }
    }
    sb.append(" ");
    textLabel.setText(sb.toString());
}
Also used : UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) DataBufferByte(java.awt.image.DataBufferByte) Point(java.awt.Point) UtilCancelException(org.vcell.util.UtilCancelException) UserCancelException(org.vcell.util.UserCancelException)

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