Menu



Manage

Cord > Project_AI이미지 처리 전체 다운로드
Project_AI이미지 처리 > makenpz/sizedown.py Lines 45 | 1.5 KB
다운로드

                        import numpy as np
import cv2
import os

# .npz 파일 경로
file_path = r"C:\Users\remil\바탕 화면\productive\last.npz"
output_file_path = r"C:\Users\remil\바탕 화면\productive\final.npz"

# 청크 사이즈 설정
chunk_size = 200

# 결과 저장 공간
resized_data = {}

# .npz 파일 로드
with np.load(file_path) as data:
    for key in ['train_images', 'train_masks', 'test_images', 'test_masks']:
        if key in data:
            image_data = data[key]
            total_images = len(image_data)
            num_chunks = (total_images + chunk_size - 1) // chunk_size
            resized_images = []

            for i in range(num_chunks):
                start_idx = i * chunk_size
                end_idx = min((i + 1) * chunk_size, total_images)
                chunk = image_data[start_idx:end_idx]

                print(f"{key} 청크 {i+1}/{num_chunks} 처리 시작 ({start_idx}-{end_idx-1})")

                for img in chunk:
                    if img.ndim == 3:
                        resized_img = cv2.resize(img, (256, 256), interpolation=cv2.INTER_AREA)
                        resized_images.append(resized_img)
                    else:
                        print(f"{key}의 3차원 이미지가 아닙니다.")

            resized_data[key] = np.array(resized_images)
        else:
            print(f"{key} 키가 파일에 없습니다.")

# 결과 파일 저장
np.savez_compressed(output_file_path, **resized_data)

print("이미지 축소 및 저장 완료")