Class ImageDisplay

All Implemented Interfaces:
ImageRenderer

public class ImageDisplay extends AbstractImageRenderer
Class used to look after the color transforms that may be applied to an image, including brightness/contrast settings.

Warning! This implementation is likely to change in a future version.

  • Property Details

  • Constructor Details

    • ImageDisplay

      public ImageDisplay()
      Constructor.
  • Method Details

    • create

      public static ImageDisplay create(ImageData<BufferedImage> imageData) throws IOException
      Create a new image display, and set the specified image data.
      Parameters:
      imageData - the image to set initially; may be null
      Returns:
      a new instance
      Throws:
      IOException - if an exception occurs when trying to set the image
    • setImageData

      public void setImageData(ImageData<BufferedImage> imageData, boolean retainDisplaySettings) throws IOException
      Set the ImageData to a new value
      Parameters:
      imageData - image data that should be displayed
      retainDisplaySettings - if true, retain the same display settings as for the previous image if possible (i.e. the images have similar channels)
      Throws:
      IOException
    • getImageData

      public ImageData<BufferedImage> getImageData()
      Get the current image data
      Returns:
    • useGrayscaleLutProperty

      public BooleanProperty useGrayscaleLutProperty()
      Property that specifies whether grayscale lookup tables should be preferred to color lookup tables
      Returns:
    • useGrayscaleLuts

      public boolean useGrayscaleLuts()
      Get the value of useGrayscaleLutProperty()
      Returns:
    • setUseGrayscaleLuts

      public void setUseGrayscaleLuts(boolean useGrayscaleLuts)
      Set the value of useGrayscaleLutProperty()
      Parameters:
      useGrayscaleLuts -
    • useInvertedBackgroundProperty

      public BooleanProperty useInvertedBackgroundProperty()
      Property that specifies whether the background should be inverted (i.e. to make fluorescence resemble brightfield, and vice versa)
      Returns:
      See Also:
    • useInvertedBackground

      public boolean useInvertedBackground()
      Returns:
    • displayMode

      public ObjectBinding<ChannelDisplayMode> displayMode()
      Returns:
    • setUseInvertedBackground

      public void setUseInvertedBackground(boolean useInvertedBackground)
      Parameters:
      useInvertedBackground -
    • useColorLUTs

      public boolean useColorLUTs()
      The opposite of useGrayscaleLuts()
      Returns:
    • getLastChangeTimestamp

      public long getLastChangeTimestamp()
      Get the event count, which is here used as an alternative to a timestamp.
      Returns:
    • eventCountProperty

      public LongProperty eventCountProperty()
      Counter for the number of display changes that have been made.

      Note: This replaces a timestamp property used before v0.6.0. It should be more reliable, because changes occurring in quick succession can still be captured - whereas previously any changes that were faster than the millisecond close might get lost.

      Returns:
    • refreshChannelOptions

      public void refreshChannelOptions()
      Refresh the channel options. This may be used if an underlying property of the image has changed, such as the channel names or lookup tables.
    • switchToGrayscaleChannelProperty

      public ObjectProperty<ChannelDisplayInfo> switchToGrayscaleChannelProperty()
      Property indicating which channel should be used if useGrayscaleLutProperty() is turned on. This is useful to develop more intuitive interfaces and prevent surprises when switching to grayscale mode.

      Settings this value does not have any immediate effect on whether channels are selected or not, but rather it is only used when switching to grayscale mode.

      Returns:
      Since:
      v0.5.0
      See Also:
    • setSwitchToGrayscaleChannel

      public void setSwitchToGrayscaleChannel(ChannelDisplayInfo channel)
      Parameters:
      channel -
      Since:
      v0.5.0
    • getSwitchToGrayscaleChannel

      public ChannelDisplayInfo getSwitchToGrayscaleChannel()
      Returns:
      Since:
      v0.5.0
    • setMinMaxDisplay

      public void setMinMaxDisplay(ChannelDisplayInfo info, float minDisplay, float maxDisplay)
      Set the min/max display values for a specified ChannelDisplayInfo.

      The benefit of calling this method is that it will update the ImageData metadata if appropriate.

      Parameters:
      info -
      minDisplay -
      maxDisplay -
    • saveChannelColorProperties

      public void saveChannelColorProperties()
      Save color channels in the ImageData properties. This lets them be deserialized later.
    • selectedChannels

      public ObservableList<ChannelDisplayInfo> selectedChannels()
      Read-only observable list containing the channels currently selected for display.
      Returns:
      the selected channels
      See Also:
    • availableChannels

      public ObservableList<ChannelDisplayInfo> availableChannels()
      Read-only observable list containing the channels currently available for display.
      Returns:
      the available channels
      See Also:
    • setChannelSelected

      public void setChannelSelected(ChannelDisplayInfo channel, boolean selected)
      Set the selection of a channel on or off.

      If a channel's isAdditive() method returns false, all other selected channels will be cleared. Otherwise, other selected channels will be cleared if they are non-additive - but kept if they are additive (and therefore can be sensibly displayed in combination with this channel).

      Parameters:
      channel - the channel
      selected - true if the channel should be selected, false if it should not
    • applyTransforms

      public BufferedImage applyTransforms(BufferedImage imgInput, BufferedImage imgOutput)
      Apply the required transforms to a BufferedImage to get the appropriate display.

      Warning: This is not thread-safe.

      Parameters:
      imgInput - the input image; this should not be null, and should be of a type that matches the ImageData (i.e. same number of channels, same bit-depth).
      imgOutput - the output image (optional); if not null, this should be an RGB image (usually TYPE_INT_RGB).
      Returns:
      the transformed image; this may be the same as imgOutput, if provided
    • applyTransforms

      public static BufferedImage applyTransforms(BufferedImage imgInput, BufferedImage imgOutput, List<? extends ChannelDisplayInfo> selectedChannels, ChannelDisplayMode mode)
      Convert an image to RGB by applying the specified ChannelDisplayInfos and ChannelDisplayMode.
      Parameters:
      imgInput - the input image to transform
      imgOutput - optional output image (must be the same size as the input image, and RGB)
      selectedChannels - the channels to use
      mode - the mode used to determine RGB colors for each channel
      Returns:
      an RGB image determined by transforming the input image using the specified channels
    • getTransformedValueAsString

      public String getTransformedValueAsString(BufferedImage img, int x, int y)
      Get a string representation of a transformed pixel value, using the currently-selected channels.
      Parameters:
      img - image providing the value
      x - x-coordinate of the pixel
      y - y-coordinate of the pixels
      Returns:
      a String representation of the pixel's transformed value
    • autoSetDisplayRange

      public void autoSetDisplayRange(ChannelDisplayInfo info)
      Automatically set the display range for a channel, using the default saturation defined in PathPrefs.autoBrightnessContrastSaturationPercentProperty().
      Parameters:
      info - channel to update
    • autoSetDisplayRange

      public void autoSetDisplayRange(ChannelDisplayInfo info, double saturation)
      Automatically set the display range for a channel.
      Parameters:
      info - channel to update
      saturation - proportion of pixels that may be saturated, i.e. have the max/min display values (between 0.0 and 1.0)
    • getHistogram

      public Histogram getHistogram(ChannelDisplayInfo channel)
      Returns a histogram for a channel of the current image.
      Parameters:
      channel - the channel
      Returns:
      the histogram for the specified channel, or null if no histogram is available (e.g. the channel is a packed RGB representation that can't have a single histogram associated with it)
    • toJSON

      public String toJSON(boolean prettyPrint)
      Create a JSON representation of the main components of the current display.
      Parameters:
      prettyPrint - optionally request pretty printing
      Returns:
      the Json representation, or null if no image has been set
    • isCompatible

      public boolean isCompatible(ImageDisplay display)
      Check if an image display is 'compatible' with this one. Compatible means that they have the same number of channels, and the same channel names.
      Parameters:
      display - the other display with which to check compatibility
      Returns:
      true if the display is compatible, false otherwise
    • updateFromDisplay

      public boolean updateFromDisplay(ImageDisplay display)
      Update the current display based upon a different display. This only makes changes if isCompatible(ImageDisplay) returns true.

      This method exists to make it easier to sync display settings across viewers.

      Parameters:
      display -
      Returns: