如何为一批图像提取元数据?我的第一个想法是记录一个宏,然后修改它以操作文件名列表。
在那种情况下,我尝试录制一个像这样的宏:
Ctrl-o # Open a file
12.dm3 输入 # Select file to open
Ctrl-i # Open metadata in a new window
Ctrl-s # Save file
12.txt的信息输入 # Name of file being saved
Ctrl-w # Close current window
Ctrl-w # Close current window
当我手动执行这些步骤时,这些步骤会起作用。这导致以下宏,这似乎缺少我试图记录的大部分内容:
open("/path/to/file/12.dm3");
run("Show Info...");
run("Close");
run("Close");
答案 0 :(得分:2)
修改Jython script that is supposed to extract dimension metadata from an image:
from java.io import File
from loci.formats import ImageReader
from loci.formats import MetadataTools
import glob
# Create output file
outFile = open('./pixel_sizes.txt','w')
# Get list of DM3 files
filenames = glob.glob('*.dm3')
for filename in filenames:
# Open file
file = File('.', filename)
# parse file header
imageReader = ImageReader()
meta = MetadataTools.createOMEXMLMetadata()
imageReader.setMetadataStore(meta)
imageReader.setId(file.getAbsolutePath())
# get pixel size
pSizeX = meta.getPixelsPhysicalSizeX(0)
# close the image reader
imageReader.close()
outFile.write(filename + "\t" + str(pSizeX) + "\n")
# Close the output file
outFile.close()
(Gist)。
答案 1 :(得分:1)
您可以使用getImageInfo()而不是run(" Show Info ...")。这将在包含run(" Show Info ...")输出的宏中创建一个字符串,但随后可以根据需要进行修改。有关详细信息,请参阅http://rsb.info.nih.gov/ij/developer/macro/functions.html#getImageInfo。