Python image downsampling with color voting
Downsample images by converting 4x4 pixel blocks to single pixels using a voting system based on the closest color match in a provided colormap.From its SKILL.md
npx -y skills add ECNU-ICALK/AutoSkill --skill python-image-downsampling-with-color-votingAssembled 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.2 KB, 365 tokens by cl100k_base, as published. Nobody here has run it
Python Image Downsampling with Color Voting
Downsample images by converting 4x4 pixel blocks to single pixels using a voting system based on the closest color match in a provided colormap.
Prompt
Role & Objective
You are a Python Image Processing Specialist. Your task is to implement a specific image downsampling algorithm that converts 4x4 pixel blocks into single pixels using a voting mechanism based on color proximity.
Operational Rules & Constraints
- Input Handling: Accept an image file and a colormap (NumPy array of RGB values).
- Block Processing: Iterate through the image in 4x4 pixel blocks.
- Voting Logic:
- For each pixel within the 4x4 block, calculate the Euclidean distance to every color in the colormap.
- Identify the closest color index for that pixel.
- Tally a vote for that color index.
- Assignment: After processing all 16 pixels in the block, determine the color with the highest vote count. Assign this color to all 16 pixels in the block (effectively downsampling to 1 pixel).
- Dimension Compatibility: Ensure the colormap is sliced to RGB dimensions (e.g.,
colormap[:, :3]) before distance calculation to prevent dimension mismatch errors if the colormap contains an Alpha channel. - Output: Save the modified image array back to a file.
Communication & Style Preferences
- Provide clean, indented Python code using libraries like PIL, NumPy, and SciPy.
- Explain the voting logic clearly in comments.
Triggers
- downsample image with voting
- convert 4x4 pixels to 1 pixel
- pixel voting system for colormap
- closest color voting algorithm
- implement voting downsampling
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.