Deleting slices from 3D datasets using pyimagej

Fiji version = 2.1.0/1.53c; Java 1.8.0_202 [64-bit]

Hello,

This is a very basic question, but I’m just starting to learn image processing with python and have been using the pyimagej tutorials to learn how to integrate with Fiji. I’m stuck on how to use xarrays because I have never done this before!

I want to subtract one image from another, either using the ImageCalculator in Fiji, or some more pythonic way. I cannot figure out how to call ImageCalculator in pyimageJ, of if I’m calling any plugin, how to know what the argument names are?

So far trying to do this in pyimagej with xarrays I have the following code:

import imagej

from skimage import io

import numpy as np


ij_img = ij.io().open(file) #pretend the file has dimensions of (Time:80, x:512, y:512)
py_img = ij.py.from_java(ij_img) #pull the file from fiji

delFront = np.delete(py_img, np.s_[:4], 0) #delete the first 4 slices?
delEnd = np.delete(py_img, np.s_[76:80:1], 0) #delete the last 4 slices?

newImg = delFront - delEnd #subtract the two images from each other?

This does not do what I wanted it to (which was to subtract the pixel values from each other across all remaining slices). It gives me a weird output that shows:

xarray.DataArray (Time:76, y:512, x:512)

but still has all 80 slices for the Time coordinates at the bottom.

I’m assuming it’s doing something weird like deleting the values in the Time column but leaving the x and y values? I’m not sure but it has me confused!

So I guess my questions are:

  1. How do I perform this function? Do I need to use xarray or when do I use io.imread()?
  2. If I do want to use Fiji plugins like ImageCalculator, how to I import them and how do I know which args to specify (I was reading the plugins jupyter notebook here).

Thanks so much!
Ani