Image calculator for hyperstack

Hi all, new here :slight_smile:
I am wondering what the best process is to perform image calculations on a hyperstack. I’d like to do flatfield correction using an empty reference image on all images in a hyperstack. Both the reference and the images to be processed have 2 channels (c ), 10 slices (z), and 1 frame (t).

If I just do Image calculator and divide the image by the reference, I get a completely black output on all slices in both channels for all images I tested.

Does anyone know a good way to do this? I’m hoping to avoid splitting the hyperstacks up into individual images since I need to batch process a folder of images, and that sounds messy.

Thanks for any help!
Crawdauntz

Did you select the Create new window and 32-bit (float) result options in Image Calculator? In my tests, I get the expected hyperstack result containing the correct values, but I need to adjust Brightness & Contrast (Shift+C) for each channel in order to display the intensities correctly.

Here’s a macro that recapitulates my tests:

// Load sample image
run("Mitosis (26MB, 5D stack)");

// Create reference by duplicating and blurring
run("Duplicate...", "title=reference duplicate");
run("Gaussian Blur...", "sigma=20");

// Divide image by reference
imageCalculator("Divide create 32-bit stack", "mitosis.tif","reference");
selectWindow("Result of mitosis.tif");

// Re-adjust display settings
setSlice(1);
resetMinAndMax();
setSlice(2)
resetMinAndMax();
1 Like

Thanks for the response! Your macro works just fine on my fiji, with no need to adjust brightness or contrast.

I just realized by opening the resulting .tif in a separate program (Preview on Mac) it actually worked! I can see the signal in the resulting image. But loading that .tif in fiji I just see black. You were right, I just needed to adjust my brightness and contrast. For some reason it loads with the minimum = maximum intensity.

Thanks :slight_smile:

p.s. Any idea why I might not need to adjust brightness/contrast for your macro, but I do need to for my macro? Intrinsic properties of the images?

p.p.s. This is the macro I am using (part of a loop processing a folder of images):

//Code for loop
imageTitle=getTitle(); //returns a string with the image title
selectWindow(imageTitle);
imageCalculator("Divide create 32-bit stack", imageTitle,"chromaFile2.tif");2
selectWindow("Result of "+imageTitle);
// Save the last active image
saveAs("tif", output_folder+"/"+files[i]+"_result.tif");

The comments in my above macro code were meant to help understanding the different parts. Have a close look at the section // Re-adjust display settings and try to understand what it is doing. Without this section, you will have to adjust display settings manually, but with this section it’s done automatically when running the macro.

Ah… yeah it’s right there. Haha. Sorry! Thanks for the help. :slight_smile:

Cheers