การบีบอัดข้อมูล
แนะนำใหม่
21:52
ระบบตัวเลข & ข้อมูล
รูปนี้ เพลงนี้ วิดีโอนี้ ชื่อของคุณ ข้อความ ไฟล์ทุกไฟล์บนทุกอุปกรณ์ — ภายในคอมพิวเตอร์ ทั้งหมดนั้นคือเพียงเลขศูนย์และเลขหนึ่ง.…
บรรยายภาษาอังกฤษ · สลับคำบรรยายภาษาอังกฤษและภาษาจีนได้
ในบทเรียนนี้
| English | ความหมาย |
|---|---|
| compression/kəmˈpreʃn/ | การบีบอัด |
| file format | A way of organising and storing data in a file. |
| HD video | Video with a high number of pixels in each frame. |
| MB | A unit of data equal to about one million bytes. |
| terabytes | Units of data, each equal to about one trillion bytes. |
| Streaming/ˈstriːmɪŋ/ | The process of playing media while receiving it over a network. |
| Lossless/ˈlɒsləs/ | Describing compression from which the original data can be recovered exactly. |
| Lossy/ˈlɒsi/ | Describing compression that discards some original information so it cannot be perfectly recovered. |
| storage space | The amount of room available for keeping data on a device. |
| bandwidth/ˈbændwɪdθ/ | แบนด์วิดท์ |
| Run-length encoding/rʌn leŋθ enˈkəʊdɪŋ/ | A lossless method that stores repeated values as one value and a count. |
| run/rʌn/ | A sequence of identical values that are next to each other. |
| pixels/ˈpɪkslz/ | An individual picture element in a digital image or display. |
| Dictionary coding/ˈdɪkʃənəri ˈkəʊdɪŋ/ | A lossless method that replaces repeated data sequences with short references to a dictionary. |
| Huffman coding/ˈhʌfmən ˈkəʊdɪŋ/ | การเข้ารหัสฮูฟแมน |
| dictionary/ˈdɪkʃənəri/ | A data structure that stores associations between keys and their values. |
| byte sequences | Groups of bytes arranged in a particular order. |
| index/ˈɪndeks/ | A position marker or lookup structure used to locate data within a collection or database. |
| program code | Instructions written in a programming language for a computer to follow. |
| average code length | The average number of bits used to represent each symbol. |
| decoder/dɪˈkəʊdə/ | A program or device that changes encoded data back into its original form. |
| nodes/nəʊdz/ | Points or units in a network, graph or linked structure, connected by relationships or edges. |
| tree/triː/ | A structure of connected nodes that can split into branches. |
| pitches | How high or low sounds seem to the listener. |
| spatial/ˈspeɪʃl/ | เชิงพื้นที่ |
| frame/freɪm/ | A discrete unit in a sequence or transmission; in video, one complete image, and in networking, a link-layer data unit. |
| temporal/ˈtempərəl/ | เชิงเวลา |
| Text file/tekst faɪl/ | Dictionary and Huffman coding turn repeated words and common characters into short codes. It must stay lossless, because one changed character changes the meaning. |
| characters/ˈkærɪktəz/ | A text unit such as a letter, digit, punctuation mark or other symbol. |
| Bitmap image | RLE for runs of identical pixels in icons and diagrams. |
| colour depth/ˈkʌlə depθ/ | The number of bits used to represent the colour of each pixel. |
| resolution/ˌrezəˈluːʃn/ | The ability to distinguish fine detail or closely separated features. |
| Vector graphic/ˈvektə ˈɡræfɪk/ | The drawing list is already small. Remove drawing objects that are not needed, store coordinates to fewer decimal places, or apply a lossless method such as ZIP to the file. |
| drawing objects/ˈdrɔːɪŋ ˈɒbdʒekts/ | Separate shapes, text items or other elements that make up an editable drawing. |
| coordinates/kəʊˈɔːdɪnəts/ | Ordered values specifying the position of a point relative to a chosen system. |
| Sound file | Lossy MP3 or AAC removes what the ear cannot hear. |
| sampling rate/ˈsæmplɪŋ reɪt/ | The number of sound samples taken each second. |
| sample/ˈsæmpl/ | A measurement of a sound signal at a particular time. |
| megabits per second | A unit of data rate equal to one million bits per second. |
| buffer/ˈbʌfə/ | A temporary storage area holding data while it is transferred or processed. |
| data rate | The amount of data transferred or processed in a given time. |
สามตัวอักษรที่ทำให้เว็บทำงานได้
- ใน 1987 โปรแกรมเมอร์ชื่อ Phil Katz เขียนโปรแกรมบีบอัดและวางรูปแบบไฟล์ไว้ในพื้นที่สาธารณะ เขาตั้งชื่อว่า ZIP เขาเป็น 24
- Nothing about the web works without that idea. A single uncompressed second of HD video is about 187 MB; a two-hour film would be 1.3 terabytes. Streaming it over a home connection is arithmetically impossible.
- ภาพยนตร์ที่คุณดูอาจเป็นเพียงหนึ่งในพันของปริมาณนั้น แต่ยังดูถูกต้องเพราะการบีบอัดทิ้งรายละเอียดที่ตาเราไม่เคยสังเกตเห็น
- This lesson is compression: the two families, the three lossless methods, and how to justify one for a given file.

การบีบอัดแบบไม่สูญเสียและการบีบอัดแบบสูญเสีย
- การบีบอัด ลดขนาดไฟล์ ประหยัดพื้นที่จัดเก็บและ แบนด์วิดท์ ในการส่งข้อมูล ทำให้ดาวน์โหลดและสตรีมเร็วขึ้น
- Lossless (ไม่สูญเสียข้อมูล) คือการบีบอัดที่ recovering ข้อมูลต้นฉบับได้ ครบถ้วนตามเดิม ZIP และ PNG เป็น lossless
- Lossy (สูญเสียข้อมูล) เป็นการลบข้อมูลบางส่วนอย่างถาวร ทำให้ ไม่สามารถ recover ข้อมูลต้นฉบับได้ JPEG, MP3 และวิดีโอแบบสตรีมมิ่งเป็น lossy

Recover exactly, or shrink much further -> Recover ได้ครบถ้วน หรือหดขนาดได้มากกว่านั้น
การบีบอัดข้อมูลที่ไม่สูญเสียข้อมูลหมายถึง:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
การบีบอัดข้อมูลที่ไม่สูญเสียข้อมูลช่วยให้สามารถสร้างข้อมูลต้นฉบับออกมาได้พอดี — จำเป็นสำหรับข้อความ โปรแกรม และ ZIP/PNG
จับคู่แนวคิดการบีบอัดแต่ละอย่างกับความหมาย
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
การบีบอัดแบบไร้การสูญเสียรักษาทุกบิต (จำเป็นสำหรับข้อความ/โค้ด); แบบมีการสูญเสียแลกเปลี่ยนคุณภาพเพื่อขนาด (สำหรับภาพ/เสียง)
การบีบอัดแบบไร้การสูญเสียสร้างข้อมูลต้นฉบับออกมาได้สมบูรณ์ (จำเป็นสำหรับข้อความและโปรแกรม) ในขณะที่แบบมีการสูญเสียกำจัดข้อมูลบางอย่างออกถาวรเพื่อลดขนาดไฟล์ (ใช้กับภาพและเสียง)
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
นั่นเป็นเหตุผลว่าทำไมโปรแกรมหรือ ZIP ต้องเป็นการบีบอัดที่ไม่สูญเสียข้อมูล แต่ภาพถ่ายหรือเพลงสามารถใช้การบีบอัดแบบสูญเสียข้อมูลได้
ตัวอย่างวิธีทำ: ให้เหตุผลในการเลือก
- บริษัทจัดเก็บสเปรดชีตบัญชี Which kind of compression, and why? Lossless, เพราะสเปรดชีตต้องถูก restore กลับมาได้อย่างถูกต้อง; การเปลี่ยนค่าเพียงค่าเดียวจะทำให้บัญชีผิดเพี้ยน
- A photographer uploads holiday photographs to a phone gallery. Lossy, because the photographs are viewed on a small screen where the dropped detail is not visible, and the smaller files upload faster and use less storage.
- ชื่อประเภท แล้วให้เหตุผล จากสถานการณ์ "Lossy is smaller" เพียงอย่างเดียวไม่ใช่เหตุผลที่ยอมรับได้
ไฟล์ใดควรบีบอัดโดยไม่สูญเสียข้อมูล?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
โค้ดแหล่งกำเนิดต้องกู้คืนได้พอดี — ตัวอักษรเปลี่ยนเพียงตัวเดียวก็อาจทำให้มันพังได้ — ดังนั้นจึงต้องการการบีบอัดที่ไม่สูญเสียข้อมูล
Run-length encoding
- Run-length encoding (RLE) แทนที่ run ของค่าซ้ำกันด้วยค่าหนึ่งและ count: แทนที่จะเก็บ 8 white pixels เดียวกัน เก็บ "8, white"
- มีประสิทธิภาพสูงกับข้อมูลที่มี run ยาว เช่น icons, diagrams, scans ขาวดำ และพื้นที่สีแบน
- ใช้ไม่ได้ และอาจทำให้ไฟล์ ใหญ่ขึ้น กับ noisy data เช่น Photographs, ที่เกือบไม่มีค่าเพื่อนข้างกันเท่ากันเลย

แต่ละแถวกลายเป็นจำนวนนับและสี
Run-length encoding ทำงานได้ดีที่สุดกับข้อมูลที่มี:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
RLE แทนชุดค่าซ้ำซ้อนด้วยจำนวนนับ + ค่า ดังนั้นมันจึงโดดเด่นในพื้นที่เรียบและไร้ประโยชน์กับข้อมูลที่มีสัญญาณรบกวน
Worked example: encode a row with RLE
- แถวหนึ่งของภาพขาวดำขนาด 8 พิกเซลอ่านได้ดังนี้: ขาว ขาว ขาว ดำ ดำ ขาว ขาว ขาว.编码ด้วย RLE.
- ขาวสามตัว, ดำสองตัว, ขาวสามตัว, ดังนั้นคือ
3W 2B 3W, หรือเป็นคู่ๆ คือ(3, 0) (2, 1) (3, 0)ถ้าขาวคือ 0. - ค่าแปดค่ากลายเป็นสามคู่ ตอนนี้ให้เข้ารหัส
W B W B W B W BEight runs of one:1W 1B 1W 1B 1W 1B 1W 1B, ซึ่งจัดเก็บ มากกว่า ข้อมูลต้นฉบับ นั่นคือเหตุผลที่ RLE ไม่ถูกนำไปใช้กับภาพถ่าย
Run-length encoding (วิธีที่ไม่สูญเสียข้อมูล)
Run-length encoding แทนชุดค่าซ้ำซ้อนด้วยค่าหนึ่งบวกกับจำนวนนับ เป็นวิธีที่ไม่สูญเสียข้อมูล — สามารถสร้างข้อมูลต้นฉบับออกมาได้อย่างสมบูรณ์ — แต่จะลดขนาดข้อมูลที่มีชุดซ้ำยาวเท่านั้น
เข้ารหัสแถวพิกเซล W W W B B W W W ด้วย run-length encoding โดยใช้รูปแบบ 3W 2B 3W
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
สามขาว สองดำ สามขาว สแปดค่ากลายเป็นสามคู่ แต่ถ้าเป็นแถวสลับสีจะเป็นแปดคู่และขยายขนาด
Run-length encoding จะทำให้ไฟล์เล็กลงเสมอ
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
บนข้อมูลที่ไม่มีชุดซ้ำ เช่น ภาพถ่ายหรือแพทเทิร์นสลับกัน ทุกชุดมีความยาวเป็นหนึ่งและการเข้ารหัสจะเก็บมากกว่าต้นฉบับ
Dictionary coding and Huffman coding
- Dictionary coding, ใช้โดย ZIP และ PNG, สร้าง dictionary ของ byte sequences ที่ซ้ำแล้วแทนที่ทุก occurrence ด้วย index สั้น เหมาะกับ text และ program code, ที่ words และ patterns ซ้ำกัน
- การเข้ารหัส Huffman ให้ รหัสสั้นกับสัญลักษณ์ที่พบบ่อย และรหัสดำกับสัญลักษณ์ที่พบน้อย ทำให้อัตราเฉลี่ยของรหัสลดลง ในคำว่า "BANANA" A พบบ่อยที่สุดและได้รับรหัสสั้นที่สุด
- ทั้งสองเป็น lossless: decoder rebuilds ต้นฉบับ byte ต่อ byte
การเข้ารหัสฮัฟแมนลดขนาดข้อมูลโดย:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
Huffman assign รหัสที่สั้นที่สุดให้กับสัญลักษณ์ที่พบบ่อยที่สุด ลดความยาวรหัสเฉลี่ย
จับคู่วิธีการบีบอัดแบบไม่สูญเสียข้อมูลแต่ละชนิดเข้ากับหลักการทำงาน
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ทั้งสามวิธีเป็นแบบไม่สูญเสียข้อมูล: ตัวถอดรหัสจะสร้างกลับเป็นไบต์เดิมทั้งหมด
Lossy methods
- Images (JPEG): detail เล็กน้อยและความแตกต่างของสีที่ตาแทบจะไม่สังเกตเห็นจะถูก drop
- เสียง (MP3, AAC): ตี้นิយวาทที่หูเราจับได้ยากถูกลบออกพร้อมกับเสียงเบาที่ถูกปิดบังโดยเสียงดังในขณะเดียวกัน
- Video: spatial compression ทำงานภายในแต่ละ frame, เหมือน JPEG, และ temporal compression เก็บส่วนใหญ่ frames เป็นเพียง differences จาก frame ก่อนหน้า, เนื่องจาก consecutive frames เกือบจะเหมือนกัน

การบีบอัดตามเวลาของวิดีโอทำงานโดย:
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
การบีบอัดตามเวลาระบุว่าแต่ละเฟรมแตกต่างจากเฟรมก่อนหน้าอย่างไร เนื่องจากภาพส่วนใหญ่คงที่ระหว่างเฟรม (การบีบอัดตามพื้นที่จัดการรายละเอียดภายในเฟรม)
Worked example: how each kind of file is compressed
- Text file: dictionary และ Huffman coding เปลี่ยนคำซ้ำและตัวอักษรที่พบบ่อยเป็น short codes. ต้องคง lossless ไว้, เพราะการเปลี่ยน character หนึ่งตัวเปลี่ยนความหมาย
- Bitmap image: RLE สำหรับ runs ของ identical pixels ใน icons และ diagrams; lossy JPEG สำหรับ photographs; หรือลด colour depth หรือ resolution, ซึ่งเป็น lossy เช่นกัน
- Vector graphic: drawing list มีขนาดเล็กอยู่แล้ว. ลบ drawing objects ที่ไม่จำเป็นออก, เก็บ coordinates เป็นทศนิยมน้อยลง, หรือใช้วิธี lossless เช่น ZIP กับไฟล์
- Sound file: lossy MP3 หรือ AAC removesสิ่งที่หูฟังไม่ได้; ลด sampling rate หรือ resolution ก็เป็น lossy; formats lossless เก็บทุก sample และหดขนาดได้น้อยกว่ามาก
ไฟล์กราฟิกเวกเตอร์สามารถทำให้เล็กลงได้อย่างไร? เลือก ทุก ข้อที่ถูกต้อง
ความยาก 2/5 · 140 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
ไฟล์เวกเตอร์คือรายการวาด ไม่ใช่พิกเซล จึงไม่มีค่าความลึกสี ความลึกสีเป็นของคุณสมบัติของภาพbitmap
Why streaming must be lossy
- วิดีโอ HD/raw มีขนาดกิกะไบต์ต่อนาที และอินเทอร์เน็ตบ้านรองรับเพียงไม่กี่เมกะบิตต่อวินาที
- Lossless compression กับ video อาจ achieves factor ของสอง, ห่างไกลจากพอ,ดังนั้นpicture จะหยุด buffering ต่อเนื่อง
- Lossy compression achieves a factor of a hundred or more by discarding detail the viewer does not notice at normal speed. The reason names the bandwidth and the data rate, not just "it is smaller".
ทำไมการสตรีมวิดีโอแบบเรียลไทม์จึงใช้การบีบอัดแบบสูญเสียข้อมูล?
ความยาก 1/5 · 100 เหรียญ + บอนัสน้อยๆ เมื่อทำสำเร็จครั้งแรกในวันนี้
วิดีโอ HD แบบดิบมีขนาดเป็นกิกะไบต์ต่อนาที การบีบอัดแบบสูญเสียข้อมูลเพียงอย่างเดียวจึงสามารถลดขนาดให้พอสำหรับการสตรีมแบบเรียลไทม์โดยไม่สะดุด
คะแนนที่หลุดหายไป
- Lossless แปลว่า recover ต้นฉบับได้ ครบถ้วน; lossy แปลว่า ไม่สามารถ. "Lossy loses quality" ลืมไปว่าข้อมูลหายไปถาวร
- RLE สามารถทำให้ noisy file ใหญ่ขึ้น. บอกว่าทำงานได้ดีที่ไหนและไม่ดีที่ไหน
- Video compression เป็น spatial และ temporal; temporal เก็บ differences ระหว่าง frames
- คำตอบ "justify" เชื่อมต่อ method เข้ากับการใช้งาน: ความแม่นยำสำหรับบัญชีและ medical images, ขนาดสำหรับ streaming และ phone galleries
คุณเข้าใจแล้ว
- compression ประหยัด storage และ bandwidth; lossless recover ต้นฉบับได้ครบถ้วน, lossy ลบข้อมูลออกไปอย่างถาวร
- lossless methods: RLE (value และ count, ดีกับ runs, แย่กับ noise), dictionary coding (repeated sequences เป็น short indices), Huffman coding (short codes สำหรับ common symbols)
- lossy methods drop สิ่งที่ตาหรือหูพลาด; video เพิ่ม spatial ภายใน frame และ temporal ระหว่าง frames
- justify จากการใช้งาน: exact data แปลว่า lossless, limited bandwidth สำหรับ streaming แปลว่า lossy
เกิดปัญหาอะไรขึ้น? เฉพาะทีมเว็บไซต์เท่านั้นที่เห็นข้อมูลนี้