B&C for a whole virtual stack



is there a way to set Brightness & Contrast for a virtual stack and apply it to all frames?

“Apply does not work with virtual stacks”

i don’t know the inner workings, but i don’t immediately see why it isn’t possible to do this with a virtual stack. would performing this calculation on the fly make navigating through the images too choppy?

i have a long time series with multiple channels and it takes 3+ minutes to load all the images as normal stacks, when all i want to do is quickly view them (channel windows synchronized, B&C such that i can also see the dim images).

when i select a window and click “Auto” in B&C I get:

Exception in thread "ContrastAdjuster" java.lang.ClassCastException: loci.plugins.util.RecordedImageProcessor cannot be cast to ij.process.ByteProcessor
	at ij.process.ByteStatistics.<init>(ByteStatistics.java:17)
	at ij.process.ImageStatistics.getStatistics(ImageStatistics.java:76)
	at ij.ImagePlus.getRawStatistics(ImagePlus.java:854)
	at ij.plugin.frame.ContrastAdjuster.autoAdjust(ContrastAdjuster.java:787)
	at ij.plugin.frame.ContrastAdjuster.doUpdate(ContrastAdjuster.java:1110)
	at ij.plugin.frame.ContrastAdjuster.run(ContrastAdjuster.java:1063)
	at java.lang.Thread.run(Thread.java:745)


Dear @dpschreiner,

The ImageJ manual states:

Apply Applies the current display range mapping function to the pixel data. If there is a selection, only pixels within the selection are modified. This option currently only works with 8-bit images, 8-bit stacks and RGB stacks. This is the only B&C option that alters the pixel data of non-RGB images.

Since Virtual Stacks are not residing in memory it’s not possible to change pixel values, which is what Apply is doing.

What exactly are you trying to achieve? Are you looking for an automated method or a manual one? Should it take into account the histogram of the complete stack or just the currently active image?



thanks for the quick reply, Stefan.

sorry for not being clearer - my goal is a lazy-loading movie viewer that allows the user to scroll through a movie (thousands of time points) and up to 4 channels, with channels split into separate windows and be able to set brightness levels for each channel’s stack (the whole stack, not an individual image). i can do the split channels part by creating an OME-TIFF for the movie and then importing into imageJ. but i cannot persistently set the brightness levels per channel with a virtual stack; if i set the levels, they get reset as soon as i move to the next time point.

unless i am missing something, i think this basically implies the concept of a window-specific max/min setting (rather than per image). the only purpose of this is to make it easier to see dim signals more easily with the eye. i guess i’m seeking a kind of lazy application of a given window’s min/max to the virtual stack as one progresses through the time points.

there may be more than 100 such movies for one experiment, and the user needs to look through them in a relatively time-efficient manner to see which movies are worth analyzing further. this is why loading all the images into memory (~4 minutes for a typical movie on our machine) is not ideal.


I am not aware of that functionality in ImageJ.

You could maybe, and this is just thinking out loud, implement a plugin/macro that records the set B&C settings in combination with a custom play/“next image” button that changes the slice on all open images and applies the B&C settings. That, however, would require some coding, unless someone else comes up with a more sensible solution.


Hi @dpschreiner,

I had this problem myself for a long time. I don’t know if this is a new feature, but it is possible. Sometimes holding the shift key as the video is playing or when changing frames works. But this hasn’t been working for me with the SCIFIO reader.

What does work is setting the option Edit -> Options -> Appearance -> Auto contrast stacks.

This setting isn’t saved when closing ImageJ, but you can save it as a startup macro. Just add run("Appearance...", "auto"); to Edit -> Options -> Startup.