From 401b3c584ddf5dbb74475343812dc5a2a871b3fb Mon Sep 17 00:00:00 2001 From: Laurent Guerard Date: Mon, 8 Dec 2025 11:54:58 +0100 Subject: [PATCH 1/2] fix(image): validate slice count before subtraction * Added a check to ensure both images have the same number of slices. * Exits with an error message if the slice counts differ. * Adjusted the subtraction operation to handle stack images appropriately. --- src/imcflibs/imagej/misc.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/imcflibs/imagej/misc.py b/src/imcflibs/imagej/misc.py index dcf66f8..b1ae848 100644 --- a/src/imcflibs/imagej/misc.py +++ b/src/imcflibs/imagej/misc.py @@ -416,7 +416,13 @@ def subtract_images(imp1, imp2): The ImagePlus resulting from the subtraction. """ ic = ImageCalculator() - subtracted = ic.run("Subtract create", imp1, imp2) + if imp1.getNSlices() != imp2.getNSlices(): + sys.exit( + "Cannot subtract images with different number of slices, " + "please check your input data." + ) + option = " stack" if imp1.getNSlices() > 1 else "" + subtracted = ic.run("Subtract create" + option, imp1, imp2) return subtracted From 0a462643934f0eb9d48ae769fa8b30adb77f5c72 Mon Sep 17 00:00:00 2001 From: Laurent Guerard Date: Mon, 8 Dec 2025 11:59:06 +0100 Subject: [PATCH 2/2] fix(image): set calibration for subtracted images * Ensure the calibration of the first image is applied to the result of the subtraction. --- src/imcflibs/imagej/misc.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/imcflibs/imagej/misc.py b/src/imcflibs/imagej/misc.py index b1ae848..e8e2e2c 100644 --- a/src/imcflibs/imagej/misc.py +++ b/src/imcflibs/imagej/misc.py @@ -423,6 +423,7 @@ def subtract_images(imp1, imp2): ) option = " stack" if imp1.getNSlices() > 1 else "" subtracted = ic.run("Subtract create" + option, imp1, imp2) + subtracted.setCalibration(imp1.getCalibration()) return subtracted