圖像GIST特征和LMGIST包的python實現(有github)


1什么是Gist特征

       (1) 一種宏觀意義的場景特征描述
       (2) 只識別“大街上有一些行人”這個場景,無需知道圖像中在那些位置有多少人,或者有其他什么對象。
       (3) Gist特征向量可以一定程度表征這種宏觀場景特征
GIST定義下列五種對空間包絡的描述方法

空間包絡名 闡釋
自然度(Degree of Naturalness) 場景如果包含高度的水平和垂直線,這表明該場景有明顯的人工痕跡,通常自然景象具有紋理區域和起伏的輪廓。所以,邊緣具有高度垂直於水平傾向的自然度低,反之自然度高。
開放度(Degree of Openness) 空間包絡是否是封閉(或圍繞)的。封閉的,例如:森林、山、城市中心。或者是廣闊的,開放的,例如:海岸、高速公路。
粗糙度(Degree of Roughness) 主要指主要構成成分的顆粒大小。這取決於每個空間中元素的尺寸,他們構建更加復雜的元素的可能性,以及構建的元素之間的結構關系等等。粗糙度與場景的分形維度有關,所以可以叫復雜度。
膨脹度(Degree of Expansion) 平行線收斂,給出了空間梯度的深度特點。例如平面視圖中的建築物,具有低膨脹度。相反,非常長的街道則具有高膨脹度。
險峻度(Degree of Ruggedness) 即相對於水平線的偏移。(例如,平坦的水平地面上的山地景觀與陡峭的地面)。險峻的環境下在圖片中生產傾斜的輪廓,並隱藏了地平線線。大多數的人造環境建立了平坦地面。因此,險峻的環境大多是自然的。

2 Gist的實現--LMgist

% 讀取圖片
img = imread('demo2.jpg');

% 設置GIST參數
clear param
param.orientationsPerScale = [8 8 8 8]; % number of orientations per scale (from HF to LF)
param.numberBlocks = 4;
param.fc_prefilt = 4;

% 計算GIST
[gist, param] = LMgist(img, '', param);

3 LMgist原理

3.1 LMgist算法主流程

  • G1:對輸入圖片進行預處理 (RGB或RGBA轉128x128灰度圖)
  • G2:對輸入圖片進行Prefilt處理
  • G3:計算圖片的Gist向量

3.2 G2 對輸入圖片進行Prefilt處理

3.2.1 Pad images to reduce boundary artifacts (擴邊+去偽影)

\[{\bf{matlog}} = \log \left( {{\bf{mat}} + 1} \right) \]

\[{\bf{matPad}} = {\mathop{\rm sympading}\nolimits} \left( {{\bf{matlog}},\left[ {5,5,5,5} \right]} \right) \]


圖1 sympading操作

3.2.2 Filter (構造濾波器)



\[{\bf{matGf}} = {\mathop{\rm FFTSHITF}\nolimits} \left( {\exp \left( { - \frac{{{\bf{matF}}{{\bf{x}}^2} + {\bf{matF}}{{\bf{y}}^2}}}{{{{\left( {\frac{{fc}}{{\sqrt {\log \left( 2 \right)} }}} \right)}^2}}}} \right)} \right) \]

3.2.3 Whitening (白化)

\[{\bf{matRes}} = {\bf{matPad}} - {\mathop{\rm Real}\nolimits} \left( {{\mathop{\rm IFFT}\nolimits} \left( {{\mathop{\rm FFT}\nolimits} \left( {{\bf{matPad}}} \right){\bf{matGf}}} \right)} \right) \]

3.2.4 Local contrast normalization (局部對比度歸一化)

\[{\bf{matLocal}} = \sqrt {\left| {{\mathop{\rm IFFT}\nolimits} \left( {{\mathop{\rm FFT}\nolimits} \left( {{\bf{matRes}} \cdot {\bf{matRes}}} \right) \cdot {\bf{matGf}}} \right)} \right|} \]

\[{\bf{matRes}} = \frac{{{\bf{matRes}}}}{{0.2 + {\bf{matLocal}}}} \]

3.2.5 Local contrast normalization (局部對比度歸一化)

\[{\bf{matPrefilt = matRes}}\left[ {5:64 + 5,5:64 + 5} \right] \]

3.3 計算圖片的Gist向量

3.3.1 Pading

\[{\bf{matPad}} = {\mathop{\rm sympading}\nolimits} \left( {{\bf{matPrefilt}},\left[ {32,32,32,32} \right]} \right) \]

3.3.2 FFT

\[{\bf{matLocal}} = {\mathop{\rm FFT}\nolimits} \left( {{\bf{matPad}}} \right) \]

3.3.3 遍歷每個Gabor核函數



圖2 全局Gist特征的提取

4 LMgist的Python實現

GitHub代碼 https://github.com/Kalafinaian/python-img_gist_feature

4.1 提取Gist特征

import cv2
from img_gist_feature.utils_gist import *

s_img_url = "./test/A.jpg"
gist_helper = GistUtils()

np_img = cv2.imread(s_img_url, -1)

print("default: rgb")
np_gist = gist_helper.get_gist_vec(np_img)
print("shape ", np_gist.shape)
print("noly show 10dim", np_gist[0,:10], "...")
print()

print("convert rgb image")
np_gist = gist_helper.get_gist_vec(np_img, mode="rgb")
print("shape ", np_gist.shape)
print("noly show 10dim", np_gist[0,:10], "...")
print()

print("convert gray image")
np_gist = gist_helper.get_gist_vec(np_img, mode="gray")
print("shape ", np_gist.shape)
print("noly show 10dim", np_gist[0,:10], "...")
print()

運行得到的gist特征為
default: rgb
shape (1, 1536)
noly show 10dim [0.02520592 0.05272802 0.05941689 0.05476999 0.13110509 0.13333975
0.29072759 0.16522023 0.25032277 0.36850457] ...

convert rgb image
shape (1, 1536)
noly show 10dim [0.02520592 0.05272802 0.05941689 0.05476999 0.13110509 0.13333975
0.29072759 0.16522023 0.25032277 0.36850457] ...

convert gray image
shape (1, 512)
noly show 10dim [0.10004389 0.20628179 0.17682694 0.16277722 0.10557428 0.14448622
0.29214159 0.11260066 0.16488087 0.28381876] ...

4.2 Gist特征余弦相似距離

下載好github中的代碼項目,運行python _test_get_cossim.py


5 LMgist的效果


參考資料

  1. GIST特征描述符使用
  2. GIST 空間包絡特征 推薦論文 簡介


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM