반응형
depth pro output이 jpg, npz 두가지 형식으로 나오는데 나는 absolute depth가 필요하다
처음에 jpg를 불러왔는데 rgb 3channel 이미지라 맞지 않았다
depth output 으로 깊이값 like regression으로 형식 맞춰야함
cv.image unchange? 하면 rgb 그대로 유지돼서 안되고, grayscale하면 jpg 이용하긴 하는거라 show할때 알아서 ~255로 정규화되기 때문에 relative depth로 나타나짐 -> 이게 아님
그래서 npz의 absolute depth를 알아내서 써야할 것 같다
이거에 도움되는코드
차이점
# jpg로 로드
✅ Depth Map Shape: (332, 500, 3)
🔹 Depth Min Value: 0
🔹 Depth Max Value: 255
🔹 Depth Mean Value: 112.6892469879518
🔍 This is likely relative depth.
# npz로 로드
Available keys in the NPZ file: ['depth']
✅ Depth Map Shape: (332, 500)
🔹 Depth Min Value: 1.5595979690551758
🔹 Depth Max Value: 134.40841674804688
🔹 Depth Mean Value: 16.044923782348633
The depth map is single-channel (grayscale).
1. NPZ 파일의 데이터 구조 확인 코드
import numpy as np
import matplotlib.pyplot as plt
# ✅ 1. NPZ 파일 경로 설정
file_path = "경로/001762_225.npz"
# ✅ 2. NPZ 파일 로드
data = np.load(file_path)
# ✅ 3. NPZ 파일의 키 확인
print(f"Available keys in the NPZ file: {data.files}")
# ✅ 4. Depth Map 데이터 가져오기
if 'depth' in data.files:
depth_map = data['depth']
else:
raise KeyError(f"Depth map key not found in the file. Available keys are: {data.files}")
# ✅ 5. Depth Map 기본 정보 출력
depth_min = np.min(depth_map)
depth_max = np.max(depth_map)
depth_mean = np.mean(depth_map)
print(f"✅ Depth Map Shape: {depth_map.shape}") # 예: (Height, Width)
print(f"🔹 Depth Min Value: {depth_min}")
print(f"🔹 Depth Max Value: {depth_max}")
print(f"🔹 Depth Mean Value: {depth_mean}")
# ✅ 6. 단일 채널인지 확인
if len(depth_map.shape) == 2:
print("The depth map is single-channel (grayscale).")
elif len(depth_map.shape) == 3 and depth_map.shape[-1] == 1:
print("The depth map is single-channel but stored as a 3D array with one channel.")
elif len(depth_map.shape) == 3:
print("The depth map is multi-channel (e.g., RGB).")
else:
print(f"Unexpected shape format: {depth_map.shape}")
# ✅ 7. Depth Map 시각화
plt.figure(figsize=(10, 6))
plt.title("Depth Map Visualization")
plt.imshow(depth_map, cmap="viridis") # 다른 컬러맵: 'jet', 'plasma', 'inferno' 등
plt.colorbar(label="Depth")
plt.xlabel("Width")
plt.ylabel("Height")
plt.show()
2. 설명
- Shape: depth_map.shape를 통해 데이터의 크기와 차원을 확인할 수 있습니다.
- 예: (332, 500) -> 2D 데이터 (단일 채널)
- 예: (332, 500, 1) -> 단일 채널이지만 3D 배열로 저장됨
- 예: (332, 500, 3) -> 다중 채널 (RGB 데이터처럼 3개의 채널)
- Data Type: depth_map.dtype로 데이터가 float32, int16, uint8 등 어떤 형식으로 저장되었는지 확인합니다.
- 단일 채널 여부:
- len(depth_map.shape) == 2: 단일 채널(Grayscale)로 저장됨.
- len(depth_map.shape) == 3 and depth_map.shape[-1] == 1: 단일 채널이지만, 3D 배열로 표현됨.
- len(depth_map.shape) == 3 and depth_map.shape[-1] > 1: 다중 채널 데이터.
3. NPZ 데이터 구조
- Shape:
- Shape은 데이터의 차원(예: 2D 또는 3D)을 나타내므로, 모델에 입력하거나 시각화할 때 중요합니다.
- 채널 수:
- 단일 채널 데이터는 Grayscale로 처리하며, 다중 채널 데이터는 RGB처럼 다르게 처리해야 합니다.
- 데이터 타입:
- float32와 같은 형식은 깊이를 더 정밀하게 표현할 수 있고, uint8은 시각화에 적합합니다.
반응형