In Fiji (ImageJ) I have two images open (Img1 and Img2). I want run a script that adds both images and stores the result in Img1. I'm boing to do this in a sequence of images so I would like to try to avoid creating and closing many images.
Would this be possible? I tried the code below but it crashes when I call the second Sum3and50.show()
after the first AddSlice()
call. Basically I would love to just be able to to Sum3and50+=imp[Slice]
from __future__ import division
from ij import IJ
from ij import plugin
import time
def AddSlice(Stack,SumImg,Slice):
Stack.setSlice(Slice)
ic = plugin.ImageCalculator()
SliceImg = ic.run("Copy create", Stack, Stack)
SliceImg.show()
time.sleep(SLEEP_TIME)
SumImg=ic.run("Add RGB", SumImg, SliceImg)
return SumImg
SLEEP_TIME=1 #seconds
#imp = IJ.getImage()
imp = IJ.openImage("http://imagej.nih.gov/ij/images/flybrain.zip");
W,H,NCh,NSl,NFr = imp.getDimensions()
imp.show()
Sum3and50 = IJ.createImage("Sum3and50", "RGB black", W, H, 1)
Sum3and50.show()
time.sleep(SLEEP_TIME)
Sum3and50 = AddSlice(imp,Sum3and50,3)
Sum3and50.show()
time.sleep(SLEEP_TIME)
Sum3and50 = AddSlice(imp,Sum3and50,5)
Sum3and50.show()