Skip to content

Commit 401b3c5

Browse files
committed
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.
1 parent 205869c commit 401b3c5

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/imcflibs/imagej/misc.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,13 @@ def subtract_images(imp1, imp2):
416416
The ImagePlus resulting from the subtraction.
417417
"""
418418
ic = ImageCalculator()
419-
subtracted = ic.run("Subtract create", imp1, imp2)
419+
if imp1.getNSlices() != imp2.getNSlices():
420+
sys.exit(
421+
"Cannot subtract images with different number of slices, "
422+
"please check your input data."
423+
)
424+
option = " stack" if imp1.getNSlices() > 1 else ""
425+
subtracted = ic.run("Subtract create" + option, imp1, imp2)
420426

421427
return subtracted
422428

0 commit comments

Comments
 (0)