Datasets:
EntropyDrop commited on
Commit ·
84162cc
1
Parent(s): 7e93568
update
Browse files- DDJ_real2render/real2render.py +48 -47
- DDJ_real2render/test_batch.sh +6 -4
- DDJ_real2render/test_output/img10_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img10_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img11_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img11_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img12_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img12_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img13_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img14_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img14_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img15_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img15_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img16_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img16_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img17_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img17_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img18_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img18_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img19_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img19_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img1_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img1_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img20_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img20_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img21_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img21_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img22_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img22_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img23_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img23_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img24_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img2_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img2_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img3_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img3_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img4_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img4_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img5_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img5_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img6_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img6_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img7_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img7_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img8_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img8_template41_50_51_52.png +3 -0
- DDJ_real2render/test_output/img9_template41_50_50_50.png +3 -0
- DDJ_real2render/test_output/img9_template41_50_51_52.png +3 -0
DDJ_real2render/real2render.py
CHANGED
|
@@ -9,72 +9,67 @@ import banana_pro_image
|
|
| 9 |
# Default template image path located under inverse_uv/template.png
|
| 10 |
DEFAULT_TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template', 'template5.png')
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
DEFAULT_PROMPT = """生成[图1]中角色的Minecraft形象
|
| 14 |
|
| 15 |
-
- 人物模型必须与minecraft的玩家模型相同,且为包含内层/外层贴图的双图层模型,不能有额外元素。texture不能高于Minecraft所支持的分辨率,参考
|
| 16 |
|
| 17 |
-
- 生成的minecraft角色的尺寸、朝向、姿势必须与
|
| 18 |
|
| 19 |
- 使用容易区分前景的纯色背景。
|
| 20 |
|
| 21 |
- 在上述约束下,尽可能完美、准确的还原[图1]中的角色,包括外貌特征、全身所有服装、各种饰品等(不包括手持物品和披风)"""
|
| 22 |
|
|
|
|
| 23 |
def real2render(
|
| 24 |
image_path,
|
| 25 |
-
|
| 26 |
-
template2_path=None,
|
| 27 |
output_path=None,
|
| 28 |
prompt=None,
|
| 29 |
aspect_ratio="1:1",
|
| 30 |
image_size="1K",
|
| 31 |
-
template3_path=None,
|
| 32 |
):
|
| 33 |
"""
|
| 34 |
High-level API to generate a Minecraft 3D character render from a real character photo using Nano Banana Pro.
|
| 35 |
-
|
| 36 |
:param image_path: Path to the real character input image (Graph 1).
|
| 37 |
-
:param
|
| 38 |
-
|
| 39 |
-
:param template3_path: Path to the third template reference image (Graph 4, defaults to None).
|
| 40 |
:param output_path: Output PNG path.
|
| 41 |
-
:param prompt: Custom prompt text
|
|
|
|
| 42 |
:param aspect_ratio: Image aspect ratio (default: "1:1").
|
| 43 |
:param image_size: Image resolution (default: "1K").
|
| 44 |
:return: Path to generated image file.
|
| 45 |
"""
|
| 46 |
if not os.path.exists(image_path):
|
| 47 |
raise FileNotFoundError(f"Real character image '{image_path}' does not exist.")
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
raise FileNotFoundError(f"Template 3 image '{template3_file}' does not exist.")
|
| 60 |
-
|
| 61 |
-
prompt_text = prompt or DEFAULT_PROMPT
|
| 62 |
-
|
| 63 |
print(f"[*] Real Image (Graph 1): {image_path}")
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
print(f"[*] Template 2 Image (Graph 3): {template2_file}")
|
| 67 |
-
if template3_file:
|
| 68 |
-
print(f"[*] Template 3 Image (Graph 4): {template3_file}")
|
| 69 |
print(f"[*] Image Size: {image_size}, Aspect Ratio: {aspect_ratio}")
|
| 70 |
print(f"[*] Prompt:\n{prompt_text}\n")
|
| 71 |
-
|
| 72 |
-
local_image_paths = [image_path
|
| 73 |
-
|
| 74 |
-
local_image_paths.append(template2_file)
|
| 75 |
-
if template3_file:
|
| 76 |
-
local_image_paths.append(template3_file)
|
| 77 |
-
|
| 78 |
output_file = banana_pro_image.generate_img2img(
|
| 79 |
local_image_paths=local_image_paths,
|
| 80 |
prompt=prompt_text,
|
|
@@ -84,16 +79,23 @@ def real2render(
|
|
| 84 |
)
|
| 85 |
return output_file
|
| 86 |
|
|
|
|
| 87 |
def main():
|
| 88 |
parser = argparse.ArgumentParser(description="Convert real character photo to Minecraft render using Nano Banana Pro.")
|
| 89 |
parser.add_argument("image", help="Path to local real character photo (Graph 1).")
|
| 90 |
-
parser.add_argument(
|
| 91 |
-
|
| 92 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 93 |
parser.add_argument("-o", "--output", help="Output path for the generated image.")
|
| 94 |
-
parser.add_argument("-p", "--prompt", default=
|
| 95 |
-
|
| 96 |
-
|
|
|
|
| 97 |
help="Aspect ratio.")
|
| 98 |
parser.add_argument("-s", "--image-size", default="2K", choices=["1K", "2K", "4K"], help="Resolution size (default: 2K).")
|
| 99 |
args = parser.parse_args()
|
|
@@ -101,9 +103,7 @@ def main():
|
|
| 101 |
try:
|
| 102 |
output_file = real2render(
|
| 103 |
image_path=args.image,
|
| 104 |
-
|
| 105 |
-
template2_path=args.template2,
|
| 106 |
-
template3_path=args.template3,
|
| 107 |
output_path=args.output,
|
| 108 |
prompt=args.prompt,
|
| 109 |
aspect_ratio=args.aspect_ratio,
|
|
@@ -114,5 +114,6 @@ def main():
|
|
| 114 |
print(f"[!] Execution failed: {e}")
|
| 115 |
sys.exit(1)
|
| 116 |
|
|
|
|
| 117 |
if __name__ == '__main__':
|
| 118 |
main()
|
|
|
|
| 9 |
# Default template image path located under inverse_uv/template.png
|
| 10 |
DEFAULT_TEMPLATE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'template', 'template5.png')
|
| 11 |
|
| 12 |
+
|
| 13 |
+
def _build_template_refs(count):
|
| 14 |
+
"""Build the [图2][图3]...[图N+1] reference string for the prompt."""
|
| 15 |
+
return "".join(f"[图{i}]" for i in range(2, count + 2))
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
# Default prompt for real-to-render Minecraft character generation.
|
| 19 |
+
# {template_refs} is replaced at runtime based on the number of templates.
|
| 20 |
DEFAULT_PROMPT = """生成[图1]中角色的Minecraft形象
|
| 21 |
|
| 22 |
+
- 人物模型必须与minecraft的玩家模型相同,且为包含内层/外层贴图的双图层模型,不能有额外元素。texture不能高于Minecraft所支持的分辨率,参考{template_refs}。
|
| 23 |
|
| 24 |
+
- 生成的minecraft角色的尺寸、朝向、姿势必须与{template_refs}完全一致。
|
| 25 |
|
| 26 |
- 使用容易区分前景的纯色背景。
|
| 27 |
|
| 28 |
- 在上述约束下,尽可能完美、准确的还原[图1]中的角色,包括外貌特征、全身所有服装、各种饰品等(不包括手持物品和披风)"""
|
| 29 |
|
| 30 |
+
|
| 31 |
def real2render(
|
| 32 |
image_path,
|
| 33 |
+
template_paths=None,
|
|
|
|
| 34 |
output_path=None,
|
| 35 |
prompt=None,
|
| 36 |
aspect_ratio="1:1",
|
| 37 |
image_size="1K",
|
|
|
|
| 38 |
):
|
| 39 |
"""
|
| 40 |
High-level API to generate a Minecraft 3D character render from a real character photo using Nano Banana Pro.
|
| 41 |
+
|
| 42 |
:param image_path: Path to the real character input image (Graph 1).
|
| 43 |
+
:param template_paths: List of paths to template reference images (Graph 2, Graph 3, ...).
|
| 44 |
+
Defaults to [DEFAULT_TEMPLATE_PATH] if None or empty.
|
|
|
|
| 45 |
:param output_path: Output PNG path.
|
| 46 |
+
:param prompt: Custom prompt text. Use {template_refs} to insert the reference image tags.
|
| 47 |
+
Defaults to the standard Minecraft real-to-render prompt.
|
| 48 |
:param aspect_ratio: Image aspect ratio (default: "1:1").
|
| 49 |
:param image_size: Image resolution (default: "1K").
|
| 50 |
:return: Path to generated image file.
|
| 51 |
"""
|
| 52 |
if not os.path.exists(image_path):
|
| 53 |
raise FileNotFoundError(f"Real character image '{image_path}' does not exist.")
|
| 54 |
+
|
| 55 |
+
if not template_paths:
|
| 56 |
+
template_paths = [DEFAULT_TEMPLATE_PATH]
|
| 57 |
+
|
| 58 |
+
for i, tp in enumerate(template_paths):
|
| 59 |
+
if not os.path.exists(tp):
|
| 60 |
+
raise FileNotFoundError(f"Template image {i + 2} '{tp}' does not exist.")
|
| 61 |
+
|
| 62 |
+
template_refs = _build_template_refs(len(template_paths))
|
| 63 |
+
prompt_text = (prompt or DEFAULT_PROMPT).format(template_refs=template_refs)
|
| 64 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 65 |
print(f"[*] Real Image (Graph 1): {image_path}")
|
| 66 |
+
for i, tp in enumerate(template_paths):
|
| 67 |
+
print(f"[*] Template Image (Graph {i + 2}): {tp}")
|
|
|
|
|
|
|
|
|
|
| 68 |
print(f"[*] Image Size: {image_size}, Aspect Ratio: {aspect_ratio}")
|
| 69 |
print(f"[*] Prompt:\n{prompt_text}\n")
|
| 70 |
+
|
| 71 |
+
local_image_paths = [image_path] + list(template_paths)
|
| 72 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
| 73 |
output_file = banana_pro_image.generate_img2img(
|
| 74 |
local_image_paths=local_image_paths,
|
| 75 |
prompt=prompt_text,
|
|
|
|
| 79 |
)
|
| 80 |
return output_file
|
| 81 |
|
| 82 |
+
|
| 83 |
def main():
|
| 84 |
parser = argparse.ArgumentParser(description="Convert real character photo to Minecraft render using Nano Banana Pro.")
|
| 85 |
parser.add_argument("image", help="Path to local real character photo (Graph 1).")
|
| 86 |
+
parser.add_argument(
|
| 87 |
+
"-t", "--template",
|
| 88 |
+
action="append",
|
| 89 |
+
default=None,
|
| 90 |
+
help="Path to a reference template image. May be specified multiple times "
|
| 91 |
+
"(e.g. -t t1.png -t t2.png -t t3.png). "
|
| 92 |
+
"Defaults to the built-in template if omitted."
|
| 93 |
+
)
|
| 94 |
parser.add_argument("-o", "--output", help="Output path for the generated image.")
|
| 95 |
+
parser.add_argument("-p", "--prompt", default=None,
|
| 96 |
+
help="Prompt for image generation. Use {template_refs} as placeholder for reference image tags.")
|
| 97 |
+
parser.add_argument("-a", "--aspect-ratio", default="1:1",
|
| 98 |
+
choices=["1:1", "2:3", "3:2", "3:4", "4:3", "4:5", "5:4", "9:16", "16:9", "21:9"],
|
| 99 |
help="Aspect ratio.")
|
| 100 |
parser.add_argument("-s", "--image-size", default="2K", choices=["1K", "2K", "4K"], help="Resolution size (default: 2K).")
|
| 101 |
args = parser.parse_args()
|
|
|
|
| 103 |
try:
|
| 104 |
output_file = real2render(
|
| 105 |
image_path=args.image,
|
| 106 |
+
template_paths=args.template,
|
|
|
|
|
|
|
| 107 |
output_path=args.output,
|
| 108 |
prompt=args.prompt,
|
| 109 |
aspect_ratio=args.aspect_ratio,
|
|
|
|
| 114 |
print(f"[!] Execution failed: {e}")
|
| 115 |
sys.exit(1)
|
| 116 |
|
| 117 |
+
|
| 118 |
if __name__ == '__main__':
|
| 119 |
main()
|
DDJ_real2render/test_batch.sh
CHANGED
|
@@ -1,7 +1,9 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
for i in {
|
| 5 |
if [ -f "test_input/img${i}.png" ]; then
|
| 6 |
img_file="test_input/img${i}.png"
|
| 7 |
elif [ -f "test_input/img${i}.jpg" ]; then
|
|
@@ -11,5 +13,5 @@ for i in {15..17}; do
|
|
| 11 |
continue
|
| 12 |
fi
|
| 13 |
|
| 14 |
-
python real2render.py "$img_file" -t template/${
|
| 15 |
done
|
|
|
|
| 1 |
+
template_a=${template_a:-41}
|
| 2 |
+
template_b=${template_b:-50}
|
| 3 |
+
template_c=${template_c:-51}
|
| 4 |
+
template_d=${template_d:-52}
|
| 5 |
|
| 6 |
+
for i in {1..23}; do
|
| 7 |
if [ -f "test_input/img${i}.png" ]; then
|
| 8 |
img_file="test_input/img${i}.png"
|
| 9 |
elif [ -f "test_input/img${i}.jpg" ]; then
|
|
|
|
| 13 |
continue
|
| 14 |
fi
|
| 15 |
|
| 16 |
+
python real2render.py "$img_file" -t template/template${template_a}.png -t template/template${template_b}.png -t template/template${template_c}.png -t template/template${template_d}.png -o test_output/img${i}_template${template_a}_${template_b}_${template_c}_${template_d}.png
|
| 17 |
done
|
DDJ_real2render/test_output/img10_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img10_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img11_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img11_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img12_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img12_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img13_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img14_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img14_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img15_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img15_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img16_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img16_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img17_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img17_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img18_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img18_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img19_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img19_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img1_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img1_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img20_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img20_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img21_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img21_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img22_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img22_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img23_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img23_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img24_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img2_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img2_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img3_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img3_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img4_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img4_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img5_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img5_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img6_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img6_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img7_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img7_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img8_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img8_template41_50_51_52.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img9_template41_50_50_50.png
ADDED
|
Git LFS Details
|
DDJ_real2render/test_output/img9_template41_50_51_52.png
ADDED
|
Git LFS Details
|