如何一次平均多个堆栈?理想情况下使用像ImageJ这样的GUI工具?我想在大约10-20个堆栈上执行此操作:1500x1500像素,500个切片,每个堆栈中有1个通道。一次加载所有这些将推动我的RAM的限制。
作为输出,我想要一个堆栈(1500x1500像素,500个切片,1个通道),并且在不同堆栈中平均强度。
ImageJ似乎限于一次平均2个堆栈。
我希望最终平均值中所有筹码的权重相等。
答案 0 :(得分:2)
理想情况下使用像imageJ这样的GUI工具
有关ImageJ的用法且与任何代码无关的问题在stackoverflow.com上都是偏离主题的,应该最好在ImageJ forum上询问。
如何一次平均多个堆栈?
在ImageJ中,您可以从堆栈中构建 hyperstack (例如,使用 Image> Stacks> Tools> Concatenate ... 和然后 Image> Hyperstacks> Stack to Hyperstack ... )并随后创建一个平均投影( Image> Stacks> Z Project ... )。 要完成任务,您应该为每个堆栈分配500个切片到 t 维度,要平均的维度应该是 z 。
希望有所帮助。
答案 1 :(得分:0)
我有太多的堆栈将它们全部组合成一个大的hyperstack。我的内存不足了。
我最终使用了python:
import tkFileDialog
import os
import matplotlib.pyplot as plt
from PIL import Image
import numpy as np
import glob
from tifffile import imsave
#select a directory containing tif-stacks to process
#tif-stacks must have equal dimensions
sd=tkFileDialog.askdirectory()
#list of files to process
fl= glob.glob(os.path.join(sd,'*.tif'))
#number of files to process
n_files=np.shape(fl)[0]
im = Image.open(fl[0])
#get number of frames in first file by seeking all frames until error occurs
#this seems clunky but is very fast
#assuming same number of frames for all files
n = 0
while True:
n += 1
try:
im.seek(n)
except:
break
n_frames=n
#loop through all images,
#read each frame and accumulate frame-wise sum over all stacks
w, h = im.size
temp = np.zeros( (h,w,n_frames), dtype=np.int32 )
for i in range(n_files):
print 'processing file: ', i
im = Image.open(fl[i])
for n in range (n_frames):
curframe = np.array(im.getdata()).reshape(h,w)
temp[:,:,n] += curframe
im.seek(n)
print ['frame: ', n]," \r",
avgStack=temp/n_files
答案 2 :(得分:0)
我稍微修改了jlarsch的代码,因为它没有在python3中运行。这是我的解决方案:
from tkinter import filedialog
import os
from PIL import Image
import numpy as np
import glob
from tifffile import imwrite, imread
#select a directory containing tif-stacks to process
#tif-stacks must have equal dimensions
sd=filedialog.askdirectory()
fl = glob.glob(os.path.join(sd, '*.tif'))
#list of files to process
fl= glob.glob(os.path.join(sd,'*.tif'))
#number of files to process
n_files=np.shape(fl)[0]
#get number of frames in first file by seeking all frames until error occurs
#this seems clunky but is very fast
#assuming same number of frames for all files
with Image.open(fl[0]) as im:
h,w=im.size
n = 0
while True:
n += 1
try:
im.seek(n)
except:
break
n_frames = n
#loop through all images,
#read each stack and append to a 4-dimensional numpy array
w, h = im.size
temp = np.empty((0,n_frames,h,w), dtype=np.int32)
for i in range(n_files):
stack = imread(fl[i])
temp = np.append(temp, stack[np.newaxis, :], axis=0)
#average over all stacks
average=np.mean(temp,axis=0)
imwrite('average.tif', average)