J'essaie d'utiliser des bioformats en Python pour lire une image microscopique (.lsm, .czi, .lif , vous l'appelez), imprimez les métadonnées et affichez l'image. ome = bf.OMEXML(md)
me donne une erreur (ci-dessous). Je pense qu'il parle de l'information stockée dans md
. Il n'aime pas que les informations dans md
ne sont pas tous ASCII. Mais comment puis-je surmonter ce problème? C'est ce que je l'ai écrit:Erreur bioformats-Python: le codec 'ascii' ne peut pas encoder le caractère 'xb5' lorsque vous utilisez OMEXML()
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')
L'utilisateur sélectionne le fichier pour travailler avec
#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)
image rangea 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)
Afficher voulait métadonnées
iome = ome.image(0) # e.g. first image
print(iome.get_Name())
print(iome.Pixels.get_SizeX())
print(iome.Pixels.get_SizeY())
Voilà l'e rror je reçois:
---------------------------------------------------------------------------
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)
est ici un test image représentant au format de la microscopie exclusive
Pouvez-vous ajouter un exemple d'image? –
@MaximilianPeters, je viens d'ajouter un fichier .lsm pour les tests. Toute suggestion serait appréciée. Merci! – puifais