Unexpected behavior from screen shot

I am working through Ellen Arena’s tutorial on segmentataion and trying to document my analysis. I am doing this with Fiji on MacOS Mojave. I encountered an odd behavior when I did a screen print from the Mac (CMD+shift+4 and trace…). I uploaded the file below and it renders properly here:

jrm-sceen-shot

It does not render as normal PNG in Fiji… Fiji tells me this is a four channel stack…

SCIFIO version: 0.37.3
File format: Animated PNG
--- Dataset Information ---
BitsPerPixel = 8
PixelType = 1
Dataset name = /Users/jrminter/Desktop/jrm-sceen-shot.png
Image 0 Information
Dimension order = X,Y,Channel
Dimension lengths = 454,482,4
--- Global Metadata ---
--- Image Metadata ---
separate default = true

------------------------------------------------------
(Fiji Is Just) ImageJ 2.0.0-rc-69/1.52n; Java 1.8.0_202 [64-bit]; Mac OS X 10.14.5; 260MB of 8284MB (3%)
 
Title: jrm-sceen-shot.png
Width:  454 pixels
Height:  482 pixels
Depth:  1 pixels
Size:  855K
Voxel size: 1x1x1 pixel^3
ID: -14
Bits per pixel: 8 (color LUT)
Display ranges
  1: 0-255
  2: 0-255
  3: 0-255
  4: 0-255
Image: 1/4 (1)
  Channels: 4
  Composite mode: "composite"
Stack type: virtual
No threshold
ScaleToFit: false
Uncalibrated
Path: /Users/jrminter/Desktop/jrm-sceen-shot.png
Screen location: 159,144 (1440x900)
SetMenuBarCount: 14 (347ms)
Coordinate origin:  0,0,0
No overlay
No selection

I cannot seem to find a way to convert this to a normal RGB png. I’m hoping someone will quickly see the problem and offer a solution. I’m stumped…

This behavior is true for any Mac OSX screenshot when opened with #scifio, and completely independent of the Trainable Weka Segmentation plugin.

To open files like these a RGB image, please deselect the

  • Use SCIFIO when opening files (BETA!)

option in Edit › Options › ImageJ2….


To explain this behavior: screenshots created using Cmd Shift 4 on Mac OSX are saved as RGBA images in PNG format. This means that in addition to the RGB color channels, they contain an Alpha channel encoding the opacity of the image. You can nicely see this when pressing Space after the shortcut for the screenshot to activate the full window mode. This will save a PNG containing some transparent space and a shadow around the window being recorded.

Here’s the alpha channel of this image:

The “problem” is in the difference how ImageJ 1.x and SCIFIO handle these images.

  • ImageJ 1.x doesn’t have the concept of transparency in color images, it therefore opens only the RGB channels and ignores the Alpha channel.
  • In contrast, SCIFIO correctly reads it as a 4-channel image, but the display of this image (in the legacy UI) is wrong in the sense that the fourth channel gets assigned a default color (cyan) that doesn’t reflect the purpose of this channel.

A solution to display the 4-channel image in the way it is intended to be displayed would be to change channel 4 to an inverted grayscale LUT.

2 Likes

Thanks. That helps. I spent the afternoon seeing if I could generate the png. I have a jython script that that works. I’m including it at the end in case someone ever needs it… I think I’ll follow your advice and just deselect the Use SCIFIO.

"""
make_rgb_from_stack_4.py

make a RGB image from a Weka 4 channel image

  Modifications
  Date      Who  Ver                       What
----------  --- ------  -------------------------------------------------
2019-05-17  JRM 0.1.00  Test function in to generate an RGB image

"""

from org.python.core import codecs
codecs.setDefaultEncoding('utf-8')

import os
from ij import IJ, WindowManager

def convert_stack_4_to_rgb(imp):
	"""
	Convert a 4 image stack with a uniform cyan channel 4
	to a RGB image.

	Parameters
	==========
	imp ImagePlus
		The image to be converted

	Returns
	=======
	
	"""
	title = imp.getShortTitle()
	imp.setTitle(title)
	IJ.run("Stack to Images")
	impR = WindowManager.getImage("1")
	impG = WindowManager.getImage("2")
	impB = WindowManager.getImage("3")
	IJ.run("Merge Channels...", "c1=1 c2=2 c3=3 ignore")
	impRGB = WindowManager.getImage("RGB")
	# impRGB.show()
	impC = WindowManager.getImage("4")
	impC.close()
	impR.close()
	impG.close()
	impB.close()
	return (impRGB)
	
IJ.run("Close All")
imgDir = "/Users/jrminter/Desktop/"
imgNam = "jrm-screen-shot"
imgExt = ".png"
imgPath = imgDir + imgNam + imgExt
imgFullName = imgNam + imgExt
IJ.open(imgPath)
imp = IJ.getImage()
impRGB = convert_stack_4_to_rgb(imp)
impRGB.show()



Question for the community: what could we do to make this behavior better and less confusing? Implement support for alpha in ImageJ somehow? I do not think assigning the alpha channel an inverted grayscale LUT is sufficient, is it?

1 Like