脚本如何批量调整图片色调曲线

wen 实用脚本 13

本文目录导读:

脚本如何批量调整图片色调曲线

  1. 方法一:使用 Photoshop 动作(最常用)
  2. 方法二:Python + Pillow 脚本
  3. 方法三:Python + OpenCV(更专业)
  4. 方法四:使用 ImageMagick(命令行工具)
  5. 方法五:专业的批量处理软件
  6. 实用技巧
  7. 推荐方案

使用 Photoshop 动作(最常用)

步骤:

  1. 准备动作

    • 打开一张示例图片
    • 窗口 → 动作 (Alt+F9)
    • 新建动作组和动作
    • 开始录制
  2. 调整曲线

    • 图像 → 调整 → 曲线 (Ctrl+M)
    • 调整曲线参数
    • 保存图片(可选)
    • 停止录制
  3. 批量处理

    • 文件 → 自动 → 批处理
    • 选择源文件夹和目标文件夹
    • 选择刚才录制的动作
    • 执行

Python + Pillow 脚本

from PIL import Image, ImageOps
import os
def apply_curve_adjustment(image, points):
    """
    调整色调曲线
    points: 控制点列表 [(x1,y1), (x2,y2), ...]
    """
    # 创建曲线映射
    curve = []
    for i in range(256):
        curve.append(i)
    # 应用控制点插值
    for i, (x, y) in enumerate(points):
        if i < len(points) - 1:
            x1, y1 = x, y
            x2, y2 = points[i + 1]
            # 线性插值
            for j in range(x1, x2):
                ratio = (j - x1) / (x2 - x1)
                curve[j] = int(y1 + ratio * (y2 - y1))
    # 应用曲线
    return image.point(curve)
def batch_adjust_curves(input_folder, output_folder, curve_points):
    """批量调整图片色调曲线"""
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    for filename in os.listdir(input_folder):
        if filename.lower().endswith(('.png', '.jpg', '.jpeg', '.tiff')):
            # 读取图片
            img_path = os.path.join(input_folder, filename)
            img = Image.open(img_path)
            # 应用曲线调整
            adjusted_img = apply_curve_adjustment(img, curve_points)
            # 保存结果
            output_path = os.path.join(output_folder, filename)
            adjusted_img.save(output_path)
            print(f"处理完成: {filename}")
# 使用示例 - S曲线增加对比度
curve_points = [
    (0, 0),      # 起点
    (64, 32),    # 暗部压低
    (128, 128),  # 中间调不变
    (192, 224),  # 亮部提亮
    (255, 255)   # 终点
]
# 执行批量处理
batch_adjust_curves("输入文件夹", "输出文件夹", curve_points)

Python + OpenCV(更专业)

import cv2
import numpy as np
import os
from glob import glob
def create_curve_lut(points):
    """创建曲线查找表"""
    lut = np.zeros((256, 1), dtype=np.uint8)
    for i in range(256):
        for j in range(len(points) - 1):
            if points[j][0] <= i <= points[j+1][0]:
                x1, y1 = points[j]
                x2, y2 = points[j+1]
                # 线性插值
                ratio = (i - x1) / (x2 - x1)
                lut[i] = int(y1 + ratio * (y2 - y1))
    return lut
def apply_curves(image_path, curve_points, output_path):
    """应用色调曲线调整"""
    # 读取图片
    img = cv2.imread(image_path)
    if img is None:
        print(f"无法读取: {image_path}")
        return
    # 转换到 HSV 色彩空间(可以分别调整色相、饱和度、明度)
    hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
    # 创建曲线 LUT
    curve_lut = create_curve_lut(curve_points)
    # 应用曲线到明度通道
    hsv[:,:,2] = cv2.LUT(hsv[:,:,2], curve_lut)
    # 转换回 BGR
    result = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
    # 保存结果
    cv2.imwrite(output_path, result)
def batch_process(input_folder, output_folder, curve_points):
    """批量处理文件夹中的图片"""
    # 创建输出文件夹
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)
    # 支持的文件格式
    formats = ['*.jpg', '*.jpeg', '*.png', '*.tiff', '*.bmp']
    for fmt in formats:
        for file_path in glob(os.path.join(input_folder, fmt)):
            filename = os.path.basename(file_path)
            output_path = os.path.join(output_folder, filename)
            print(f"处理中: {filename}")
            apply_curves(file_path, curve_points, output_path)
# 使用示例 - 复古胶片风格曲线
vintage_curve = [
    (0, 10),      # 增加暗部灰雾
    (50, 40),     # 压缩暗部
    (128, 128),   # 中间调不变
    (200, 215),   # 微调亮部
    (255, 245)    # 降低高光
]
# 执行批量处理
batch_process("输入文件夹", "输出文件夹", vintage_curve)

使用 ImageMagick(命令行工具)

# 安装 ImageMagick
# macOS: brew install imagemagick
# Ubuntu: sudo apt-get install imagemagick
# Windows: 官网下载安装
# 单个文件调整曲线
convert input.jpg -channel RGB -curve "0,0 64,32 128,128 192,224 255,255" output.jpg
# 批量处理所有jpg文件
for file in *.jpg; do
    convert "$file" -channel RGB -curve "0,0 64,32 128,128 192,224 255,255" "processed_$file"
done
# 另一种方法:使用-level(快速调整对比度)
mogrify -path output_folder -level 10%,90%,1.0 *.jpg
# 使用-sigmoidal-contrast(S曲线对比度)
mogrify -path output_folder -sigmoidal-contrast 10,50% *.jpg

专业的批量处理软件

Adobe Lightroom

- 编辑一张图片的曲线
- 保存为预设
- 批量应用预设到其他图片

Capture One

- 创建样式(Style)
- 批量应用到整个会话

DxO PhotoLab

- 保存为预设
- 批量应用

实用技巧

常见的色调曲线预设模板:

# 1. 增加对比度(S曲线)
contrast_curve = [
    (0, 0),
    (64, 48),    # 暗部压低
    (128, 128),
    (192, 208),  # 亮部提亮
    (255, 255)
]
# 2. 日系清新风格
japan_style = [
    (0, 20),     # 提升暗部
    (64, 80),    # 提高阴影
    (128, 136),  # 微调中间调
    (192, 200),
    (255, 240)   # 降低高光
]
# 3. 胶片质感
film_look = [
    (0, 8),
    (32, 40),
    (128, 120),
    (224, 220),
    (255, 248)
]
# 4. 高对比黑白效果
high_contrast_bw = [
    (0, 0),
    (48, 32),
    (128, 128),
    (208, 224),
    (255, 255)
]

推荐方案

  1. 简单需求:使用 Photoshop 动作批量处理
  2. 编程能力:Python + Pillow 或 OpenCV 脚本
  3. 命令行:ImageMagick(适合Linux服务器)
  4. 专业摄影师:Lightroom 预设批量处理

选择最适合你技术背景和需求的方法即可,如果需要更复杂的色调调整,建议使用 Python + OpenCV,灵活性最高。

抱歉,评论功能暂时关闭!