我正在研究分析細胞旋轉的專案。資訊存盤在包含單元影像的 .dat 檔案中。我必須將其轉換為 tiff 檔案,然后連接所有影像以獲得 avi 視頻。問題是我沒有找到關于 dat 和 tiff 檔案的檔案。當我嘗試使用 Python 打開 .dat 檔案時,我收到以下錯誤訊息:
UnicodeDecodeError:“utf-8”編解碼器無法解碼位置 1 的位元組 0x9f:無效的起始位元組
相機是Andor Neo5.5 scmos(https://andor.oxinst.com/assets/uploads/products/andor/documents/andor-neo-scmos-specifications.pdf)
這是 .dat 檔案的示例:
https://drive.google.com/file/d/180VuU7XO9suUK0v8G1mlQu_ZGRdUHD0z/view?usp=sharing
顏色模式為灰度
相機的特點
uj5u.com熱心網友回復:
根據AndorSDK和一些逆向工程,該38.dat檔案包含一個 4 位元組整數,指定要跟隨的資料的長度,然后是 Mono12Packed 編碼的幀資料和一些額外的元資料,所有這些都以 little-endian 位元組順序排列。
來自 .DAT 檔案序列的幀資料可以解碼并寫入多頁 TIFF 檔案,而不會丟失精度。DAT 檔案中的一些元資料丟失:
import glob
import numpy
import tifffile
width = 2560
height = 2160
datfiles = glob.glob('*.dat')
with tifffile.TiffWriter('datfiles.tif', bigtiff=False) as tif:
for datfile in datfiles:
data = numpy.fromfile(
datfile,
count=width * height * 3 // 2, # 12 bit packed
offset=4, # 4 byte integer header
dtype=numpy.uint8,
).astype(numpy.uint16)
image = numpy.zeros(width * height, numpy.uint16)
image[0::2] = (data[1::3] & 15) | (data[0::3] << 4)
image[1::2] = (data[1::3] >> 4) | (data[2::3] << 4)
image.shape = height, width
tif.write(
image, photometric='minisblack', compression=None, metadata=None
)
根據幀資料的總大小,使用壓縮和/或 BigTIFF 格式。將幀資料保存為 AVI 時,會丟失一些資料。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/440854.html
標籤:Python matlab 生物信息学 tiff 数据转换
