Datasets:
EntropyDrop commited on
Commit ·
ba2ef65
1
Parent(s): b9af2c2
README
Browse files- README.md +43 -1
- ext_flip_img.py +149 -0
- make_half_dataset.py +91 -0
- merge_skins.py +72 -0
README.md
CHANGED
|
@@ -47,6 +47,18 @@ Along with the dataset assets, it contains the complete automated pipeline for d
|
|
| 47 |
* **📐 Conditioning Image Formatting (`force_resize_control_imgs.py`)**
|
| 48 |
- Automatically resamples and centers control images inside a standard `1024x1024` alpha-transparent canvas utilizing Lanczos interpolation, ensuring compatibility with advanced ControlNet training frameworks.
|
| 49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
---
|
| 51 |
|
| 52 |
## 📂 Project Structure
|
|
@@ -60,11 +72,15 @@ Sking/
|
|
| 60 |
├── build_target_imgs.py # Concurrent batch rendering pipeline
|
| 61 |
├── extract_skin.py # Skin UV map extraction CLI & FastAPI server
|
| 62 |
├── force_resize_control_imgs.py # Control map resampling & canvas standardization (1024x1024)
|
|
|
|
|
|
|
|
|
|
| 63 |
├── skin-mask.png # Pixel-level spatial mapping mask for Core layer
|
| 64 |
├── skin-decor-mask.png # Pixel-level spatial mapping mask for Decor layer
|
| 65 |
├── skins/ # Directory for raw input skins (.png)
|
| 66 |
├── target_imgs_v73/ # Output directory for baked multi-view layouts
|
| 67 |
-
|
|
|
|
| 68 |
```
|
| 69 |
|
| 70 |
---
|
|
@@ -144,6 +160,32 @@ The microservice launches locally on `http://0.0.0.0:10010`.
|
|
| 144 |
}
|
| 145 |
```
|
| 146 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 147 |
---
|
| 148 |
|
| 149 |
## 📄 License
|
|
|
|
| 47 |
* **📐 Conditioning Image Formatting (`force_resize_control_imgs.py`)**
|
| 48 |
- Automatically resamples and centers control images inside a standard `1024x1024` alpha-transparent canvas utilizing Lanczos interpolation, ensuring compatibility with advanced ControlNet training frameworks.
|
| 49 |
|
| 50 |
+
* **🔄 Skin UV & View Port Horizontal Flipping (`ext_flip_img.py`)**
|
| 51 |
+
- Performs horizontal flipping of character front/back views in control images and correctly flips the corresponding 64x64 skin UV map.
|
| 52 |
+
- Specifically handles 3D voxel box flipping (swapping left and right faces, horizontally flipping each face, and swapping left/right limbs/sleeves/pants/legs for Steve and Alex models).
|
| 53 |
+
|
| 54 |
+
* **✂️ Front-View Dataset Slicing (`make_half_dataset.py`)**
|
| 55 |
+
- Generates a front-view-only subset by horizontally splitting composite layout/control images in half, retaining only the left (front) side.
|
| 56 |
+
- Automatically copies and standardizes associated files (PNG images, txt descriptions, and control maps) prefixing them with `half_`.
|
| 57 |
+
|
| 58 |
+
* **🧬 Skin Merging Utility (`merge_skins.py`)**
|
| 59 |
+
- Combines two skins by extracting the head and head decoration (decor) layers from Skin A and copying them onto the body and limbs of Skin B.
|
| 60 |
+
- Utilizes head mapping coordinates matching standard UV layouts.
|
| 61 |
+
|
| 62 |
---
|
| 63 |
|
| 64 |
## 📂 Project Structure
|
|
|
|
| 72 |
├── build_target_imgs.py # Concurrent batch rendering pipeline
|
| 73 |
├── extract_skin.py # Skin UV map extraction CLI & FastAPI server
|
| 74 |
├── force_resize_control_imgs.py # Control map resampling & canvas standardization (1024x1024)
|
| 75 |
+
├── ext_flip_img.py # Flip front/back views and horizontally mirror skin UV layouts
|
| 76 |
+
├── make_half_dataset.py # Create front-view subset by slicing images in half horizontally
|
| 77 |
+
├── merge_skins.py # Combine head of skin A with body/limbs of skin B
|
| 78 |
├── skin-mask.png # Pixel-level spatial mapping mask for Core layer
|
| 79 |
├── skin-decor-mask.png # Pixel-level spatial mapping mask for Decor layer
|
| 80 |
├── skins/ # Directory for raw input skins (.png)
|
| 81 |
├── target_imgs_v73/ # Output directory for baked multi-view layouts
|
| 82 |
+
├── control_imgs/ # Processing directory for conditioning control maps
|
| 83 |
+
└── control_imgs_v2/ # Directory for multi-view layout control maps
|
| 84 |
```
|
| 85 |
|
| 86 |
---
|
|
|
|
| 160 |
}
|
| 161 |
```
|
| 162 |
|
| 163 |
+
### E. Horizontal Flipping of Views and UV Maps
|
| 164 |
+
This script horizontally flips character front and back views separately for a ControlNet image, and mirrors the 64x64 skin UV map by swapping and mirroring corresponding limbs and details.
|
| 165 |
+
```bash
|
| 166 |
+
python ext_flip_img.py <original_id> <new_id>
|
| 167 |
+
```
|
| 168 |
+
- Processes `control_imgs_v2/{original_id}.png` to generate flipped version at `control_imgs_v2/{new_id}.png`.
|
| 169 |
+
- Flips `img_label/{original_id}.png` (UV map) to generate `img_label/{new_id}.png`.
|
| 170 |
+
- Copies the corresponding text description from `img_label/{original_id}.txt` to `img_label/{new_id}.txt`.
|
| 171 |
+
|
| 172 |
+
### F. Front-View Dataset Slicing
|
| 173 |
+
This script processes the dataset by horizontally cutting all layout/control images in half (keeping only the left half, which corresponds to the character's front view) to create a front-view-only training subset.
|
| 174 |
+
```bash
|
| 175 |
+
python make_half_dataset.py
|
| 176 |
+
```
|
| 177 |
+
- Automatically processes files in `img_label/` and `control_imgs_v2/`.
|
| 178 |
+
- Saves sliced files with the prefix `half_` (e.g. `half_{original_name}.png`, `half_{original_name}.txt`).
|
| 179 |
+
- Proactively skips already processed files.
|
| 180 |
+
|
| 181 |
+
### G. Skin Merging Utility (Head of A + Body/Limbs of B)
|
| 182 |
+
This script merges two skins by taking the head and hat decoration layers from Skin A and the body and limbs from Skin B.
|
| 183 |
+
```bash
|
| 184 |
+
python merge_skins.py <path_to_skin_a> <path_to_skin_b> -o <output_path>
|
| 185 |
+
```
|
| 186 |
+
- Extracts head region UVs (including outer decors) from skin A.
|
| 187 |
+
- Pastes them over skin B's head region, outputting the newly combined skin.
|
| 188 |
+
|
| 189 |
---
|
| 190 |
|
| 191 |
## 📄 License
|
ext_flip_img.py
ADDED
|
@@ -0,0 +1,149 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import argparse
|
| 3 |
+
import shutil
|
| 4 |
+
from PIL import Image
|
| 5 |
+
|
| 6 |
+
def flip_box(img, x, y, w, h, d):
|
| 7 |
+
"""
|
| 8 |
+
Horizontally flips a 3D box in the Minecraft skin UV map.
|
| 9 |
+
This includes swapping the left and right faces, and horizontally flipping all faces.
|
| 10 |
+
"""
|
| 11 |
+
# Create a temporary image to store the box area (2w+2d, h+d)
|
| 12 |
+
res = Image.new("RGBA", (2*w + 2*d, h + d))
|
| 13 |
+
|
| 14 |
+
# Crop each face
|
| 15 |
+
# Layout: [Right] [Front] [Left] [Back]
|
| 16 |
+
top = img.crop((x + d, y, x + d + w, y + d)).transpose(Image.FLIP_LEFT_RIGHT)
|
| 17 |
+
bottom = img.crop((x + d + w, y, x + d + 2*w, y + d)).transpose(Image.FLIP_LEFT_RIGHT)
|
| 18 |
+
|
| 19 |
+
right = img.crop((x, y + d, x + d, y + d + h)).transpose(Image.FLIP_LEFT_RIGHT)
|
| 20 |
+
front = img.crop((x + d, y + d, x + d + w, y + d + h)).transpose(Image.FLIP_LEFT_RIGHT)
|
| 21 |
+
left = img.crop((x + d + w, y + d, x + 2*d + w, y + d + h)).transpose(Image.FLIP_LEFT_RIGHT)
|
| 22 |
+
back = img.crop((x + 2*d + w, y + d, x + 2*d + 2*w, y + d + h)).transpose(Image.FLIP_LEFT_RIGHT)
|
| 23 |
+
|
| 24 |
+
# Paste back to the flipped positions
|
| 25 |
+
# The new right face is the old left face, and the new left face is the old right face
|
| 26 |
+
res.paste(top, (d, 0))
|
| 27 |
+
res.paste(bottom, (d + w, 0))
|
| 28 |
+
res.paste(left, (0, d)) # New Right (0) <- Old Left
|
| 29 |
+
res.paste(front, (d, d)) # Front (d)
|
| 30 |
+
res.paste(right, (d + w, d)) # New Left (d+w) <- Old Right
|
| 31 |
+
res.paste(back, (2*d + w, d)) # Back (2d+w)
|
| 32 |
+
|
| 33 |
+
return res
|
| 34 |
+
|
| 35 |
+
def process_uvmap(img_id, new_id):
|
| 36 |
+
"""
|
| 37 |
+
Flips the UV Map of img_label/{id}.png.
|
| 38 |
+
Requires swapping left and right limbs, and flipping the textures of each component.
|
| 39 |
+
"""
|
| 40 |
+
dir_name = "img_label"
|
| 41 |
+
input_path = f"{dir_name}/{img_id}.png"
|
| 42 |
+
output_path = f"{dir_name}/{new_id}.png"
|
| 43 |
+
|
| 44 |
+
if not os.path.exists(input_path):
|
| 45 |
+
print(f"Warning: {input_path} does not exist, skipping UV Map flipping.")
|
| 46 |
+
return
|
| 47 |
+
|
| 48 |
+
img = Image.open(input_path).convert("RGBA")
|
| 49 |
+
# Unify to 64x64 format
|
| 50 |
+
if img.size == (64, 32):
|
| 51 |
+
new_img = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
| 52 |
+
new_img.paste(img, (0, 0))
|
| 53 |
+
img = new_img
|
| 54 |
+
elif img.size != (64, 64):
|
| 55 |
+
print(f"Error: Unsupported image size {img.size}")
|
| 56 |
+
return
|
| 57 |
+
|
| 58 |
+
# Determine if it is a slim (Alex) skin
|
| 59 |
+
is_slim = img.getpixel((47, 52))[3] == 0
|
| 60 |
+
w_arm = 3 if is_slim else 4
|
| 61 |
+
|
| 62 |
+
flipped_img = Image.new("RGBA", (64, 64), (0, 0, 0, 0))
|
| 63 |
+
|
| 64 |
+
# 1. Flip head and hat (symmetrical components)
|
| 65 |
+
flipped_img.paste(flip_box(img, 0, 0, 8, 8, 8), (0, 0)) # Head
|
| 66 |
+
flipped_img.paste(flip_box(img, 32, 0, 8, 8, 8), (32, 0)) # Hat
|
| 67 |
+
|
| 68 |
+
# 2. Flip torso and jacket (symmetrical components)
|
| 69 |
+
flipped_img.paste(flip_box(img, 16, 16, 8, 12, 4), (16, 16)) # Body
|
| 70 |
+
flipped_img.paste(flip_box(img, 16, 32, 8, 12, 4), (16, 32)) # Jacket
|
| 71 |
+
|
| 72 |
+
# 3. Swap and flip left and right limbs
|
| 73 |
+
# Right Arm (40, 16) <-> Left Arm (32, 48)
|
| 74 |
+
flipped_img.paste(flip_box(img, 40, 16, w_arm, 12, 4), (32, 48)) # Old Right -> New Left
|
| 75 |
+
flipped_img.paste(flip_box(img, 32, 48, w_arm, 12, 4), (40, 16)) # Old Left -> New Right
|
| 76 |
+
|
| 77 |
+
# Right Leg (0, 16) <-> Left Leg (16, 48)
|
| 78 |
+
flipped_img.paste(flip_box(img, 0, 16, 4, 12, 4), (16, 48)) # Old Right -> New Left
|
| 79 |
+
flipped_img.paste(flip_box(img, 16, 48, 4, 12, 4), (0, 16)) # Old Left -> New Right
|
| 80 |
+
|
| 81 |
+
# 4. Flip overlay layers (Sleeves & Pants)
|
| 82 |
+
# Right Sleeve (40, 32) <-> Left Sleeve (48, 48)
|
| 83 |
+
flipped_img.paste(flip_box(img, 40, 32, w_arm, 12, 4), (48, 48)) # Old Right -> New Left
|
| 84 |
+
flipped_img.paste(flip_box(img, 48, 48, w_arm, 12, 4), (40, 32)) # Old Left -> New Right
|
| 85 |
+
|
| 86 |
+
# Right Pants (0, 32) <-> Left Pants (0, 48)
|
| 87 |
+
flipped_img.paste(flip_box(img, 0, 32, 4, 12, 4), (0, 48)) # Old Right -> New Left
|
| 88 |
+
flipped_img.paste(flip_box(img, 0, 48, 4, 12, 4), (0, 32)) # Old Left -> New Right
|
| 89 |
+
|
| 90 |
+
flipped_img.save(output_path)
|
| 91 |
+
print(f"Successfully saved flipped UV Map to {output_path}")
|
| 92 |
+
|
| 93 |
+
# Process description files at the same time
|
| 94 |
+
txt_input = f"{dir_name}/{img_id}.txt"
|
| 95 |
+
txt_output = f"{dir_name}/{new_id}.txt"
|
| 96 |
+
if os.path.exists(txt_input):
|
| 97 |
+
shutil.copy(txt_input, txt_output)
|
| 98 |
+
print(f"Copied description file to {txt_output}")
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
# Input image id, new_id
|
| 102 |
+
# Read control_imgs_v2/{id}.png
|
| 103 |
+
|
| 104 |
+
# Copy control_imgs_v2/{id}.png to control_imgs_v2/{new_id}.png
|
| 105 |
+
# Each image consists of front and back photos of the character (split in the middle, left-right layout, left is front, right is back).
|
| 106 |
+
# Now we need to flip the left and right parts horizontally and splice them into a new image.
|
| 107 |
+
|
| 108 |
+
def process_image(img_id, new_id):
|
| 109 |
+
dir_name = "control_imgs_v2"
|
| 110 |
+
|
| 111 |
+
input_path = f"{dir_name}/{img_id}.png"
|
| 112 |
+
output_path = f"{dir_name}/{new_id}.png"
|
| 113 |
+
|
| 114 |
+
if not os.path.exists(input_path):
|
| 115 |
+
print(f"Error: {input_path} does not exist.")
|
| 116 |
+
return
|
| 117 |
+
|
| 118 |
+
# Read image
|
| 119 |
+
img = Image.open(input_path)
|
| 120 |
+
width, height = img.size
|
| 121 |
+
|
| 122 |
+
# Split into left and right parts (split in the middle)
|
| 123 |
+
# Left is front, right is back
|
| 124 |
+
left_part = img.crop((0, 0, width // 2, height))
|
| 125 |
+
right_part = img.crop((width // 2, 0, width, height))
|
| 126 |
+
|
| 127 |
+
# Horizontally flip the left and right parts respectively
|
| 128 |
+
left_flipped = left_part.transpose(Image.FLIP_LEFT_RIGHT)
|
| 129 |
+
right_flipped = right_part.transpose(Image.FLIP_LEFT_RIGHT)
|
| 130 |
+
|
| 131 |
+
# Splice into a new image
|
| 132 |
+
new_img = Image.new('RGBA', (width, height))
|
| 133 |
+
new_img.paste(left_flipped, (0, 0))
|
| 134 |
+
new_img.paste(right_flipped, (width // 2, 0))
|
| 135 |
+
|
| 136 |
+
# Save the new image
|
| 137 |
+
new_img.save(output_path)
|
| 138 |
+
print(f"Successfully saved flipped image to {output_path}")
|
| 139 |
+
|
| 140 |
+
# Process UV Map flipping
|
| 141 |
+
process_uvmap(img_id, new_id)
|
| 142 |
+
|
| 143 |
+
if __name__ == "__main__":
|
| 144 |
+
parser = argparse.ArgumentParser(description="Horizontally flip the front and back views of a character and splice them back together.")
|
| 145 |
+
parser.add_argument("id", type=str, help="Original image ID")
|
| 146 |
+
parser.add_argument("new_id", type=str, help="New image ID")
|
| 147 |
+
|
| 148 |
+
args = parser.parse_args()
|
| 149 |
+
process_image(args.id, args.new_id)
|
make_half_dataset.py
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import shutil
|
| 3 |
+
from PIL import Image
|
| 4 |
+
|
| 5 |
+
def process_and_crop(img_path, output_path):
|
| 6 |
+
"""
|
| 7 |
+
Read image, horizontally crop in half (left/right), keep only the left half, and save to output_path.
|
| 8 |
+
"""
|
| 9 |
+
if not os.path.exists(img_path):
|
| 10 |
+
print(f"File does not exist: {img_path}")
|
| 11 |
+
return False
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
with Image.open(img_path) as img:
|
| 15 |
+
width, height = img.size
|
| 16 |
+
# Crop in half horizontally, keep only the left half
|
| 17 |
+
left_half = img.crop((0, 0, width // 2, height))
|
| 18 |
+
left_half.save(output_path)
|
| 19 |
+
print(f"Successfully saved the cropped left-half image: {output_path}")
|
| 20 |
+
return True
|
| 21 |
+
except Exception as e:
|
| 22 |
+
print(f"Error processing image {img_path}: {e}")
|
| 23 |
+
return False
|
| 24 |
+
|
| 25 |
+
def main():
|
| 26 |
+
img_label_dir = "skins"
|
| 27 |
+
control_dir = "control_imgs"
|
| 28 |
+
|
| 29 |
+
if not os.path.exists(img_label_dir):
|
| 30 |
+
print(f"Error: Directory {img_label_dir} does not exist.")
|
| 31 |
+
return
|
| 32 |
+
|
| 33 |
+
# Get all png files in the img_label directory
|
| 34 |
+
png_files = sorted([f for f in os.listdir(img_label_dir) if f.lower().endswith(".png")])
|
| 35 |
+
|
| 36 |
+
processed_count = 0
|
| 37 |
+
skipped_count = 0
|
| 38 |
+
|
| 39 |
+
for filename in png_files:
|
| 40 |
+
if filename.startswith("half_"):
|
| 41 |
+
# Skip files that already start with half_
|
| 42 |
+
continue
|
| 43 |
+
|
| 44 |
+
# Target filename
|
| 45 |
+
half_filename = f"half_{filename}"
|
| 46 |
+
|
| 47 |
+
# Define source and destination paths
|
| 48 |
+
src_img_label = os.path.join(img_label_dir, filename)
|
| 49 |
+
dst_img_label = os.path.join(img_label_dir, half_filename)
|
| 50 |
+
|
| 51 |
+
base_name, _ = os.path.splitext(filename)
|
| 52 |
+
|
| 53 |
+
src_control = os.path.join(control_dir, filename)
|
| 54 |
+
dst_control = os.path.join(control_dir, half_filename)
|
| 55 |
+
|
| 56 |
+
# Check if all corresponding target files already exist
|
| 57 |
+
has_control = os.path.exists(src_control)
|
| 58 |
+
|
| 59 |
+
img_label_exists = os.path.exists(dst_img_label)
|
| 60 |
+
control_exists = not has_control or os.path.exists(dst_control)
|
| 61 |
+
|
| 62 |
+
if img_label_exists and control_exists:
|
| 63 |
+
skipped_count += 1
|
| 64 |
+
continue
|
| 65 |
+
|
| 66 |
+
print(f"\nProcessing {filename}...")
|
| 67 |
+
processed_count += 1
|
| 68 |
+
|
| 69 |
+
# 1. Process PNG image
|
| 70 |
+
if img_label_exists:
|
| 71 |
+
print(f" [Skip] Image {dst_img_label} already exists.")
|
| 72 |
+
else:
|
| 73 |
+
try:
|
| 74 |
+
shutil.copy(src_img_label, dst_img_label)
|
| 75 |
+
print(f" [Success] Copied image to {dst_img_label}")
|
| 76 |
+
except Exception as e:
|
| 77 |
+
print(f" [Error] Failed to copy image to {dst_img_label}: {e}")
|
| 78 |
+
|
| 79 |
+
# 2. Process corresponding image
|
| 80 |
+
if has_control:
|
| 81 |
+
if control_exists:
|
| 82 |
+
print(f" [Skip] Cropped image {dst_control} already exists.")
|
| 83 |
+
else:
|
| 84 |
+
process_and_crop(src_control, dst_control)
|
| 85 |
+
else:
|
| 86 |
+
print(f" [Note] No corresponding image {src_control} in control_imgs directory")
|
| 87 |
+
|
| 88 |
+
print(f"\nProcessing complete! Newly processed {processed_count} pairs, skipped {skipped_count} existing pairs.")
|
| 89 |
+
|
| 90 |
+
if __name__ == "__main__":
|
| 91 |
+
main()
|
merge_skins.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import argparse
|
| 2 |
+
from PIL import Image
|
| 3 |
+
|
| 4 |
+
def get_head_uvs():
|
| 5 |
+
"""
|
| 6 |
+
Returns the (x, y, w, h) of each 2D texture block of the head.
|
| 7 |
+
"""
|
| 8 |
+
head_uvs = []
|
| 9 |
+
|
| 10 |
+
# [ [ [size, offset], ... ], decor_offset ]
|
| 11 |
+
part = [
|
| 12 |
+
[
|
| 13 |
+
[(8,8,8),(8,8)], # front
|
| 14 |
+
[(8,8,8),(24,8)], # back
|
| 15 |
+
[(8,8,8),(16,8)], # left
|
| 16 |
+
[(8,8,8),(0,8)], # right
|
| 17 |
+
[(8,8,8),(8,0)], # top
|
| 18 |
+
[(8,8,8),(16,0)], # bottom
|
| 19 |
+
], (32,0)
|
| 20 |
+
]
|
| 21 |
+
|
| 22 |
+
decor_offset = part[1]
|
| 23 |
+
|
| 24 |
+
for size_info, offset in part[0]:
|
| 25 |
+
# Take the first two values from the 3D size (dx, dy, dz) as the width and height of the 2D texture map
|
| 26 |
+
w, h = size_info[0], size_info[1]
|
| 27 |
+
|
| 28 |
+
# Base head area
|
| 29 |
+
head_uvs.append((offset[0], offset[1], w, h))
|
| 30 |
+
|
| 31 |
+
# Head decoration (decor) area
|
| 32 |
+
decor_x = offset[0] + decor_offset[0]
|
| 33 |
+
decor_y = offset[1] + decor_offset[1]
|
| 34 |
+
head_uvs.append((decor_x, decor_y, w, h))
|
| 35 |
+
|
| 36 |
+
return head_uvs
|
| 37 |
+
|
| 38 |
+
def merge_skins(skin_a_path, skin_b_path, output_path):
|
| 39 |
+
# Open images and ensure they have an alpha channel
|
| 40 |
+
img_a = Image.open(skin_a_path).convert("RGBA")
|
| 41 |
+
img_b = Image.open(skin_b_path).convert("RGBA")
|
| 42 |
+
|
| 43 |
+
# Check if dimensions are compatible
|
| 44 |
+
if img_a.size != img_b.size:
|
| 45 |
+
print(f"Warning: Skin A ({img_a.size}) and Skin B ({img_b.size}) sizes do not match.")
|
| 46 |
+
|
| 47 |
+
# Use B (provides body and limbs) as the base background
|
| 48 |
+
img_c = img_b.copy()
|
| 49 |
+
|
| 50 |
+
# Get head regions that need to be copied from A
|
| 51 |
+
head_uvs = get_head_uvs()
|
| 52 |
+
|
| 53 |
+
for x, y, w, h in head_uvs:
|
| 54 |
+
box = (x, y, x + w, y + h)
|
| 55 |
+
|
| 56 |
+
# Crop the corresponding head block from A
|
| 57 |
+
region_a = img_a.crop(box)
|
| 58 |
+
|
| 59 |
+
# Paste onto C. Do not use mask to ensure complete coverage (including transparent pixels covering B's original pixels)
|
| 60 |
+
img_c.paste(region_a, box)
|
| 61 |
+
|
| 62 |
+
img_c.save(output_path)
|
| 63 |
+
print(f"Successfully merged: A's head ({skin_a_path}) + B's body/limbs ({skin_b_path}) -> {output_path}")
|
| 64 |
+
|
| 65 |
+
if __name__ == "__main__":
|
| 66 |
+
parser = argparse.ArgumentParser(description="Combine skins: Take the head of Skin A and the body and limbs of Skin B.")
|
| 67 |
+
parser.add_argument("skin_a", help="Path to Skin A (provides the head)")
|
| 68 |
+
parser.add_argument("skin_b", help="Path to Skin B (provides the body and limbs)")
|
| 69 |
+
parser.add_argument("-o", "--output", default="skin_c.png", help="Output path for Skin C")
|
| 70 |
+
args = parser.parse_args()
|
| 71 |
+
|
| 72 |
+
merge_skins(args.skin_a, args.skin_b, args.output)
|