Search in sources :

Example 11 with ColorDeconvolutionStains

use of qupath.lib.color.ColorDeconvolutionStains in project qupath by qupath.

the class ImageDetailsPane method getValue.

private Object getValue(ImageDetailRow rowType) {
    if (imageData == null)
        return null;
    ImageServer<BufferedImage> server = imageData.getServer();
    PixelCalibration cal = server.getPixelCalibration();
    switch(rowType) {
        case NAME:
            var project = QuPathGUI.getInstance().getProject();
            var entry = project == null ? null : project.getEntry(imageData);
            if (entry == null)
                return ServerTools.getDisplayableImageName(server);
            else
                return entry.getImageName();
        case URI:
            Collection<URI> uris = server.getURIs();
            if (uris.isEmpty())
                return "Not available";
            if (uris.size() == 1)
                return decodeURI(uris.iterator().next());
            return "[" + String.join(", ", uris.stream().map(ImageDetailsPane::decodeURI).collect(Collectors.toList())) + "]";
        case IMAGE_TYPE:
            return imageData.getImageType();
        case METADATA_CHANGED:
            return hasOriginalMetadata(imageData.getServer()) ? "No" : "Yes";
        case PIXEL_TYPE:
            String type = server.getPixelType().toString().toLowerCase();
            if (server.isRGB())
                type += " (rgb)";
            return type;
        case MAGNIFICATION:
            double mag = server.getMetadata().getMagnification();
            if (Double.isNaN(mag))
                return "Unknown";
            return mag;
        case WIDTH:
            if (cal.hasPixelSizeMicrons())
                return String.format("%s px (%.2f %s)", server.getWidth(), server.getWidth() * cal.getPixelWidthMicrons(), GeneralTools.micrometerSymbol());
            else
                return String.format("%s px", server.getWidth());
        case HEIGHT:
            if (cal.hasPixelSizeMicrons())
                return String.format("%s px (%.2f %s)", server.getHeight(), server.getHeight() * cal.getPixelHeightMicrons(), GeneralTools.micrometerSymbol());
            else
                return String.format("%s px", server.getHeight());
        case DIMENSIONS:
            return String.format("%d x %d x %d", server.nChannels(), server.nZSlices(), server.nTimepoints());
        case PIXEL_WIDTH:
            if (cal.hasPixelSizeMicrons())
                return String.format("%.4f %s", cal.getPixelWidthMicrons(), GeneralTools.micrometerSymbol());
            else
                return "Unknown";
        case PIXEL_HEIGHT:
            if (cal.hasPixelSizeMicrons())
                return String.format("%.4f %s", cal.getPixelHeightMicrons(), GeneralTools.micrometerSymbol());
            else
                return "Unknown";
        case Z_SPACING:
            if (cal.hasZSpacingMicrons())
                return String.format("%.4f %s", cal.getZSpacingMicrons(), GeneralTools.micrometerSymbol());
            else
                return "Unknown";
        case UNCOMPRESSED_SIZE:
            double size = server.getWidth() / 1024.0 * server.getHeight() / 1024.0 * server.getPixelType().getBytesPerPixel() * server.nChannels() * server.nZSlices() * server.nTimepoints();
            String units = " MB";
            if (size > 1000) {
                size /= 1024.0;
                units = " GB";
            }
            return GeneralTools.formatNumber(size, 1) + units;
        case SERVER_TYPE:
            return server.getServerType();
        case PYRAMID:
            if (server.nResolutions() == 1)
                return "No";
            return GeneralTools.arrayToString(Locale.getDefault(Locale.Category.FORMAT), server.getPreferredDownsamples(), 1);
        case STAIN_1:
            return imageData.getColorDeconvolutionStains().getStain(1);
        case STAIN_2:
            return imageData.getColorDeconvolutionStains().getStain(2);
        case STAIN_3:
            return imageData.getColorDeconvolutionStains().getStain(3);
        case BACKGROUND:
            ColorDeconvolutionStains stains = imageData.getColorDeconvolutionStains();
            double[] whitespace = new double[] { stains.getMaxRed(), stains.getMaxGreen(), stains.getMaxBlue() };
            return whitespace;
        default:
            return null;
    }
}
Also used : PixelCalibration(qupath.lib.images.servers.PixelCalibration) URI(java.net.URI) BufferedImage(java.awt.image.BufferedImage) ColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains)

Example 12 with ColorDeconvolutionStains

use of qupath.lib.color.ColorDeconvolutionStains in project qupath by qupath.

the class QP method setColorDeconvolutionStains.

/**
 * Set the color deconvolution stains for hte current image data using a (JSON) String representation
 *
 * @param arg
 * @return
 */
public static boolean setColorDeconvolutionStains(final String arg) {
    ImageData<?> imageData = getCurrentImageData();
    if (imageData == null)
        return false;
    ColorDeconvolutionStains stains = ColorDeconvolutionStains.parseColorDeconvolutionStainsArg(arg);
    imageData.setColorDeconvolutionStains(stains);
    return true;
}
Also used : ColorDeconvolutionStains(qupath.lib.color.ColorDeconvolutionStains)

Aggregations

ColorDeconvolutionStains (qupath.lib.color.ColorDeconvolutionStains)12 BufferedImage (java.awt.image.BufferedImage)4 IOException (java.io.IOException)4 DefaultColorDeconvolutionStains (qupath.lib.color.ColorDeconvolutionStains.DefaultColorDeconvolutionStains)4 StainVector (qupath.lib.color.StainVector)3 ParameterList (qupath.lib.plugins.parameters.ParameterList)3 DialogButton (qupath.lib.gui.dialogs.Dialogs.DialogButton)2 ParameterPanelFX (qupath.lib.gui.dialogs.ParameterPanelFX)2 PathObject (qupath.lib.objects.PathObject)2 ROI (qupath.lib.roi.interfaces.ROI)2 BufferedInputStream (java.io.BufferedInputStream)1 EOFException (java.io.EOFException)1 FileNotFoundException (java.io.FileNotFoundException)1 ObjectInputStream (java.io.ObjectInputStream)1 URI (java.net.URI)1 HashMap (java.util.HashMap)1 Locale (java.util.Locale)1 Map (java.util.Map)1 SimpleStringProperty (javafx.beans.property.SimpleStringProperty)1 Insets (javafx.geometry.Insets)1