---
# System prepended metadata

title: SD-04 tex2img & img2img 基本操作
tags: [mlsd, tex2img, img2img, "ControlNet\_", depth, lora, canny]

---

SD-04 tex2img & img2img 基本操作
![SD-04 t2i & i2i 基本操作](https://hackmd.io/_uploads/BJHqSVehp.png)


台大李弘毅教授Hung-yi Lee
【生成式AI時代下的機器學習(2025)】第一講：一堂課搞懂生成式人工智慧的技術突破與未來發展
https://www.youtube.com/watch?v=QLiKmca4kzI&t=893s

**Web UI的操作介面**
![螢幕擷取畫面 2024-02-19 115909](https://hackmd.io/_uploads/HyOmfUl3p.png)

**更改模型路徑修改** (copy 電腦教室的.bat檔)
![image](https://hackmd.io/_uploads/ByU-BOZi0.png)
編輯修改webui-user.bat 檔案


**Lora的圖片如何顯示**
需安裝Civitai Helper執行Scan後 就會下載Lora圖片至檔案中
![螢幕擷取畫面 2024-03-10 193514](https://hackmd.io/_uploads/S14IsfsTp.png)
Lora下載可在資料夾中進行分類 依類別放置Lora檔案
![螢幕擷取畫面 2024-03-10 193715](https://hackmd.io/_uploads/SyKYjfopp.png)

![螢幕擷取畫面 2024-03-10 194440](https://hackmd.io/_uploads/r1946Mjpa.png)

![螢幕擷取畫面 2024-03-10 194810](https://hackmd.io/_uploads/SyXGCfoTT.png)

![螢幕擷取畫面 2024-03-10 194717](https://hackmd.io/_uploads/HJ9Aafj6T.png)

**PNG Info圖片資訊**
將筆記中的圖片 拉入PNG Info(圖片資料)即可看到生成的所有參數設定
只要是用SD生成的圖片 都可以查看生成時所設定的參數
![image](https://hackmd.io/_uploads/BJAKXDJjC.png)



**tex2img(文生圖)&img2img(圖生圖)的基本操作**
Prompt: masterpiece,best quality,....
Negative Prompt: ugly,normal,....

1. Prompt: masterpiece,best quality,modern single house,façade design,window,outdoors,tree,landscape,,real world location,background,4K uhd,

1. Negative Prompt:noisy,ugly,low quality,deform,blurry,



1. Prompt:Modern luxury apartment in Taipei, glass and metal facade, highlights urban exquisite charm, rainy and humid weather, outdoor,
(一座位於台北市的現代豪華公寓大樓，以都會風格為主，提供高檔設施和便利的生活方式，突顯都市生活的精緻魅力。)
1. Negative Prompt:Rural landscapes, traditional homes, snow
(鄉村風景、傳統住宅、雪)

1. Prompt:Seaside villa in Taitung, wood and glass facade, comfortable seaside living, outdoor,building facade,
(一座位於台東縣的海濱度假別墅，結合了現代設計與海洋元素，營造出寧靜與放鬆的度假氛圍，提供舒適的海濱生活體驗。)
Negative Prompt:Urban pollution, desert landscapes, heavy snow
(城市污染、沙漠景觀、大雪)


1. Prompt: masterpiece , best quality, Office Building, outdoors, sky, day, tree, blue sky, ground vehicle, building, scenery, motor vehicle, walking, city, car, road, lamppost, street, real world location,background,4K uhd,
(傑作，最佳品質，（（辦公大樓）），戶外，天空，白天，樹，藍天，地面車輛，建築，風景，摩托車，步行，城市，汽車，道路，燈柱，街道，真實世界位置，解析度)

1. (RAW photo,subject,8k uhd,dslr,soft lighting,high quality)
(RAW 照片、主體、8k 超高清、數位單眼相機、柔和的燈光、高品質)

1. photography, dynamic view, minimalist design, depth of field that highlights architectural photography, 
(攝影、動態取景、簡約設計、突顯建築攝影的景深，)

**範例練習**
**手繪底圖一(1477*1108)**
![75603](https://hackmd.io/_uploads/HJIgO1bCR.jpg)
**Resize imagine(512x384) or (1024x768)**
![image](https://hackmd.io/_uploads/rJEiAht5R.png)

**Img2Img**
![00001-851982082](https://hackmd.io/_uploads/rkL-_kkh1l.jpg)


**立面底圖一**
以schroder house立面為底圖 
底圖一(512x354)
![schroder-1](https://hackmd.io/_uploads/B1c3yG7VT.jpg)
底圖二(512x384)
![schroder-2](https://hackmd.io/_uploads/SJjDOdt06.jpg)


AI生成1
![00005-1742589714](https://hackmd.io/_uploads/Hkxgoy13Jg.jpg)
AI生成2
![00002-2076960880](https://hackmd.io/_uploads/rJIi5JJ3yl.jpg)
AI生成3
![00004-1809622499](https://hackmd.io/_uploads/ByOR5y131g.jpg)

加入Lora 手繪風格
![螢幕擷取畫面 2024-03-10 203359](https://hackmd.io/_uploads/HkJIYQiap.png)

![螢幕擷取畫面 2024-03-10 203700](https://hackmd.io/_uploads/Hy-FtXiTT.png)

AI生成4
![00012-866889695](https://hackmd.io/_uploads/HJPook12kl.jpg)

**修改圖面寬度 及高度 **
記得調整縮放模式(Resize Mode) 修改圖面比例
共有四種可調整的選項:Just resize, Crop and resize, Resize and fill, Just resize(latent upscale)
若要增加建築物之外的空間 且保持建築比例不變 Resize and fill
![螢幕擷取畫面 2024-03-10 203746](https://hackmd.io/_uploads/rkAjF7ja6.png)

1.Just resize
![00032-1262313125](https://hackmd.io/_uploads/HkWtqmjap.jpg)
2.Crop and resize
![00033-708722145](https://hackmd.io/_uploads/H1ZF9XiTT.jpg)
3.Resize and fill
![00034-3833941477](https://hackmd.io/_uploads/BkWtcQi6a.jpg)
4.Just resize(latent upscale)
![00035-1712778170](https://hackmd.io/_uploads/By-t97iT6.jpg)

**加入Lora讓效果更突出**
Prompt:masterpiece,best quality,De Stijl,schroder house,modern single house,façade design,window,outdoors,tree,landscape,,real world location,background,4K uhd,
加入lora:landscapesupermix_v2:0.85

![螢幕擷取畫面 2024-03-10 205235](https://hackmd.io/_uploads/HygjpmiT6.png)

![螢幕擷取畫面 2024-03-10 205416](https://hackmd.io/_uploads/SJKjpmjTT.png)

![grid-0002](https://hackmd.io/_uploads/rytE0Qia6.jpg)


在數次跌代後 選一張滿意的圖片 再放入img2img的inpaint進行建築以外的環境局部重繪
![00056-3759292381](https://hackmd.io/_uploads/r1A_S-3aa.jpg)
![螢幕擷取畫面 2024-03-11 121621](https://hackmd.io/_uploads/B1sjHb3pp.png)


**inpaint局部重繪**
Prompt:landscape,suburbs background,
加入lora:landscapesupermix_v2:0.85

![00073-2016937900](https://hackmd.io/_uploads/BkWT7Wh6p.jpg)

![00074-2016937901](https://hackmd.io/_uploads/ryWp7-2Ta.jpg)

![00075-2016937902](https://hackmd.io/_uploads/rJbpQ-npp.jpg)

選擇手繪風格為底圖 在局部重繪時 加入二個Lora 我會讓二個Lora的參數相加值不超過1 數值過大就會常出現過擬合的效果 
<lora:landscapesupermix_v2:0.6>,<lora:CWG_archi_sketch_v1:0.4>

![00090-153012497](https://hackmd.io/_uploads/HJcOOZhaa.jpg)

![螢幕擷取畫面 2024-03-11 122847](https://hackmd.io/_uploads/r1P2_b3TT.png)

![00106-1000708245](https://hackmd.io/_uploads/Sk9TtW2pT.jpg)

![00098-4289533370](https://hackmd.io/_uploads/Bk7s_bhT6.jpg)


**練習示範**
在文生圖中輸入 
prompt:masterpiece,best quality,modern building,road,landscape, office building,architectural photography,
Negative prompt: curve,lowres,normal quality,worst quality,cropped,blurry,
![00059-3889573801](https://hackmd.io/_uploads/r1Cfh0Ipa.png)
生成參數如下
Steps: 30, Sampler: Euler a, CFG scale: 7, Seed: 3889573801, Size: 768x512, Model hash: 6ce0161689, Model: v1-5-pruned-emaonly, Version: v1.8.0

**在圖生圖中 進行inpaint 局部重繪**
![螢幕擷取畫面 2024-03-07 142126](https://hackmd.io/_uploads/S1i7pCI6T.png)
將前面道路部分塗起來 並寫入prompt如下
beautifully landscape,grass,flower,tree,

Denoising strength的參數值 0.1~1.0 將決定重繪幅度大小
0.7是一個臨界值
![00027-1179327672](https://hackmd.io/_uploads/BkzlkJwp6.png)

prompt:photography, dynamic view, minimalist building facade design, Canon EOS 5D Mark IV, EF 24mm f/1. 4L II USM lens, set f/2. 8, depth of field that highlights architectural photography, 

