tiffshow.py 877 B

12345678910111213141516171819202122232425262728
  1. import tifffile as tiff
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. # 读取 TIFF 图像
  5. img = tiff.imread(r"\\192.168.50.222\share2\zyh\data\rgbd_line\rgbd_tiff\2025-07-21-09-10-52_LaserData_ID019504_rgbd.tiff") # 替换成你的路径
  6. # 检查图像维度
  7. print("Image shape:", img.shape)
  8. # 假设图像是 H x W x C 结构(通道在最后)
  9. if img.ndim == 3 and img.shape[2] >= 3:
  10. rgb_img = img[:, :, :3] # 取前三个通道
  11. elif img.ndim == 3 and img.shape[0] >= 3:
  12. rgb_img = np.transpose(img[:3, :, :], (1, 2, 0)) # 如果是 C x H x W 格式
  13. else:
  14. raise ValueError("图像不是 RGB 结构,或通道数不足3个")
  15. # 归一化处理以便可视化
  16. rgb_img = rgb_img.astype(np.float32)
  17. if rgb_img.max() > 1.0:
  18. rgb_img /= rgb_img.max()
  19. # 显示图像
  20. plt.imshow(rgb_img)
  21. plt.title("First 3 Channels of TIFF")
  22. plt.axis('off')
  23. plt.show()