图片批量颜色查找工具滤镜效果

联启 电脑工具 18

本文目录导读:

图片批量颜色查找工具滤镜效果-第1张图片-电脑手机工具软件下载 - 免费实用工具合集 | 联启科技

  1. 🎯 核心需求理解
  2. 🛠 方案详解
  3. 📌 快速选择指南
  4. 🚀 扩展建议

这是一个很具体的需求,我来为你整理几种实现“图片批量颜色查找 + 滤镜效果”的方案,从在线工具到专业软件再到代码实现,覆盖不同使用场景。

🎯 核心需求理解

“颜色查找”通常指将图片中的颜色替换/映射为预设色板中的颜色,类似于PS的“颜色查找”功能。“滤镜效果”则是指批量应用统一的视觉风格。

🛠 方案详解

专业软件(推荐)

Adobe Photoshop / Lightroom

  • 颜色查找功能:通过 图层 > 新建调整图层 > 颜色查找 加载 .cube 文件
  • 批量处理:使用“动作”录制 + “批处理”功能
  • 优势:效果专业、支持3D LUT
  • 适用:需要高质量输出的用户

Affinity Photo

  • 支持批量处理 + LUT加载
  • 性价比高,一次性购买

在线批量工具

Pixelied

  • 批量上传图片
  • 内置多种滤镜效果
  • 支持颜色替换/查找
  • 适合不需要安装软件的场景

Canva / Fotor

  • 批量编辑功能
  • 内置颜色查找预设
  • 适合社交媒体快速处理

开源代码方案(最灵活)

Python + OpenCV + numpy

import cv2
import numpy as np
import os
from glob import glob
class ColorLookupFilter:
    def __init__(self, palette):
        """
        初始化颜色查找表
        palette: [(R1,G1,B1), (R2,G2,B2), ...] 目标色板
        """
        self.palette = np.array(palette, dtype=np.float32)
    def nearest_color(self, pixel):
        """查找最近的颜色"""
        distances = np.sqrt(np.sum((self.palette - pixel) ** 2, axis=1))
        return self.palette[np.argmin(distances)]
    def apply_lut_style(self, img):
        """应用颜色查找滤镜"""
        # 转换为float
        img_float = img.astype(np.float32)
        # 对每个像素进行颜色查找
        result = np.zeros_like(img_float)
        for i in range(img.shape[0]):
            for j in range(img.shape[1]):
                result[i][j] = self.nearest_color(img_float[i][j])
        return result.astype(np.uint8)
    def apply_art_filter(self, img, style='posterize'):
        """应用艺术滤镜效果"""
        if style == 'posterize':
            # 色调分离
            levels = 4
            return (img // (256//levels)) * (256//levels)
        elif style == 'oil_paint':
            # 油画效果
            return cv2.medianBlur(img, 5)
        elif style == 'watercolor':
            # 水彩效果
            kernel = np.ones((3,3), np.float32)/9
            return cv2.filter2D(img, -1, kernel)
        return img
def batch_process(input_dir, output_dir, palette, filter_style='posterize'):
    """批量处理图片"""
    os.makedirs(output_dir, exist_ok=True)
    filter_obj = ColorLookupFilter(palette)
    # 支持的图片格式
    extensions = ['*.jpg', '*.jpeg', '*.png', '*.bmp']
    files = []
    for ext in extensions:
        files.extend(glob(os.path.join(input_dir, ext)))
    for file_path in files:
        print(f"处理: {os.path.basename(file_path)}")
        # 读取图片
        img = cv2.imread(file_path)
        if img is None:
            continue
        # 转换BGR到RGB
        img_rgb = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
        # 应用颜色查找
        img_lookup = filter_obj.apply_lut_style(img_rgb)
        # 应用滤镜
        img_filtered = filter_obj.apply_art_filter(img_lookup, filter_style)
        # 保存结果
        output_path = os.path.join(output_dir, f"filtered_{os.path.basename(file_path)}")
        cv2.imwrite(output_path, cv2.cvtColor(img_filtered, cv2.COLOR_RGB2BGR))
    print("批量处理完成!")
# 使用示例
if __name__ == "__main__":
    # 定义你的色板(颜色查找表)
    my_palette = [
        (255, 0, 0),    # 红色
        (0, 255, 0),    # 绿色
        (0, 0, 255),    # 蓝色
        (255, 255, 0),  # 黄色
        (255, 0, 255),  # 品红
        (0, 255, 255),  # 青色
        (128, 128, 128) # 灰色
    ]
    # 批量处理
    batch_process(
        input_dir='./input_images',
        output_dir='./output_images',
        palette=my_palette,
        filter_style='posterize'  # 或 'oil_paint', 'watercolor'
    )

高级颜色查找(使用3D LUT)

import numpy as np
from PIL import Image
import os
def create_lookup_table(lut_path='default.cube'):
    """创建或加载3D LUT"""
    lut_size = 32  # 标准LUT大小
    # 创建一个默认的色调映射LUT
    lut = np.zeros((lut_size, lut_size, lut_size, 3), dtype=np.uint8)
    for r in range(lut_size):
        for g in range(lut_size):
            for b in range(lut_size):
                # 这里实现你的颜色映射逻辑
                # 示例:增加对比度
                lut[r, g, b] = [
                    np.clip(r * 1.5, 0, lut_size-1),
                    np.clip(g * 1.2, 0, lut_size-1),
                    np.clip(b * 0.8, 0, lut_size-1)
                ]
    return lut
def apply_3d_lut(image, lut):
    """应用3D LUT到图片"""
    img_array = np.array(image)
    lut_size = lut.shape[0]
    # 归一化到LUT空间
    factor = lut_size / 256
    indices = (img_array * factor).astype(np.int32)
    # 应用LUT
    result = lut[indices[:,:,0], indices[:,:,1], indices[:,:,2]]
    return Image.fromarray(result)
def batch_with_lut(input_dir, output_dir, lut_path='default.cube'):
    """使用LUT批量处理"""
    lut = create_lookup_table(lut_path)
    for filename in os.listdir(input_dir):
        if filename.lower().endswith(('.png', '.jpg', '.jpeg')):
            img = Image.open(os.path.join(input_dir, filename))
            img_lut = apply_3d_lut(img, lut)
            img_lut.save(os.path.join(output_dir, f"lut_{filename}"))
# 使用
batch_with_lut('./input', './output')

成品软件推荐(Windows/Mac)

软件名称 颜色查找 批量处理 滤镜效果 价格
XnConvert 免费
FastStone Image Viewer 免费
IrfanView 免费
Photoscape X 免费

📌 快速选择指南

  • 零门槛、快速:XnConvert(免费、绿色版)
  • 专业效果:Photoshop + 动作批处理
  • 可定制、自动化:Python代码方案
  • 无需安装、在线:Pixelied.com

🚀 扩展建议

如果你需要更复杂的效果(如霓虹、赛博朋克等),可以在颜色查找逻辑中加入:

  1. 色调偏移:整体色调偏移
  2. 饱和度调整:增强/减弱饱和度
  3. 色调分离:限制颜色数量
  4. 渐变映射:使用两个颜色的渐变替换

需要哪种具体的滤镜效果或颜色风格?我可以给你更针对性的代码或参数调优。

标签: 图片批量处理 颜色查找

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