1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
| import cv2 import numpy as np import glob import sys def pre_process(img): img = cv2.fastNlMeansDenoisingColored(img, None, 10, 10, 7, 21) lab = cv2.cvtColor(img, cv2.COLOR_BGR2LAB) l, a, b = cv2.split(lab) clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(8,8)) l = clahe.apply(l) img = cv2.cvtColor(cv2.merge((l,a,b)), cv2.COLOR_LAB2BGR) return img
def create_star_trail(input_path, output_file): """ 合成星轨图像 :param input_path: 输入图像路径(支持通配符,如 'input/*.jpg') :param output_file: 输出文件名 """ img_files = sorted(glob.glob(input_path)) if not img_files: print("未找到输入图像,请检查路径是否正确") return star_trail = None for idx, file in enumerate(img_files): img = cv2.imread(file) if img is None: print(f"警告:无法读取图像 {file},已跳过") continue if star_trail is None: star_trail = img.copy().astype(np.float32) else: star_trail = np.maximum(star_trail, img.astype(np.float32)) print(f"已处理 {idx+1}/{len(img_files)} 张图像", end='\r')
temp = np.clip(star_trail, 0, 255).astype(np.uint8) cv2.imwrite(sys.path[0] + f'/temp/{idx}.jpg', temp) if star_trail is None: print("错误:未找到有效输入图像") return star_trail = np.clip(star_trail, 0, 255).astype(np.uint8) cv2.imwrite(output_file, star_trail) print(f"\n星轨合成完成!结果已保存至 {output_file}")
if __name__ == "__main__": create_star_trail( input_path='/Volumes/backup/星空2/修改/*.jpg', output_file='star_trail1.jpg' )
|