s1093522 作業 6
作業說明 Run-Length Based Image Compression 練習 附件中為三張利用將晶片高度以色彩視覺化後的圖片。 請設計一個基於 Run-Length 的壓縮法方,對圖檔作無失真壓縮後儲存成新檔案。 部落格上應敘述你的壓縮方法,提供壓縮檔之格式,並計算三張圖的平均壓縮率 (compression ratio)。 開發環境 Windows 11 21H2 Visual Studio 2019 16.11.24 OpenCV 4.5.1 程式說明 RLE_encode(const Mat& src) 遍歷圖像的每個像素,並計算連續相同像素值的個數。用來代表連續的像素序列。 compress_image(const Mat& src, const string& compressed_filename) 將圖像分成 RGB 三個通道,並對每個通道進行獨立的 Run-Length 編碼,並將編碼後的數據寫入到壓縮文件(txt檔案)中 cal_compression_ratio(const Mat& src, const string& filename, const string& compressed_filename) 比較壓縮後數據的大小與原始圖像的大小計算壓縮率 執行結果 原始 bmp 檔和壓縮後的 txt 檔大小比較 平均壓縮率: 18.04%