🎯 Mục tiêu bài học
Prompt engineering cho images rất khác với text. Bài này dạy các kỹ thuật để tạo hình ảnh chất lượng cao, nhất quán và đúng ý muốn.
Sau bài này, bạn sẽ:
✅ Master prompt anatomy và structure cho image generation ✅ Sử dụng style keywords, composition techniques, camera settings ✅ Áp dụng prompt weighting cho DALL-E và Stable Diffusion ✅ Duy trì consistency khi tạo batch images
🔍 Prompt Anatomy
Formula cơ bản
1[Subject] + [Action/Pose] + [Environment] + [Style] + [Lighting] + [Quality modifiers]Ví dụ
1prompt = """2A Vietnamese woman in traditional ao dai, 3standing in a lotus garden at golden hour,4soft natural lighting, shallow depth of field,5professional photography, 8K, highly detailed6"""78negative = """9low quality, blurry, distorted, deformed,10bad anatomy, bad hands, watermark, text11"""Checkpoint
Bạn đã hiểu cấu trúc prompt gồm Subject, Style, Composition, Lighting và Quality chưa?
🎨 Style Keywords
Photography Styles
1styles = {2 "portrait": "professional portrait photography, studio lighting, sharp focus",3 "landscape": "landscape photography, golden hour, wide angle, vivid colors",4 "product": "product photography, white background, studio lighting, commercial",5 "street": "street photography, candid, natural light, urban",6 "macro": "macro photography, extreme close-up, detailed texture, bokeh"7}Art Styles
1art_styles = {2 "watercolor": "watercolor painting, soft edges, flowing colors, artistic",3 "oil_painting": "oil painting, impasto technique, rich textures, classical",4 "digital_art": "digital art, clean lines, vibrant, modern illustration",5 "anime": "anime style, cel-shaded, detailed, studio quality",6 "minimalist": "minimalist design, clean, simple, geometric, flat colors"7}Checkpoint
Bạn đã thử áp dụng các style keywords khác nhau để thay đổi phong cách ảnh chưa?
📐 Composition Techniques
Rule of Thirds
1composition_prompts = {2 "rule_of_thirds": "subject positioned at rule of thirds intersection",3 "centered": "centered composition, symmetrical",4 "leading_lines": "leading lines drawing eye to subject",5 "golden_ratio": "golden ratio composition, balanced",6 "aerial": "bird's eye view, top-down perspective",7 "low_angle": "low angle shot, dramatic perspective"8}Camera Settings
1camera_prompts = {2 "wide": "wide angle lens, 24mm, expansive view",3 "portrait": "85mm lens, shallow depth of field, bokeh",4 "macro": "macro lens, extreme detail, close-up",5 "telephoto": "telephoto lens, compressed perspective",6 "tilt_shift": "tilt-shift photography, miniature effect"7}Checkpoint
Bạn đã biết cách sử dụng composition keywords và camera settings trong prompt chưa?
⚡ Prompt Weighting
DALL-E 3 (natural language emphasis)
1# DALL-E uses natural language - emphasize with adjectives2prompt_dalle = """3An EXTREMELY detailed and HIGHLY realistic photo of a4modern Vietnamese skyline at sunset, with VIBRANT golden5and orange colors, CRYSTAL CLEAR reflections in the river6"""Stable Diffusion (syntax weighting)
1# SD supports (word:weight) syntax2prompt_sd = """3(masterpiece:1.3), (best quality:1.2), 4a beautiful (Vietnamese landscape:1.5),5(golden hour:1.2) lighting,6(detailed:1.1) rice terraces7"""89# Higher weight = more emphasis10# (word:1.5) = 50% more emphasis11# (word:0.5) = 50% less emphasisCheckpoint
Bạn đã hiểu sự khác biệt giữa prompt weighting trong DALL-E và Stable Diffusion chưa?
📝 Negative Prompting
1# Standard negative prompt2standard_negative = """3low quality, worst quality, blurry, 4distorted, deformed, disfigured,5bad anatomy, bad hands, extra fingers,6watermark, text, logo, signature,7oversaturated, underexposed8"""910# Style-specific negatives11photo_negative = standard_negative + ", cartoon, illustration, painting, drawing"12art_negative = standard_negative + ", photo, realistic, photograph"Checkpoint
Bạn đã biết cách sử dụng negative prompts để loại bỏ artifacts không mong muốn chưa?
🛠️ Prompt Templates và Consistency
Prompt Templates với LangChain
1from langchain_openai import ChatOpenAI2from langchain_core.prompts import ChatPromptTemplate34llm = ChatOpenAI(model="gpt-4o-mini")56prompt_generator = (7 ChatPromptTemplate.from_messages([8 ("system", """Ban la image prompt engineer.9 Tao prompt chi tiet cho image generation tu mo ta ngan.10 Include: subject, style, lighting, composition, quality modifiers.11 Output chi prompt, khong giai thich."""),12 ("human", "Tao prompt cho: {description}\nStyle: {style}")13 ])14 | llm15)1617result = prompt_generator.invoke({18 "description": "Quan ca phe Viet Nam hien dai",19 "style": "professional photography"20})Consistency Techniques
1# Maintain consistent style across batch2style_prefix = "professional photography, consistent lighting, 4K, "34subjects = [5 "modern office interior",6 "team meeting room", 7 "reception area",8 "executive lounge"9]1011prompts = [style_prefix + subject for subject in subjects]12# All images will share consistent visual styleCheckpoint
Bạn đã thử dùng LLM để auto-generate image prompts và duy trì style consistency chưa?
🎯 Tổng kết
Bài tập thực hành
- Tạo 5 images cùng subject, khác style (photo, watercolor, anime, etc.)
- Thử nghiệm prompt weighting cho Stable Diffusion
- Build prompt generator với LLM
- Tạo bộ ảnh sản phẩm nhất quán
Challenge: Tạo brand visual identity với consistent style
Câu hỏi tự kiểm tra
- Prompt weighting hoạt động như thế nào trong Stable Diffusion và tại sao nó hữu ích cho việc kiểm soát output?
- Làm sao duy trì style nhất quán (consistency) khi tạo nhiều ảnh trong cùng một bộ sản phẩm?
- Các thành phần chính của một image prompt hiệu quả gồm những gì (subject, style, lighting, composition)?
- Sử dụng LLM để tự động tạo prompt cho image generation có những lợi ích và hạn chế gì?
🎉 Tuyệt vời! Bạn đã hoàn thành bài học Advanced Prompting Techniques!
Tiếp theo: Chúng ta sẽ học cách chỉnh sửa hình ảnh với AI - inpainting, outpainting và background removal.
