2014-12-24 29 views
0

我已經寫了蛇的掃描順序,但我不知道它是對還是錯! 我首先將256 * 256矩陣轉換爲8 * 8矩陣,然後在這些小矩陣中進行蛇形掃描排序。 可能你請告訴我如何顯示結果向量?Snake Scan Ordering

pic=rgb2gray(pic1); 
pic=uint8(pic); 
C = mat2cell(pic,[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 ],[8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8 8]); 
celldisp(C); 
% % % % % Converting the cell arrays to vectors in snake scan ordering form % % % % 
X=[]; 
n=0; 
for i=1:32; 
for j=1:32; 

    n=n+1; 
    C{i,j}=C{i,j}'; 
    Vn= reshape(C{i,j},1,[]); 
    Vn(5:8)=fliplr (Vn(5:8)); 
    Vn(13:16)=fliplr (Vn(13:16)); 
    X=[X Vn]; 
end 
end 
+1

Snake掃描實現起來非常簡單 - 您只需切換每一行的方向 - 首先嚐試一下,然後在遇到困難時再回來尋求幫助。 –

+0

好的謝謝。 「你只是替換每一行的方向」是什麼意思? – pic

+0

你知道蛇的掃描是如何工作的嗎?對於第一行,你從1迭代到n,第二行從n迭代到1,等等...... –

回答

1

對於一個矩陣M的蛇掃描排序:

M = M.'; %'// matlab works column major - so we first transform the matrix 
M(:, 2:2:end) = M(end:-1:1, 2:2:end); %// filp up-down every second column 
snake = M(:).'; %'// convert to a single vector. 

你可以看到here它是如何工作的。