Created
December 5, 2014 17:14
-
-
Save hirokai/60ab0f796b0f0d3438e5 to your computer and use it in GitHub Desktop.
Fiji script: Time lapse of stitched images (conversion from (multipos,frames) to (frames))
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 02A: Make time lapse of stitched image. | |
from ij import IJ, ImagePlus, ImageStack, WindowManager | |
from ij.plugin import ContrastEnhancer,StackCombiner,ImageCalculator | |
from ij.process import ImageConverter, ImageProcessor | |
from java.awt.image import IndexColorModel | |
from time import sleep | |
import csv | |
from jarray import zeros | |
folder = "/Volumes/Macintosh HD/Google Drive/Groves/Scope 7/20141204 T cells short time fix with live imaging/" | |
positions = [["4-Pos_000_000", "4-Pos_000_001", "4-Pos_000_002", "4-Pos_000_003"], ["4-Pos_001_000", "4-Pos_001_001", "4-Pos_001_002", "4-Pos_001_003"], | |
["4-Pos_002_000", "4-Pos_002_001", "4-Pos_002_002", "4-Pos_002_003"], ["4-Pos_003_000", "4-Pos_003_001", "4-Pos_003_002", "4-Pos_003_003"]] | |
frames = map(lambda n: "img_000000"+"%03d"%(n)+"_RICM_000.tif", range(100)) | |
def mk_stack(ips,w,h): | |
res = ImageStack(w,h) | |
for ip in ips: | |
res.addSlice(ip) | |
return ImagePlus("frames",res) | |
def combine_multiple(w,h,ip): | |
res = ImageStack(w,h) | |
res.addSlice(ip[0]) | |
for ip in ip[1:]: | |
st = ImageStack(w,h) | |
st.addSlice(ip) | |
res = StackCombiner().combineHorizontally(res,st) | |
return res | |
def combine_multiple_v(w,h,ip): | |
res = ImageStack(w,h) | |
# print(ip[0]) | |
res.addSlice(ip[0]) | |
for ip in ip[1:]: | |
st = ImageStack(w,h) | |
st.addSlice(ip) | |
res = StackCombiner().combineVertically(res,st) | |
return res | |
#files: 2D list of file paths. | |
def stitch(files): | |
w = 200 | |
h = 200 | |
xlen = len(files[0]) | |
rows = [] | |
for row in files: | |
ips = [] | |
for f in row: | |
imp = IJ.openImage(f) | |
ip = imp.getProcessor() | |
ips.append(ip.resize(w)) | |
st = combine_multiple(w,h,ips) | |
rows.append(st.getProcessor(1)) | |
res = combine_multiple_v(w*xlen,h,rows).getProcessor(1) | |
# ImagePlus("test",res).show() | |
return res | |
def main(): | |
maxProcess = 1000 | |
count = 0 | |
imgs = [] | |
for fr in frames: | |
count += 1 | |
print(count) | |
if count > maxProcess: | |
break | |
files = [[folder + '02 FC1/tirf_2/' + pos + '/' + fr for pos in row] for row in positions] | |
imgs.append(stitch(files)) | |
im = mk_stack(imgs,800,800) | |
outpath = folder + "02A stitched frames/" + 'out.tif' | |
print(outpath) | |
IJ.save(im,outpath) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment