---
title: "เจาะลึก ControlNet ใน Stable Diffusion [Part8]"
url: https://www.thepexcel.com/stable-diffusion-part8/
type: post
date: 2023-06-17
updated: 2025-04-24
author: Sira Ekabut
categories: ["AI Image &amp; Video"]
tags: [stable diffusion, controlnet, ai art]
---

# เจาะลึก ControlNet ใน Stable Diffusion [Part8]

จากประสบการณ์ที่ใช้เครื่องมือ AI Gen รูปมาหลายตัว พบว่า **สิ่งที่ทำให้ Stable Diffusion โดดเด่นมากเมื่อเทียบกับเครื่องมืออื่นๆ นั่นก็คือสิ่งที่เรียกว่า ControlNet นั่นเอง**

 

แม้ว่าก่อนหน้านี้[ผมจะมีการเขียนถึง ControlNet ไปแล้วทีนึง](https://www.thepexcel.com/stable-diffusion-part4/) แต่มันก็ผ่านมาหลายเดือนแล้ว (หลายเดือนในโลกของ AI นี่คือนานมากกกก) ตอนนี้ ControlNet เก่งขึ้นกว่าเดิมมากๆ แล้ว จนผมต้องขอกลับมาพูดถึงมันอีกครั้ง โดยที่นอกจากจะอธิบายว่าแต่ละตัวคืออะไรแล้ว จะบอกวิธีการประยุกต์ใช้งานด้วย จะได้สามารถเอาไปใช้ได้ในงานจริงๆ ได้ครับ

 

ก่อนอื่นให้ทุกคน Update ControlNet เป็น Version ล่าสุดเท่าที่จะทำได้ (ณ ที่ผมเขียนบทความอยู่นี่ ผมใช้ ControlNet v1.1.224 ซึ่งจะมี Model Preprocessor ให้เลือกใช้มากมายเลยล่ะ แต่ในอนาคตก็คงโผล่เพิ่มมาอีกเรื่อยๆ

 

## รวมบทความ Stable Diffusion

 

 

## Setting ต่างๆ ที่สำคัญของ ControlNet ที่ควรรู้จัก

 

### Mode ของ ControlNet

 
- **Balanced **: เป็นโหมดการทำงานมาตรฐาน ซึ่ง ControlNet จะถูกใช้กับทั้งส่วน Conditioned และ Unconditioned (ในขั้นตอนการสุ่มตัวอย่าง
- **My prompt is more important**: เน้นที่ Prompt ของเรามากกว่า โดยทำให้ผลของ ControlNet จะลดลงอย่างเรื่อย ๆ ตลอดการทำงานของ U-Net
- **ControlNet is more important** : เน้นความสำคัญของ ControlNet โดย CFG scale จะทำหน้าที่เป็นตัวคูณสำหรับผลของ ControlNet ด้วย

 

## Resize mode

 

ควบคุมวิธีการจัดการเมื่อขนาดของภาพต้นฉบับมี “อัตราส่วนของรูป” ที่แตกต่างจากขนาดของภาพที่เราจะ Gen ออกมา

 
- **Just Resize **: ปรับขนาดความกว้างและความสูงภาพต้นฉบับ (เช่น ภาพมนุษย์ก้าง) เพื่อให้พอดีกับอัตราส่วนภาพที่เราจะ Gen
- **Crop and Resize** : Crop ภาพต้นฉบับ (เช่น ภาพมนุษย์ก้าง) เพื่อให้พอดีกับอัตราส่วนภาพที่เราจะ Gen
- **Resize and fill** : ปรับขนาดภาพต้นฉบับ (เช่น ภาพมนุษย์ก้าง) ให้พอดีกับอัตราส่วนโดย”เติมค่าที่ว่างเปล่า” เพื่อให้มีขนาดเท่ากับภาพที่เราจะ Gen

 

ป.ล. ถ้าติ๊ก **Pixel Perfect** มีการปรับขนาดให้เหมาะสมโดยอัตโนมัติ ผมนะนำให้ติ๊กด้วย

 

## ความสามารถของแต่ละ Model และ Preprocessor ที่ใช้คู่กัน

 

ผมจะพยายามเรียง Model ที่คล้ายกันมาอยู่ด้วยกัน (ไม่ได้เรียงตามตัวอักษร) เพื่อนๆ จะได้เทียบความแตกต่างได้ชัดเจนขึ้นนะครับ

 

**หมายเหตุ : **ทุก Model อาจจะใช้ Preprocessor เป็น None ได้ หากว่ารูปต้นฉบับผ่านการ Process มาตามที่ Model นั้นๆ ต้องการเรียร้อยแล้ว เช่น Model Openpose ต้องการรูปมนุษย์ก้าง หากรูปที่เราใส่เป็นมนุษย์ก้างอยู่แล้ว ก็ใช้แบบ None ได้เลย

 

**หมายเหตุ 2 **: เราสามารถเปิดใช้ ControlNet ได้หลายตัวพร้อมกัน (Multi-ControlNet) โดยไปเปิดใน Setting ได้นะครับ

 

### Prompt ที่ใช้

 

```
(best quality:1.4), (ultra highres:1.2), (photorealistic:1.4), (8k, RAW photo:1.2), (beautiful woman wearing jeans:1.4)

Negative prompt: paintings, sketches, (worst quality,low quality,normal quality:2), lowres, ((monochrome)), ((grayscale))

Steps: 30, Sampler: DPM++ SDE Karras, CFG scale: 7, Seed: 1352808870, Size: 512x768, Model hash: e4a30e4607, Model: majicmixRealistic_v6, Version: v1.3.0
```

 

ผลที่ได้ (แบบไม่มีการ Control)

 ![1](https://www.thepexcel.com/wp-content/uploads/2023/06/00068-1352808870.png) 

### รูปอ้างอิงที่จะใช้ใน ControlNet

 

วิธีการที่จะได้รูปต้นแบบมาเป็นตัวควบคุมนั้นทำได้หลายอย่าง เช่น

 
- เอามาจาก internet
- Gen ขึ้นมาด้วย SD เอง
- Gen ขึ้นมาด้วย AI ตัวอื่น เช่น MidJourney
- ใช้เครื่องมือ เช่น [Blender3D](https://www.blender.org/) หรือ [https://app.posemy.art/](https://app.posemy.art/) ในการสร้าง 3D Model ก่อนจะเอาออกมาเป็น Reference ก็ได้

 

อันนี้ตัวอย่างว่าเราสามารถกำหนดท่าทางใน [https://app.posemy.art/](https://app.posemy.art/) ได้เลย แล้วอาจเอามาใช้เป็นแบบ สำหรับ OpenPose , Depth, Canny, Normal ก็ได้ (เดี๋ยวตอนใน Model จะเห็นว่าแต่ละอันควบคุมอะไร)

 ![2](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt4-1024x657.png)   ![3](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt5.png)
*รูปปกติ*
   ![4](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt5-canny.png)
*Canny*
     ![5](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt5-depth.png)
*depth*
   ![6](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt5-normal.png)
*normal*
     ![7](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt5-openpose.png)
*openpose*
   ![8](https://www.thepexcel.com/wp-content/uploads/2023/06/PoseMyArt5-openposehand.png)
*openpose+hand*
   

เอาล่ะ แต่ในตัวอย่างของบทความนี้ ผมจะใช้รูปสมจริงนี้ใน ControlNet โดยใช้ร่วมกับ Prompt ข้างบน

 ![9](https://www.thepexcel.com/wp-content/uploads/2023/06/00058-1548899759-1-683x1024.png) 

เอาล่ะ เรามาดูกันว่าถ้าใช้รูปอ้างอิงข้างต้นเป็นตัวควบคุมในแต่ละ Model จะให้ผลเป็นยังไงในแต่ละ Preprocessor ด้วย

 

## ควบคุมมนุษย์โดยเฉพาะ

 

### Model: Openpose

 

OpenPose สามารถตรวจจับจุดสำคัญของร่างกายของมนุษย์ เช่น ตำแหน่งของหัว แขน ขา มือ หรือแม้แต่สีหน้าได้ เราจะใช้ Model นี้เพื่อควบคุมท่าทางของมนุษย์ โดยไม่ต้องลอกเลียนรายละเอียดอื่น ๆ เช่น เสื้อผ้า, ทรงผม และพื้นหลัง

 
- **openpose** : = body (ควบคุมร่างกาย) คือ ตา, จมูก, ตา, คอ, ไหล่, ข้อศอก, ข้อมือ, ข้อเข่า, และข้อเท้า

   ![10](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose.png)   ![11](https://www.thepexcel.com/wp-content/uploads/2023/06/00085-1352808870.png)   
- **openpose_face** : openpose + รายละเอียดบนใบหน้า

   ![12](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose_face.png)   ![13](https://www.thepexcel.com/wp-content/uploads/2023/06/00086-1352808870.png)   
- **openpose_faceonly** : รายละเอียดใบหน้าอย่างเดียว

   ![14](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose_faceonly.png)   ![15](https://www.thepexcel.com/wp-content/uploads/2023/06/00087-1352808870.png)   
- **openpose_hand **: openpose + มือ (ตำแหน่งนิ้ว)

   ![16](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose_hand.png)   ![17](https://www.thepexcel.com/wp-content/uploads/2023/06/00088-1352808870.png)   
- **openpose_full **: openpose + face + hand

   ![18](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose_full.png)   ![19](https://www.thepexcel.com/wp-content/uploads/2023/06/00089-1352808870.png)   

**Tips: **เราสามารถใช้คู่กับ extension [https://github.com/huchenlei/sd-webui-openpose-editor](https://github.com/huchenlei/sd-webui-openpose-editor) เพื่อสามารถกด Edit เพื่อดัดแปลงมนุษย์ก้างที่ Preprocess มาให้ได้ดั่งใจมากขึ้นได้ด้วยนะ (จริงๆ มีหลาย Extension เลย ที่ edit Openpose ได้)

 ![20](https://www.thepexcel.com/wp-content/uploads/2023/06/edit-openpose-1-1024x459.png)   ![21](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose_full-edit.png)   ![22](https://www.thepexcel.com/wp-content/uploads/2023/06/00078-1352808870-1.png)    

## กลุ่มควบคุมด้วยลายเส้น

 

### Model: Canny

 

ใช้ Canny Edge Detector ในการดึงเอา “เฉพาะเส้นขอบ” ของภาพออกมา ทำให้สามารถสร้างภาพที่มีโครงเหมือนภาพต้นฉบับได้

 
- Canny

   ![23](https://www.thepexcel.com/wp-content/uploads/2023/06/canny.png)   ![24](https://www.thepexcel.com/wp-content/uploads/2023/06/00069-1352808870.png)   

### Model: Scribble

 

ควบคุมภาพแบบใช้ลายเส้นที่ชุ่ยๆ เหมือนวาดด้วยเด็กน้อย หรือคนที่วาดรูปไม่เก่ง

 
- **scribble_hed** : Holistically-Nested Edge Detection (HED) เป็นตัวตรวจจับขอบที่ดีในการสร้างเส้นขอบเหมือนคนจริงๆ เหมาะสำหรับการเปลี่ยนสีและการเปลี่ยนรูปแบบภาพ

   ![25](https://www.thepexcel.com/wp-content/uploads/2023/06/scribble_hed.png)   ![26](https://www.thepexcel.com/wp-content/uploads/2023/06/00070-1352808870.png)   
- **scribble_pidinet **: ระบบสำหรับตรวจจับเส้นโค้งและเส้นตรงโดยใช้เทคนิคของ Pixel Difference network (Pidinet) ผลลัพธ์คล้ายกับ HED แต่จะได้เส้นที่สะอาดกว่าและมีรายละเอียดน้อยลง (เหมาะสำหรับการคัดลอกเส้นเค้าโครงโดยไม่ต้องคำนึงถึงรายละเอียดละเอียดที่เล็กน้อย)

   ![27](https://www.thepexcel.com/wp-content/uploads/2023/06/scribble_pidinet.png)   ![28](https://www.thepexcel.com/wp-content/uploads/2023/06/00071-1352808870.png)   
- **scribble_xdog** : วิธีการตรวจจับขอบแบบ EXtended Difference of Gaussian (XDoG) เวลาใช้ **สามารถปรับค่าเกณฑ์ xDoG เพื่อให้ผลเปลี่ยนไปได้** (เลขเยอะจะทำให้รายละเอียดน้อยลง)

 

xDog 1

   ![29](https://www.thepexcel.com/wp-content/uploads/2023/06/scribble_xdog1.png)   ![30](https://www.thepexcel.com/wp-content/uploads/2023/06/00072-1352808870.png)   

XDog32

   ![31](https://www.thepexcel.com/wp-content/uploads/2023/06/scribble_xdog32.png)   ![32](https://www.thepexcel.com/wp-content/uploads/2023/06/00073-1352808870.png)   

Xdog64

   ![33](https://www.thepexcel.com/wp-content/uploads/2023/06/scribble_xdog64.png)   ![34](https://www.thepexcel.com/wp-content/uploads/2023/06/00074-1352808870.png)   

### Model: Softedge

 

เป็นเหมือนตัวกึ่งกลางระหว่าง Canny กับ Scribble

 

มีหลายตัว เช่น

 
- softedge_hed

   ![35](https://www.thepexcel.com/wp-content/uploads/2023/06/softedge_hed.png)   ![36](https://www.thepexcel.com/wp-content/uploads/2023/06/00075-1352808870.png)   
- softedge_pidinet

   ![37](https://www.thepexcel.com/wp-content/uploads/2023/06/softedge_pidinet.png)   ![38](https://www.thepexcel.com/wp-content/uploads/2023/06/00076-1352808870.png)   
- softedge_hedsafe

   ![39](https://www.thepexcel.com/wp-content/uploads/2023/06/softedge_hedsafe.png)   ![40](https://www.thepexcel.com/wp-content/uploads/2023/06/00077-1352808870.png)   
- softedge_pidisafe

   ![41](https://www.thepexcel.com/wp-content/uploads/2023/06/softedge_pidisafe.png)   ![42](https://www.thepexcel.com/wp-content/uploads/2023/06/00078-1352808870.png)   

แนวทางการใช้งาน

 
- **คุณภาพผลลัพธ์ **: SoftEdge_HED > SoftEdge_PIDI > SoftEdge_HED_safe > SoftEdge_PIDI_safe
- **ความยืดหยุ่น** : SoftEdge_PIDI_safe > SoftEdge_HED_safe >> SoftEdge_PIDI > SoftEdge_HED
- **ผู้จัดทำแนะนำให้ใช้** : SoftEdge_PIDI

 

### Model: MLSd

 

MLSD (Mobile Line Segment Detection) เป็นตัวตรวจจับเฉพาะเส้นตรง (โดยไม่สนใจเส้นโค้งหรือเส้นที่ไม่ตรงเป๊ะๆ เลย) มักใช้ในการสกัดเส้นขอบที่มีขอบตรง เช่น การออกแบบอาคาร, ตกแต่งภายใน, ฉากถนน, กรอบรูป, และขอบกระดาษ

 
- MLSd

   ![43](https://www.thepexcel.com/wp-content/uploads/2023/06/mlsd.png)   ![44](https://www.thepexcel.com/wp-content/uploads/2023/06/00079-1352808870.png)   

## Model: Lineart

 

เป็น Model ที่มาใหม่ แต่ทรงพลังมาก มันสามารถแสดงเส้นขอบของภาพ โดยที่เรากำหนดรูปแบบของเส้นให้เหมาะกับรูปต้นฉบับได้

 
- **lineart_realistic** : เส้นสไตล์สมจริง

   ![45](https://www.thepexcel.com/wp-content/uploads/2023/06/lineart_realistic.png)   ![46](https://www.thepexcel.com/wp-content/uploads/2023/06/00082-1352808870.png)   
- **lineart_coarse** : เส้นสไตล์สมจริงโดยมีความหยาบๆ มากกว่า (จำนวนเส้นจะน้อยลง)

   ![47](https://www.thepexcel.com/wp-content/uploads/2023/06/lineart_coarse.png)   ![48](https://www.thepexcel.com/wp-content/uploads/2023/06/00083-1352808870.png)   
- **lineart_standard** (from white background and black lines) : ภาพจากเส้นขาวดำอยู่แล้ว (พอเอามาใช้กับภาพปกติ เลยประหลาด เพราะเหมาะกับรูปต้นแบบที่เป็นเส้นอยู่แล้วนั่นเอง)

   ![49](https://www.thepexcel.com/wp-content/uploads/2023/06/lineart_standard-from-white-bg-black-line.png)   ![50](https://www.thepexcel.com/wp-content/uploads/2023/06/00084-1352808870.png)   

### Model: Lineart Anime

 

ออกแบบมาเพื่อใช้ควบคุมภาพสไตล์ anime โดยเฉพาะ (พอเอามาใช้กับ Reference ภาพจริงจะแปลกๆ หน่อยนะ)

 
- **lineart_anime** : เส้นสไตล์อนิเมะ

   ![51](https://www.thepexcel.com/wp-content/uploads/2023/06/lineart_anime.png)   ![52](https://www.thepexcel.com/wp-content/uploads/2023/06/00112-1352808870.png)   
- **lineart_anime_denoise** : เส้นสไตล์อนิเมะแบบลดรายละเอียดการควบคุมลง

   ![53](https://www.thepexcel.com/wp-content/uploads/2023/06/lineart_anime_denoise.png)   ![54](https://www.thepexcel.com/wp-content/uploads/2023/06/00113-1352808870.png)   

## กลุ่มควบคุมด้วยความลึก/พื้นที่

 

### Model: Depth

 

ควบคุมข้อมูลความลึกของรูปจากภาพอ้างอิง ออกมาเป็นภาพ grayscale

 
- **depth_midas** : ได้เฉพาะความลึกตัวแบบออกมา

   ![55](https://www.thepexcel.com/wp-content/uploads/2023/06/depth_midas.png)   ![56](https://www.thepexcel.com/wp-content/uploads/2023/06/00094-1352808870.png)   
- **depth_leres** : ได้ความลึกตัวแบบและพื้นหลังออกมาด้วย

   ![57](https://www.thepexcel.com/wp-content/uploads/2023/06/depth_leres.png)   ![58](https://www.thepexcel.com/wp-content/uploads/2023/06/00095-1352808870.png)   
- **depth_leres++** : ได้ความลึกตัวแบบและพื้นหลังออกมาเยอะที่สุด

   ![59](https://www.thepexcel.com/wp-content/uploads/2023/06/depth_leresPlus.png)   ![60](https://www.thepexcel.com/wp-content/uploads/2023/06/00096-1352808870.png)   
- **depth_zoe** : เน้นควบคุม Object ค้อนข้างคล้ายๆ depth_midas

   ![61](https://www.thepexcel.com/wp-content/uploads/2023/06/depth_zoe.png)   ![62](https://www.thepexcel.com/wp-content/uploads/2023/06/00097-1352808870.png)   

### Model: Normal

 

ใช้ระบุลักษณะพื้นผิวของ Object คล้ายกับการใช้งาน Depth Map มักใช้ในการถ่ายทอดโครงสร้างสามมิติของภาพต้นแบบ

 
- **normal_bae** : มักได้พื้นผิวทั้ง Object และ Background

   ![63](https://www.thepexcel.com/wp-content/uploads/2023/06/normal_bae.png)   ![64](https://www.thepexcel.com/wp-content/uploads/2023/06/00098-1352808870.png)   
- **normal_midas** : มักได้พื้นผิวของ Object หลักอย่างเดียว

   ![65](https://www.thepexcel.com/wp-content/uploads/2023/06/normal_midas.png)   ![66](https://www.thepexcel.com/wp-content/uploads/2023/06/00099-1352808870.png)   

### Model: Seg

 

Seg ในที่นี้คือ Segmentation หรือการแบ่งกลุ่ม จะทำการบอกประเภทของวัตถุที่อยู่ในภาพอ้างอิงออกมาได้**ด้วยสีที่แตกต่างกัน** ใช้เพื่อควบคุมตำแหน่งและรูปร่างของวัตถุที่เราต้องการได้แบบเป๊ะๆ

 
- **seg_ofade20k** : การแบ่งกลุ่ม UniFormer (uf) ที่ฝึกสอนด้วยชุดข้อมูล ADE20K

   ![67](https://www.thepexcel.com/wp-content/uploads/2023/06/seg_ofade20k.png)   ![68](https://www.thepexcel.com/wp-content/uploads/2023/06/00101-1352808870.png)   
- **seg_ofcoco** : การแบ่งกลุ่ม OneFormer (of) ที่ฝึกสอนด้วยชุดข้อมูล ADE20K

   ![69](https://www.thepexcel.com/wp-content/uploads/2023/06/seg_ofcoco.png)   ![70](https://www.thepexcel.com/wp-content/uploads/2023/06/00102-1352808870.png)   
- **seg_ufade20k** : การแบ่งกลุ่ม OnFormer ที่ฝึกสอนด้วยชุดข้อมูล COCO

   ![71](https://www.thepexcel.com/wp-content/uploads/2023/06/seg_ufade20k.png)   ![72](https://www.thepexcel.com/wp-content/uploads/2023/06/00103-1352808870.png)   

## กลุ่มพิเศษ

 

### Model: IP2P สั่งเปลี่ยนรูปตามต้องการ

 

IP2P หรือ Instruct Pix2Pix ทำให้เราสามารถ “สั่ง” ให้รูปผลลัพธ์เปลี่ยนไปได้ตามต้องการ เป็นตัวที่สนุกมากๆๆ ขอบอกเลยครับ โคตรชอบ

 

โดยใส่รูปที่ต้องการสั่ง แล้วเลือก Preprocessor เป็น None

 

```
(best quality:1.4), (ultra highres:1.2), (photorealistic:1.4), (8k, RAW photo:1.2),  make woman very strong and muscular
```

 ![73](https://www.thepexcel.com/wp-content/uploads/2023/06/00116-1352808870.png) 

```
(best quality:1.4), (ultra highres:1.2), (photorealistic:1.4), (8k, RAW photo:1.2),  (make room on fire:1.4)
```

 ![74](https://www.thepexcel.com/wp-content/uploads/2023/06/00123-1352808870.png) 

### Shuffle

 

ตัวแปรก่อนประมวลผล Shuffle จะทำการ Random หมุนกวนภาพต้นฉบับแบบสุ่ม (ขึ้นกับ seed) สามารถใช้ในการถ่ายทอดแบบสีของภาพอ้างอิงได้

   ![75](https://www.thepexcel.com/wp-content/uploads/2023/06/shuffle.png)   ![76](https://www.thepexcel.com/wp-content/uploads/2023/06/00114-1352808870.png)   

### กลุ่ม T2IA

 
- **t2ia_color_grid **: จะควบคุมสีของรูปได้ โดยใช้วิธีลดขนาดภาพอ้างอิงลงถึง 64 เท่าแล้วขยายกลับเป็นขนาดเดิม ผลลัพธ์ที่ได้คือ ผลเป็นแบบตารางที่ประกอบด้วยสีเฉลี่ยของพื้นที่เดิม โดยต้องใช้คู่กับ Model t2iadapter_color

   ![77](https://www.thepexcel.com/wp-content/uploads/2023/06/t2ia_color_grid.png)   ![78](https://www.thepexcel.com/wp-content/uploads/2023/06/00106-1352808870.png)   
- **t2ia_sketch_pidi** : คล้ายๆ พวก Model ควบคุมโครงภาพ โดยต้องใช้คู่กับ Model t2iadapter_sketch

   ![79](https://www.thepexcel.com/wp-content/uploads/2023/06/t2ia_sketch_pidi.png)   ![80](https://www.thepexcel.com/wp-content/uploads/2023/06/00107-1352808870.png)   
- **t2ia_style_clipvision** : ใช้ทำ Style Transfer ได้ โดยแปลงภาพอ้างอิงเป็น CLIP Vision Embedding การฝังภาพนี้ประกอบด้วยข้อมูลเนื้อหาและสไตล์ของภาพเดิม โดยต้องใช้คู่กับ Model t2iadapter_style

   ![81](https://www.thepexcel.com/wp-content/uploads/2023/06/t2ia_style_clipvision-1020x1024.png)   ![82](https://www.thepexcel.com/wp-content/uploads/2023/06/00108-1352808870.png)
*nude เฉยเลย*
   

### กลุ่ม Reference

 

ช่วยให้สามารถสร้างภาพที่คล้ายกับภาพอ้างอิงได้

 
- **reference_only** : เลียนแบบรูป Reference

   ![83](https://www.thepexcel.com/wp-content/uploads/2023/06/00109-1352808870.png)   
- **reference_adain** : ใช้กับการเลียนแบบ Style จากรูป Reference (Style transfer)

   ![84](https://www.thepexcel.com/wp-content/uploads/2023/06/00110-1352808870.png)   
- **reference_adain+attn** : ทำข้างบนทั้งคู่

   ![85](https://www.thepexcel.com/wp-content/uploads/2023/06/00111-1352808870.png)   

## กลุ่มที่มักต้องใช้คู่กับเครื่องมืออื่น

 

### Model: Tile

 

เราใช้อันนี้ใน img2img โดยไม่ต้องใส่รูปใน ControlNet

 
- **tile_resample** : ใช้สำหรับเพิ่มรายละเอียดในภาพ “มักใช้ร่วมกับ Upscaler” (เช่น Script Ultimate Upscale + Model [4x-Ultrasharp](https://upscale.wiki/wiki/Model_Database)) เพื่อขยายภาพให้ใหญ่ขึ้นไปโดยที่ภาพจะไม่ค่อยเพี้ยนจากเดิม แม้จะ denoise ค่อนข้างสูงก็ตาม (ถ้าใส่ down sampling rate เยอะ ภาพจะเปลี่ยนจากเดิมได้มากขึ้น)

 ![86](https://www.thepexcel.com/wp-content/uploads/2023/06/00055-1548899759.0-683x1024.png)
*denoise 0.7 ยังไม่พังเลย*
 
- **tile_colorfix** : เหมือน tile resample แต่พยายามทำให้สีไม่เพี้ยนจากต้นแบบ (แม้ว่าจะ conflict กับ prompt) ถ้าเป็นรูปสมจริงอาจะไม่ค่อยเห็นผลนัก

 ![87](https://www.thepexcel.com/wp-content/uploads/2023/06/00056-1548899759.0-683x1024.png) 
- **tile_colorfix+sharp** : เหมือน tile colorfix แต่พยายามทำให้ภาพคมชัดมาก (ปรับ sharpness ได้)

 ![88](https://www.thepexcel.com/wp-content/uploads/2023/06/00057-1548899759.0-683x1024.png)
*sharpness 1*
 

### Model: Inpaint

 

เป็น Model ที่ “ใช้ตอน Inpaint” ซึ่งจำทำให้ได้ผลลัพธ์ที่ดีขึ้นมากๆ

 

วิธีใช้งาน Model นี้มี 2 แบบ คือ

 
1. **ใช้ใน Mode Text to IMG** : สามารถใส่รูปต้นฉบับเข้า ControlNet แล้ว Inpaint ในนั้นแล้ว Gen ตามปกติได้เลย รูปจะมีการแก้เฉพาะพื้นที่ที่เรา Inpaint โดยจะไม่มีอิธิพลที่ต้อง denoise จาก img2img มายุ่งด้วยเลย [รายละเอียดดูได้ที่คลิปนี้](https://youtu.be/qU3BI73yalM)
2. **ใช้ในโหมด Inpaint ของ IMG2IMG** : อันนี้รูปต้นฉบับให้ใส่ใน Inpaint ไม่ต้องใส่ใน ControlNet ช่วยให้สามารถใช้ Denoising Strength ที่ค่อนข้างเยอะตอน Inpaint ได้โดย ภาพรวมไม่เละ (เช่น ไม่มีหัวงอก แขนขางอก)

 

สมมติ Prompt ตอน inpaint แบบนี้

 

```
(best quality:1.4), (ultra highres:1.2), (photorealistic:1.4), (8k, RAW photo:1.2), (jeans:1.4)
```

   ![89](https://www.thepexcel.com/wp-content/uploads/2023/06/inpaint-mask-1.png)
*พื้นที่ Mask*
   ![90](https://www.thepexcel.com/wp-content/uploads/2023/06/00014-1352808870-683x1024.png)
*Inpaint แบบ Fill Denoise 0.6 แบบไม่เปิด ControlNet  
จะเห็นว่ามีความเพี้ยนเกิดขึ้นพอสมควร*
   
- **inpaint_global_harmonious **:

 ![91](https://www.thepexcel.com/wp-content/uploads/2023/06/00013-1352808870-683x1024.png) 
- **inpaint_only** :

 ![92](https://www.thepexcel.com/wp-content/uploads/2023/06/00016-1352808870-683x1024.png) 
- **inpaint_only+lama** : ตัวนี้ผลลัพธ์ค่อนข้างเจ๋งสุดๆ ไปเลย (LaMa คือ Resolution-robust **La**rge **Ma**sk Inpainting with Fourier Convolutions เป็น Model ที่ฉลาดเรื่องการ Inpaint มากๆ)

 ![93](https://www.thepexcel.com/wp-content/uploads/2023/06/00017-1352808870-683x1024.png) 

## Outpainting!

 

ตัว **inpaint_only+lama** มักใช้เพื่อเลียนแบบการ Outpaint ได้ด้วย แต่จะเจ๋งกว่า Outpaint ปกติมากๆ

 

prompt คือ

 

```
(best quality:1.4), (ultra highres:1.2), (photorealistic:1.4), (8k, RAW photo:1.2),( full body shot:1.5), (woman looking at viewer:1.4), casual cloth, ( pants),  in living room, (windows:1.3), (plant and vase:1.2), (lamp :1.4), (cupboard:1.1)
```

 

เปรียบเทียบให้ดูกับ Script ปกติ

 

ใช้ Script Outpainting mk2 ในโหมด Img2Img

 

ผลลัพธ์เกือบจะดีแล้ว แต่มีความเพี้ยนตรงรอยต่อจากภาพเดิม เช่น ขอบโซฟา เป็นต้น

 ![94](https://www.thepexcel.com/wp-content/uploads/2023/06/00019-1548899759.png) 

**ถ้าจะใช้ inpaint_only+lama**

 

**วิธีที่ 1: ใช้ Txt2Img **สามารถใช้โหมด Txt2Img แต่ใส่รูปต้นแบบใน ControlNet กำหนดขนาดผลลัพธ์ตามต้องการได้เลย แล้วให้เลือก ControlNet Mode เป็น Resize and Fill และ ControlNet is more important

 

เราจะพบว่าผลลัพธ์นั้นดูดีกว่าเดิมมาก

 ![95](https://www.thepexcel.com/wp-content/uploads/2023/06/00126-1548899759.png) 

**วิธีที่ 2 ใช้ img2Img** : ทำเหมือนกันเลย แต่ใส่รูปใน Img2Img ด้วย แล้วปรับค่า Denoise เช่นได้ตามใจชอบ (แนะนำ 0.6 ขึ้นไป และ สามารถใส่สูงถึง 1 ได้เลย)

 

แล้วใน ControlNet ก็ใส่รูปต้นแบบด้วย** (ใส่รูปต้นแบบทั้ง 2 ที่)** แล้วให้เลือก ControlNet Mode เป็น Resize and Fill และ ControlNet is more important เช่นกัน

 

ผมลองปรับ Denoise ให้ดูหลายๆ ค่า (ยิ่ง Denoise น้อย จะยิ่งคล้ายๆ พื้นที่เดิม)

 ![96](https://www.thepexcel.com/wp-content/uploads/2023/06/00028-1548899759.png)
*denoise 0.6*
 ![97](https://www.thepexcel.com/wp-content/uploads/2023/06/00029-1548899759.png)
*denoise 0.8*
 ![98](https://www.thepexcel.com/wp-content/uploads/2023/06/00024-1548899759.png)
*denoise 1*
 

ผลออกมาได้เทพมาก! ผลลัพธ์พอๆ กับใช้ Generative Fill ของ Photoshop Beta ที่เสียตังแพงๆ เลย แต่ใน SD ใช้ฟรี!!

 

## การประยุกต์

 

จริงๆ พอเรารู้ว่ามันควบคุม Object ด้วยวิธีต่างๆ ที่ผมบอกข้างบนแล้ว จริงๆ เราก็สามารถเอาภาพที่ Preprocess ได้มาดัดแปลง ปรับปรุงให้เข้าทางเราได้มากขึ้น

 

### ตัวอย่าง : Segmentation

 

เช่น ใน Segmentation เราใช้สีที่แตกต่างกันในการกำหนด Object ได้ แบบนี้เราก็สามารกำหนดได้เลยว่าจะมี Object อะไรอยู่ตรงไหน (แต่ถ้าให้ดีควร Prompt ช่วยด้วย)

 

เช่น ผมจะเอาพืชไปพันรอบตัวผู้หญิง ผมก็สามารถใช้ Photo Editor อย่าง Photoshop หรือ[Photopea](https://www.photopea.com/) ไปวาดรูปเพิ่มให้สีของพืชพันตัวผู้หญิงในตำแหน่งที่ต้องการได้เลย

 

```
(best quality:1.4), (ultra highres:1.2), (photorealistic:1.4), (8k, RAW photo:1.2), (beautiful woman wearing jeans:1.4), (get tied by plant vine:1.4)
```

   ![99](https://www.thepexcel.com/wp-content/uploads/2023/06/seg_ofade20k-mod.png)
*ไปวาดรูปเพิ่มใน Photo Editor ให้สีของพืชพันตัวผู้หญิง*
   ![100](https://www.thepexcel.com/wp-content/uploads/2023/06/00131-1352808870.png)
*เราก็จะควบคุมผลลัพธ์ได้ดีขึ้น*
   

นอกจากนี้เรายังประยุกต์ในการดัดแปลงภาพโครงลายเส้นต่างๆ ให้มีสิ่งที่เราต้องการได้เช่นกันด้วยการวาด หรือตัดต่อเข้าไป

 

### ตัวอย่าง : Scribble

 

อันนี้ใช้ Scribble แล้วไปดัดแปลงใน [Photopea](https://www.photopea.com/) เพื่อเปลี่ยนรูปให้ได้ดั่งใจ

   ![101](https://www.thepexcel.com/wp-content/uploads/2023/06/scribble_hed-mod.png)   ![102](https://www.thepexcel.com/wp-content/uploads/2023/06/00132-1352808870.png)   

### ตัวอย่าง **Multi-ControlNet**

 

เราสามารถใช้ ControlNet หลาย Model ร่วมกันได้ ซึ่งเราสามารถเล่นอะไรแปลกๆ ได้ตามใจชอบ ซึ่งในที่นี้ผมขอใช้ตัวที่ไม่ conflict กันมากนัก

 

OpenPose + Shuffle

 ![103](https://www.thepexcel.com/wp-content/uploads/2023/06/00134-1352808870.png) 

OpenPose + TiAdapter Color

 ![104](https://www.thepexcel.com/wp-content/uploads/2023/06/00135-1352808870.png) 

MLSD + TiAdapter Color

 ![105](https://www.thepexcel.com/wp-content/uploads/2023/06/00136-1352808870.png) 

MLSD+Shuffle

 ![106](https://www.thepexcel.com/wp-content/uploads/2023/06/00138-1352808870.png) 

### ลอง Mix & Match เล่นๆ : ใช้ Preprocessor ที่ไม่ใช่ของ Model

 

ใช้ Segment ใน TiColor

   ![69](https://www.thepexcel.com/wp-content/uploads/2023/06/seg_ofcoco.png)   ![108](https://www.thepexcel.com/wp-content/uploads/2023/06/00143-1352808870.png)   

ใช้ TiColor ใน Model Segmentation

   ![77](https://www.thepexcel.com/wp-content/uploads/2023/06/t2ia_color_grid.png)   ![110](https://www.thepexcel.com/wp-content/uploads/2023/06/00142-1352808870.png)   

ใช้ TiColor ใน Tile

   ![77](https://www.thepexcel.com/wp-content/uploads/2023/06/t2ia_color_grid.png)   ![112](https://www.thepexcel.com/wp-content/uploads/2023/06/00141-1352808870.png)   

ใช้ OpenPoseใน Scribble

   ![10](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose.png)   ![114](https://www.thepexcel.com/wp-content/uploads/2023/06/00153-1352808870.png)   

ใช้ OpenPoseใน Soft Edges

   ![10](https://www.thepexcel.com/wp-content/uploads/2023/06/openpose.png)   ![116](https://www.thepexcel.com/wp-content/uploads/2023/06/00155-1352808870.png)   

ความ Creative ไม่มีที่สิ้นสุด!!

 

## Unofficial Model

 

### สร้าง QR Code

 

ใช้สร้างรูปที่ใช้ QR Code เป็น Reference เพื่อให้สามารถ Scan ในฐานะเป็น QR Code ได้ ซึ่งมี 2 แนวทางที่ใช้ Model ต่างกัน แต่ก่อนอื่นเรามาเตรียมรูป QR ก่อน

 

อันนี้รูป QR Code ต้นแบบ

 ![117](https://www.thepexcel.com/wp-content/uploads/2023/06/qr.png) 

(สร้างจากที่นี่ [https://dnschecker.org/qr-code-generator.php](https://dnschecker.org/qr-code-generator.php)  
โดยให้ย่อ Link ให้สั้นก่อน แล้วค่อยเอาไปทำ QR   
โดยเลือก Error Correction เป็น H=High)

 

#### วิธีที่ 1 ใช้ Brightness Model

 

ControlNet Brightness Model (ควบคุมความสว่าง) : ไป[โหลดที่นี่](https://huggingface.co/ioclab/ioc-controlnet/tree/main/models)

 

อันนี้ผมใช้ Brightness (ปรับ Weight ให้เหมาะ) และปรับ Model Resize & Fill (ผม Gen ภาพ 512×768) และ Control Start & End ให้ดี

 ![118](https://www.thepexcel.com/wp-content/uploads/2023/06/00017-1352808870-1.png) 

#### วิธีที่ 2 ใช้ ControlNet QR Code Model

 

ControlNet QR Code Model : (ใช้ทำ QR โดยเฉพาะ) ต้องไป[โหลดเพิ่มที่นี่ (โหลดทั้ง model และ yaml)](https://huggingface.co/DionTimmer/controlnet_qrcode-control_v1p_sd15/tree/main)

 

อันนี้ผมใช้ Model QR Code ซึ่งเท่าที่ลอง มีประเด็นสำคัญดังนี้

 
- ต้อง Gen รูปเป็นจตุรัส เช่น 768×768 ถึงจะ Work
- ต้องปรับ **Control Weight ให้มากกว่า 1 เช่น 1.6 ขึ้นไปเลย** ไม่งั้นจะ Scan ไม่ติด
- เลือก Preprocessor เป็น Invert จะได้ลายสีดำ (ค่าปกติจะได้ลายสีขาว)

 

นอกจากนี้เรายังสามารถ พลิกแพลงใช้ร่วมกันหลายๆ อย่าง เช่น ผม Gen รูปนี้ออกมาก่อนด้วย Txt2img ปกติ โดยยังไม่ Control อะไรเลย

 ![119](https://www.thepexcel.com/wp-content/uploads/2023/06/00072-198291294.png) 

จากนั้นลองเอารูปที่ได้ไปใช้เป็นตัว Control Model ControlNet อื่นๆ ที่จะใช้ Gen คู่กับ ControlNet QR Code (ในที่นี้ผมใช้ Openpose ช่วยคุมอีกก็ได้)

 

ผลของผมที่ออกมาได้แบบนี้

 ![120](https://www.thepexcel.com/wp-content/uploads/2023/06/00076-198291294.png) 

ซึ่ง iphone ของผม scan ติดด้วยนะ 5555

  

## สรุป

 

เห็นรึยังว่า “ControlNet โคตรทรงพลัง!” ดังนั้น.. หัดใช้ให้เป็นเถอะครับ!!

---

_Source: [https://www.thepexcel.com/stable-diffusion-part8/](https://www.thepexcel.com/stable-diffusion-part8/)_
