Inpainting คืออะไร

การทำ Image Inpainting คือการแทนที่วัตถุหรือองค์ประกอบบนรูปภาพที่มีอยู่เดิมอย่างเช่น รูปตัวอย่างเราเปลี่ยนจากน้องหมาที่นั่งบนม้านั่งเป็นหุ่นยนต์ เป็นต้น ซึ่งวิธีการทำสามารถทำได้ง่ายขึ้นมากด้วยการใช้ AI และบอก Prompt ที่ต้องการให้กับโมเดล (จากเดิมอาจจะต้องใช้ Photoshop หรือโปรแกรมจัดการรูปภาพอื่น ๆ ในการทำ และต้องอาศัยความชำนาญในระดับนึง)
ในทางเทคนิค Inpainting จัดเป็น Multimodal Model สำหรับทำงาน Image to Image
หมายเหตุ: ในตัวอย่างนี้ใช้โมเดล Stable Diffusion 2
วิธีการทำ Inpainting
หลัก ๆ แล้วสิ่งที่จำเป็นต้องเตรียมคือ
- รูปภาพต้นฉบับ
- Mask ของรูปต้นฉบับ
- Prompt สำหรับรูปที่จะสร้างลงไปแทนของเดิม

ภาพต้นฉบับของเราคือ Erling Haaland นักฟุตบอลกองหน้าสัญชาตินอร์เวย์

Mask Image แบบที่ 1 บริเวณมือ

ผลลัพธ์ที่ได้
จาก Prompt: a yellow card, in the hand, high resolution
- prompts = [“a yellow card, in the hand, high resolution”]
- negative_prompts = [“ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, blurred, text, watermark, grainy”]
- image= Original Image
- mask_image= Mask Image 1
- num_inference_steps=50
- seed=123
- guidance_scale=9

Mask Image แบบที่ 2 บริเวณผม

ผลลัพธ์ที่ได้
จาก Prompt: a black short hairstyles
- prompts = [“a black short hairstyles”]
- negative_prompts = [“ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, blurred, text, watermark, grainy”]
- image= Original Image
- mask_image= Mask Image 2
- num_inference_steps=50
- seed=78154
- guidance_scale=9

Mask Image แบบที่ 3 บริเวณตา

ผลลัพธ์ที่ได้
จาก Prompt: a black sunglasses, high resolution, on the head
- prompts = [“a black sunglasses, high resolution, on the head“]
- negative_prompts = [“ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, blurred, text, watermark, grainy”]
- image= Original Image
- mask_image= Mask Image 3
- num_inference_steps=50
- seed=9962
- guidance_scale=9

Mask Image แบบที่ 4 บริเวณปาก

ผลลัพธ์ที่ได้
จาก Prompt: a mouth with black and long beard, high resolution, on the face
- prompts = [“a mouth with black and long beard, high resolution, on the face”]
- negative_prompts = [“ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy, blurred, text, watermark, grainy”]
- image= Original Image
- mask_image= Mask Image 4
- num_inference_steps= 50
- seed= 6565
- guidance_scale= 9
Conclusion
การทำ Inpainting คุณภาพในการสร้างรูปภาพของโมเดลค่อนข้างสำคัญมากว่าจะสร้างได้ตรงกับ Prompt ที่เราระบุได้มากแค่ไหน นอกจากนี้การทำ Mask เองก็มีความสำคัญมาก โดยตัว Mask จำเป็นจะต้องมีขนาดสอดคล้องกับวัตถุที่เราบอกใน Prompt ด้วยเช่น ถ้าทำ Mask ขนาดเล็กมากแต่สั่งให้วาดของที่เป็นชิ้นใหญ่ ๆ ลงไปนั้นส่วนใหญ่แล้วจะทำไม่ได้
นอกจากนี้การใช้ Mask ยังสามารถมีวิธีที่ใช้แล้วลบวัตถุหรือคนออกจากฉากได้ด้วย
หากต้องการทดลองเล่นสามารถไปใช้ได้ที่นี่
- อัปโหลดรูปภาพที่ต้องการ
- ระบายสีดำลงบนรูป ตามบริเวณที่เราอยากแก้ไข (คือการทำ Mask)
- ใส่ Prompt ที่ต้องการและกด Inpaint