【发布时间】:2017-04-24 22:30:27
【问题描述】:
我正在尝试使用 Python 中的生物格式来读取显微镜图像(.lsm、.czi、.lif,你可以命名它),打印出元数据,并显示图像。 ome = bf.OMEXML(md) 给我一个错误(如下)。我认为这是在谈论存储在md 中的信息。它不喜欢md 中的信息不全是ASCII。但是我该如何克服这个问题呢?
这是我写的:
import Tkinter as Tk, tkFileDialog
import os
import javabridge as jv
import bioformats as bf
import matplotlib.pyplot as plt
import numpy as np
jv.start_vm(class_path=bf.JARS, max_heap_size='12G')
用户选择要使用的文件
#hiding root alllows file diaglog GUI to be shown without any other GUI elements
root = Tk.Tk()
root.withdraw()
file_full_path = tkFileDialog.askopenfilename()
filepath, filename = os.path.split(file_full_path)
os.chdir(os.path.dirname(file_full_path))
print('opening: %s' %filename)
reader = bf.ImageReader(file_full_path)
md = bf.get_omexml_metadata(file_full_path)
ome = bf.OMEXML(md)
将图像放入 numpy 数组中
raw_data = []
for z in range(iome.Pixels.get_SizeZ()):
raw_image = reader.read(z=z, series=0, rescale=False)
raw_data.append(raw_image)
raw_data = np.array(raw_data)
显示想要的元数据
iome = ome.image(0) # e.g. first image
print(iome.get_Name())
print(iome.Pixels.get_SizeX())
print(iome.Pixels.get_SizeY())
这是我得到的错误:
---------------------------------------------------------------------------
UnicodeEncodeError Traceback (most recent call last)
<ipython-input-22-a22c1dbbdd1e> in <module>()
11 reader = bf.ImageReader(file_full_path)
12 md = bf.get_omexml_metadata(file_full_path)
---> 13 ome = bf.OMEXML(md)
/anaconda/envs/env2_bioformats/lib/python2.7/site-packages/bioformats/omexml.pyc in __init__(self, xml)
318 if isinstance(xml, str):
319 xml = xml.encode("utf-8")
--> 320 self.dom = ElementTree.ElementTree(ElementTree.fromstring(xml))
321
322 # determine OME namespaces
<string> in XML(text)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in position 1623: ordinal not in range(128)
这是一位代表test image,拥有专有的显微镜格式
【问题讨论】:
-
你可以添加上传一张示例图片吗?
-
@MaximilianPeters,我刚刚添加了一个 .lsm 文件进行测试。任何建议,将不胜感激。谢谢!
标签: python xml ascii bioinformatics biopython