像素化(又稱馬賽克)是一種常見的打碼方式,通過降低圖像中部分區域的解析度來隱藏某些關鍵信息,比如:
python depix.py -p [pixelated rectangle image] -s [search sequence image] -o output.pngDepix 算法利用線性方框濾波器單獨處理每一個 block 這一事實。它對搜索圖像中的每一個 block 執行像素化以尋找直接匹配。對於大部分像素化圖像,Depix 儘量尋找單匹配結果,並假設這些匹配是正確的。至於周圍多匹配 block 的結果被看作像素化圖像中相同的幾何距離,並認為這些匹配也是正確的。該過程重複多次。在正確的 block 沒有更多幾何匹配後,Depix 將直接輸出所有正確的 block。對於多匹配 block,Depix 將輸出所有匹配的平均值。像素化常使用線性方框濾波器實現。線性方框濾波器的實現很簡單,速度很快,可以並行處理多個 block。項目作者給出的解決方案也很簡單:使用待處理字符的德布魯因序列,將其粘貼到相同的編輯器中,然後截圖。該截圖可以用作相似 block 的查找圖像,例如:德布魯因序列包括待處理字符的所有雙字符組合。這很重要,因為一些 block 會重疊兩個字符。找出恰當的匹配需要搜索圖像中具備相同像素配置的 block。在以下測試圖像中,Depix 算法無法找到「o」的一部分。這是因為在搜索圖像中,搜索 block 還包含下一個字母(「d」)的一部分,但在原始圖像中這裡有個空格。創建字母的德布魯因序列時加上空格顯然會帶來同樣的問題:算法無法找到後續字母的恰當 block。有空格又有字母的圖像需要更長的搜索時間,但結果也更好。在正確的 block 沒有更多幾何匹配後,Depix 直接輸出所有正確的 block。對於多匹配 block,Depix 將輸出所有匹配的平均值。雖然 Depix 的輸出並不完美,但已經算不錯了。下圖展示了包含隨機字符的測試圖像的去像素化結果,大部分字符被正確讀取:過程為本人第一視角,漏掉的部分請自行探索。
下載源碼,cd到根目錄,執行文檔(README.d)中的Example代碼。到這裡,目前還不明白這行代碼的意思,不過可以看到兩個圖片路徑,都在示例代碼中出現,最後一個看名字就知道,工程根目錄輸出一個output.png圖片。猜測為執行depix.py腳本,後面為『參數』和輸出結果。(這裡默認已安裝python工具,可以執行python命令)
python depix.py -p images/testimages/testimage3_pixels.png -s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png -o output.png
執行代碼後報錯
Traceback (most recent call last):
File 「depix.py」, line 1, in
from depixlib.LoadedImage import *
File 「/Users/bit_tea/Downloads/Depix-main/depixlib/LoadedImage.py」, line 1, in
from PIL import Image
ImportError: No module named PIL百度。。。,結果意思是需要安裝pillow命令。
安裝pillow
pip install pillow
報錯,沒安裝pip…
安裝pip
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py提示:
WARNING: The scripts pip, pip2 and pip2.7 are installed in 『/Users/bit_tea/Library/Python/2.7/bin』 which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.此問題需解決。。
python3 get-pip.py
Successfully installed pip-20.3.1
WARNING: You are using pip version 19.2.3; however, version 20.3.1 is available.
You should consider upgrading via the '/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip' command.執行提示命令
/Applications/Xcode.app/Contents/Developer/usr/bin/python3 -m pip install --upgrade pip
至此,pip3安裝成功。
回頭執行第2步,安裝pillow(注意:用pip3)
pip3 install pillow
回頭執行第1步(注意:用python3)
python3 depix.py -p images/testimages/testimage3_pixels.png -s images/searchimages/debruinseq_notepad_Windows10_closeAndSpaced.png -o output.png
稍作等待,最後一句完成,可以看到工程目錄下多了一個output.png文件,大功告成~
INFO:root:Finding color rectangles from pixelated space
INFO:root:Found 116 same color rectangles
INFO:root:86 rectangles left after moot filter
INFO:root:Found 1 different rectangle sizes
INFO:root:Finding matches in search image
INFO:root:Removing blocks with no matches
INFO:root:Splitting single matches and multiple matches
INFO:root:[10 straight matches | 76 multiple matches]
INFO:root:Trying geometrical matches on single-match squares
INFO:root:[15 straight matches | 71 multiple matches]
INFO:root:Trying another pass on geometrical matches
INFO:root:[17 straight matches | 69 multiple matches]
INFO:root:Writing single match results to output
INFO:root:Writing average results for multiple matches to output
INFO:root:Saving output image to: output.png結語:通過觀察輸入和輸入,發現輸入除了一個馬賽克圖片外,還需要一張對比(或者是預測結果參數)的圖片,有很大的局限性(lsp哭了),之後再看看是不是除了示例還有其他功能。。。
細心的同學應該發現第3步還有一個問題沒有解決。。。雖然pip3可以用,pip還是不行。
pip
-bash: pip: command not found原因:(第3步有提示)pip沒有添加到path環境裡,所以在非其安裝路徑下是不可以執行pip相關命令。
WARNING: The scripts pip, pip2 and pip2.7 are installed in 『/Users/bit_tea/Library/Python/2.7/bin』 which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.解決:(PATH路徑為以上第3步提示的路徑,及默認安裝到python2.7中的pip路徑)。
echo 'export PATH=/Users/bit_tea/Library/Python/2.7/bin:$PATH' >>~/.bashrc
source ~/.bashrc驗證
pip
Usage:
pip <command> [options]完成~
參考文章:
以後截圖時給敏感信息打碼,看來不能簡單地用「馬賽克了」。
https://blog.csdn.net/weixin_44037416/article/details/96842058
https://www.jianshu.com/p/96bfccc7c680https://www.linkedin.com/pulse/recovering-passwords-from-pixelized-screenshots-sipke-mellema/?trackingId=yYFSUnuxRXasNV%2Fh3ZsiSw%3D%3D
小福利:
1.關注公眾號,回復「群」後臺自動返回群二維碼進本碩博交流討論群,有985211專屬群&考研群&校招信息分享群;
2.公眾號左下角頁面按鈕,可免費下載99.9%的學術論文;
3.200G網際網路,考研,國考,教師資格證資料,最新在線電影等歡迎你來領