我有25K个tif文件(请不要问为什么),我想在图像J上将它们组织成堆栈。基本上,对于每个感兴趣区域(ROI),有50个图像,这些图像分解为两个通道的25个z平面。我希望所有的东西都放在一个堆栈中。我想批量处理整个文件夹,而不是一次打开50张图片500次。我附上了一张文件名的图片:
r01c01f01p01-ch1.tif -前10个字符是每个感兴趣区域的唯一ID,依次是平面编号(p01)、通道- ch1或ch2,最后是文件扩展名
以下是我到目前为止所拥有的(我是基于其他宏拼凑起来的,所以这可能没有意义……).This使用的是ImageJ宏语言。
//Processing loop to process each file in the folder.
for (i=0; i<list.length; i++) {
showProgress(i+1, list.length);
if (endsWith(list[i], ".tif")) { // skip the subfolder (I create a subfolder earlier in the macros)
print("-- Processing file: " + list[i] + " --");
open(dir+list[i]);
imageTitle= getTitle();
newTitle = substring(imageTitle, 0, lengthOf(imageTitle)-10); // r01c01f01p, cutting off plane number and then the rest to just get the ROI ID
//This is where I'm stuck:
// find all files containing newTitle and open them (which would be 50 at a time), then run the following macros on them
run("Images to Stack", "name=Ch1 title=[] use");
run("Duplicate...", "title=Ch2 duplicate");
selectWindow("Ch1");
run("Slice Remover", "first=1 last=50 increment=2");
selectWindow("Ch2");
run("Slice Remover", "first=2 last=50 increment=2");
run("Merge Channels...", "c1=Ch1 c2=Ch2 create");
saveAs("tiff", dirNew + newTitle + "_Stack.tif");
//Close(All)?
}
}
print("-- Done --");
showStatus("Finished.");
setBatchMode(false); // Exit batch mode
run("Collect Garbage");
谢谢!
发布于 2019-10-04 21:44:37
你可以这样做:
for (plane=1; plane<51; plane++) {
open(newTitle+plane+"-ch1.tif");
open(newTitle+place+"-ch2.tif");
}
这样就能搞定开场了。我倾向于在此之前有一个循环来整理唯一的“newTitle”的数量,因为你现在的设置最终会做一些事情,比如打开第一个项目,组装组合的TIF,然后重复这个过程25K次,如果我理解正确的话。
假设您知道唯一的"r01c01f01p“值的数量,原则上您可以执行一组堆叠循环,类似于:
newTitleArray = newArray();
for (r=1; r<50; r++) {
titleBit = "r0" + toString(r);
for (c=1; c<501; c++) {
titleBit = titleBit + "f0"...
或者,您可以设置一个循环,在其中检查唯一的"r01c01f01p“值并将它们添加到数组中。在任何情况下,您都可以将for "list“循环替换为for "newTitleArray”循环,然后继续使用上面列出的打开器,而不是现有的打开器。
发布于 2019-10-04 22:14:43
如果我没理解错的话,看起来你最好先按通道堆栈,然后再合并这两个通道。我不是百分之百确定,但我认为你可能会使用我已经创建的宏来做这件事。它最初的目的是批量处理to级的5D数据,因此它应该可以非常轻松地处理大量图像。它不完全是你想要的,但应该非常容易修改(我在代码中的注释有点过头了),我认为它唯一做的事情,你可能不希望它是从输入产生最大的项目。我会在这里抛出一个链接,并期待你的回复。如果感兴趣,请让我知道,我们可以一起努力使其符合您的需求:-)否则,如果您能提供更多细节,说明您遇到的问题和/或我可能误解的地方,我将尽我最大的努力帮助您!
https://stackoverflow.com/questions/58237279
复制相似问题