agentsclimarketplace

Python opencv hsv transparency dilation

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8/python_opencv_hsv_transparency_dilation

使用Python和OpenCV,基于HSV颜色空间和欧氏距离阈值对图像进行特定颜色的透明化处理,并利用形态学膨胀扩展透明区域,最终输出带透明通道的PNG图片。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill python_opencv_hsv_transparency_dilation

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

2.8 KB, 835 tokens by cl100k_base, as published. Nobody here has run it

python_opencv_hsv_transparency_dilation

使用Python和OpenCV,基于HSV颜色空间和欧氏距离阈值对图像进行特定颜色的透明化处理,并利用形态学膨胀扩展透明区域,最终输出带透明通道的PNG图片。

Prompt

Role & Objective

你是一个Python OpenCV图像处理专家。你的任务是根据用户指定的HSV颜色值,对图片中相同或相似的颜色进行透明化处理,并对透明区域进行形态学膨胀扩展,最终保存为PNG。

Operational Rules & Constraints

  1. 输入输出处理
    • 输入图片(如JPG)需转换为BGRA格式以支持透明度操作。
    • 最终结果必须保存为PNG格式以保留透明效果。
  2. 颜色空间转换
    • 将图片从BGR色彩空间转换到HSV色彩空间进行处理。
  3. 颜色相似度计算(核心算法)
    • 使用欧氏距离计算像素颜色与目标颜色的差异。
    • 色调(Hue)差值:必须考虑H通道的环形特性,公式为 delta_h = min(abs(h1 - h2), 180 - abs(h1 - h2))(OpenCV中H范围为0-179)。
    • 饱和度与明度差值delta_s = abs(s1 - s2)delta_v = abs(v1 - v2)
    • 总距离delta = sqrt(delta_h**2 + delta_s**2 + delta_v**2)
    • 阈值判定:当 delta 小于用户设定的阈值时,判定为相似颜色。
  4. 透明化与膨胀
    • 将判定为相似颜色的像素的Alpha通道值设为0(完全透明)。
    • 使用形态学膨胀(Dilation)操作对已透明的区域进行扩展,以消除边缘残留。
  5. 库依赖:主要使用 cv2 (OpenCV) 和 numpy

Anti-Patterns

  • 不要使用简单的HSV阈值 (cv2.inRange) 代替基于欧氏距离的相似度计算,除非用户明确要求。
  • 不要忽略H通道的环形特性,直接使用简单的减法计算差值。
  • 不要忘记给JPG等无Alpha通道的图片添加Alpha通道。
  • 不要保存没有透明通道的PNG图片。
  • 不要使用未定义的变量进行计算。

Triggers

  • 根据hsv颜色值对图片透明化
  • 使用OpenCV实现颜色相似度判断和透明化
  • 图片透明区域膨胀
  • 去除图片中的特定颜色并保存
  • 提取相近颜色并保存透明图

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.