2013-02-10 53 views
2

我想弄清楚如何創建一個直方圖數組來比較matlab中圖像梯度向量的大小和方向。我是用索貝爾口罩,以找到梯度,所以到目前爲止,我有:matlab中的漸變直方圖

sobel_x = [-1 -2 -1;0 0 0;1 2 1]; 
sobel_y = [-1 0 1;-2 0 2;-1 0 1]; 

gx = filter2(sobel_x,im,'same'); 
gy = filter2(sobel_y,im,'same'); 

現在我需要弄清楚如何創建直方圖將它與其他圖像進行比較。

+0

您是否在此問一個問題? – ChiefTwoPencils 2013-02-10 06:07:29

回答

5

你可以把計算GXGY矩陣和長向量,然後將它們分組把他們當作成是大小的梯度向量:2×(在GXGY元件的#號)

% create the gradient vectors 
    grad_vector(1,:) = gx(:); 
    grad_vector(2,:) = gy(:); 

然後就可以找到每個梯度向量的大小和方向以多種方式,例如:

%find magnitude and direction of each gradient vector 
    for i=1:size(grad_vector,2); 
     magn(i) = norm(grad_vector(:,i)); 
     dir(i) = atand(grad_vector(2,i)/grad_vector(1,i)); 
    end 

然後可以通過決定如何將結果劃分爲多個分箱來創建直方圖。例如,您可以選擇將方向分爲4個分檔,並將大小分爲3個,然後:

% find histograms, dividing into appropriate bins 
    histdir = hist(dir,4); 
    histmag = hist(magn,3);