Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> การเขียนโปรแกรม

ความแตกต่างระหว่าง Flood-fill และ Boundary-fill Algorithm

ในโพสต์นี้ เราจะทำความเข้าใจความแตกต่างระหว่าง flood fill algorithm และ boundary fill algorithm พวกมันคือ area-filling algorithms สามารถแยกได้จากว่า random pixel มีสีต้นฉบับของ region หรือไม่

Flood-fill algorithm

  • รู้จักว่า seed fill algorithm
  • คำนวณพื้นที่ที่เชื่อมต่อกับ node ที่กำหนด ใน multi-dimensional array
  • ทำงานโดย fill หรือ recolor พื้นที่เฉพาะที่มีสีต่างกันด้านใน และทำให้ boundary ของภาพ
  • แทนด้วยภาพที่มี neighborhood มี borders และ distinct color regions
  • Specific interior color แทนที่ได้ เพื่อ paint ส่วนเหล่านี้
  • Memory consumption สูง
  • Algorithsm ค่อนข้าง simple
  • ประมวลผลภาพที่มี boundary colors มากกว่า 1 ได้
  • ช้ากว่า boundary-fill algorithm
  • Random color ใช้ paint interior ได้ และ old pixel ถูกแทนที่ด้วย new one
  • Efficient algorithm

2 วิธีสร้าง multiple boundaries โดยเชื่อม pixels -

  • 4-connected way: pixel มีเพื่อนบ้านสูงสุด 4 ตำแหน่ง ซ้าย, ขวา, บน, ล่าง
  • 8-connected way: pixel มีเพื่อนบ้านสูงสุด 8 ตำแหน่ง ตรวจสอบ 4 diagonal pixels

Boundary-fill algorithm

  • เมื่อ boundary มี single color algorithm ทำงาน outward pixel by pixel จนเจอ boundary color
  • Implemented ใน interactive painting packages ที่ inside points เลือกได้ง่าย
  • Algorithm เริ่มรับ coordinates ของ inside point (x, y), boundary color และ fill color เป็น input
  • จาก (x, y) ตรวจสอบ neighboring locations ว่าเป็น boundary color หรือไม่
  • ถ้าไม่ใช่ boundary color จะ paint ด้วย fill color และทดสอบ adjacent pixels ต่อ
  • Process จบเมื่อ pixel ทั้งหมดจนถึง boundary color ถูกตรวจสอบ
  • Area ถูกกำหนดด้วย single color
  • Memory consumption ต่ำกว่า
  • เร็วกว่า flood-fill
  • ซับซ้อนกว่า flood-fill
  • ประมวลผลภาพที่มี single boundary color ได้