[問題] Hdf5轉Tiff檔 fabio讀取hdf5檔案時顯示錯
import os
import fabio
import numpy as np
def generate_tiff_files(fn, path, prefix, compress):
"""
Generate tiff files from a hdf file.
:param fn, metadata, path, prefix:
:return: -
"""
print('Generating TIFF Files...')
with fabio.open(fn) as fabio_img:
# create_tiff(fabio_img.data, metadata, path, prefix, 1)
create_tiff(fabio_img, path, prefix, 1, compress)
if fabio_img.nframes > 1:
for i in range(2, fabio_img.nframes + 1):
fabio_img = fabio_img.next()
# create_tiff(fabio_img.data, metadata, path, prefix, i)
create_tiff(fabio_img, path, prefix, i, compress)
log_progress(i, fabio_img.nframes)
print('Completed')
generate_tiff_files(r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\rat8_trabec1_225_data_000001.h5', r'rat8_trabec1_225_data_000001.h5', r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff', False)
這段程式碼是我在這個網站上找到的, 他寫說是可以把 h5轉成tiff檔. Convert HDF5 file to TIFF files — MuscleX 1.15.7 documentation
Source code在這: https://github.com/biocatiit/musclex/blob/master/musclex/utils/hdf5_to_tiffs.py
我嘗試要把h5的檔案轉成tiff檔,, 裝了Fabio 的 package 後試著跑了第二段的程式碼但卻跑出下面的錯誤訊息, 嘗試在stack overflow 上找過了可是大部分都說是因為檔案受損導致,我用確定沒受損的檔案也照樣會跑出錯誤訊息. 小弟我嘗試用關鍵字找但還是不知道為什麼fabio沒辦法讀h5檔, 我是這學期才剛開始學python, 還不是很熟悉. 請問我到底要怎麼辦才能讓fabio正常讀我想要的h5檔?
錯誤訊息:
Generating TIFF Files...
Traceback (most recent call last):
File "C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\hdf5_to_tiffs.py", line 120, in <module>
generate_tiff_files(r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\rat8_trabec1_225_data_000001.h5', r'rat8_trabec1_225_data_000001.h5', r'C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff', False)
File "C:\Users\wayne\OneDrive\Desktop\Test_hdf5_to_tiff\hdf5_to_tiffs.py", line 51, in generate_tiff_files
with fabio.open(fn) as fabio_img:
File "C:\Users\wayne\AppData\Local\Programs\Python\Python310\lib\site-packages\fabio\openimage.py", line 180, in openimage
obj = obj.read(obj.filename, frame)
File "C:\Users\wayne\AppData\Local\Programs\Python\Python310\lib\site-packages\fabio\eigerimage.py", line 159, in read
self._data = self.dataset[0][self.currentframe,:,:]
File "h5py\_objects.pyx", line 54, in h5py._objects.with_phil.wrapper
File "h5py\_objects.pyx", line 55, in h5py._objects.with_phil.wrapper
File "C:\Users\wayne\AppData\Local\Programs\Python\Python310\lib\site-packages\h5py\_hl\dataset.py", line 741, in __getitem__
return self._fast_reader.read(args)
File "h5py\_selector.pyx", line 370, in h5py._selector.Reader.read
OSError: Can't read data (can't open directory)
-----
Sent from JPTT on my iPhone
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 223.139.237.229 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1669201094.A.92F.html
→
11/23 22:51,
2年前
, 1F
11/23 22:51, 1F
→
11/23 22:51,
2年前
, 2F
11/23 22:51, 2F
→
11/23 22:52,
2年前
, 3F
11/23 22:52, 3F
→
11/23 22:52,
2年前
, 4F
11/23 22:52, 4F
→
11/23 22:53,
2年前
, 5F
11/23 22:53, 5F
推
11/24 08:59,
2年前
, 6F
11/24 08:59, 6F
→
11/24 09:03,
2年前
, 7F
11/24 09:03, 7F
→
11/24 09:03,
2年前
, 8F
11/24 09:03, 8F
→
11/24 09:53,
2年前
, 9F
11/24 09:53, 9F
Python 近期熱門文章
PTT數位生活區 即時熱門文章