| 12345678910111213141516171819202122232425262728 |
- import tifffile as tiff
- import matplotlib.pyplot as plt
- import numpy as np
- # 读取 TIFF 图像
- 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") # 替换成你的路径
- # 检查图像维度
- print("Image shape:", img.shape)
- # 假设图像是 H x W x C 结构(通道在最后)
- if img.ndim == 3 and img.shape[2] >= 3:
- rgb_img = img[:, :, :3] # 取前三个通道
- elif img.ndim == 3 and img.shape[0] >= 3:
- rgb_img = np.transpose(img[:3, :, :], (1, 2, 0)) # 如果是 C x H x W 格式
- else:
- raise ValueError("图像不是 RGB 结构,或通道数不足3个")
- # 归一化处理以便可视化
- rgb_img = rgb_img.astype(np.float32)
- if rgb_img.max() > 1.0:
- rgb_img /= rgb_img.max()
- # 显示图像
- plt.imshow(rgb_img)
- plt.title("First 3 Channels of TIFF")
- plt.axis('off')
- plt.show()
|