Modified Uniformly Redundant Array (MURA) Mask
Posted on Wed 21 February 2018 in Computational Imaging
MURA 常被應用於編碼,而 MURA mask 是一種利用 MURA sequence 生成的遮罩,因此首先介紹如何生成一維序列。MURA 序列是二元序列,可為任何的自定義長度\(L\),但是\(L\)必須為一質數,則一維的 MURA 加密序列\(A\)可以表示為:
$$A_i=\begin{cases} 0 & \text{ if } i=0 \\ 1 & \text{ if } i \text{ is a quadratic residue modulo } L \text{ and } i\neq 0 \\ 0 & \text{ otherwise } \end{cases}.$$
根據\(A\),則可以得到解碼序列\(G\):
$$G_i=\begin{cases} +1 & \text{ if } i=0 \\ +1 & \text{ if } A_i=1,i \neq 0 \\ -1 & \text{ if } A_i=0,i \neq 0 \\ \end{cases}.$$
長寬為\(p \times p\)的二維 MURA 編碼遮罩可以表示成\(\mathbf{A}= \{ A_{ij} \}\),其中:
$$A_{i_j}=\begin{cases} 0 & \text{ if } i=0 \\ 1 & \text{ if } j=0,i\neq 0 \\ 1 & \text{ if } C_i C_j=1 \\ 0 & \text{ otherwise } \end{cases} \text{ 當中 } C_i=\begin{cases} +1 & \text{ if } i \text{ is a quadratic residue modulo } p \\ -1 & \text{ otherwise } \end{cases}.$$
則二維的解碼遮罩\(\mathbf{G}\)一樣可以由\(\mathbf{A}\)求得:
$$G_{ij}=\begin{cases} +1 & \text{ if } i=0,j=0 \\ +1 & \text{ if } A_{ij}=1 \\ -1 & \text{ if } A_{ij}=0 \end{cases}.$$
上述的 quadratic residue 為二次剩餘,當存在某個\(x\),且\(x^2 \equiv q(\text{mod }n)\),則\(q\)是\(n\)的二次剩餘。由於長寬必須要為質數,因此可以用 Euler's criterion 來判斷一個整數是否為某質數的二次剩餘:
$$a^{\frac{p-1}{2}}\equiv \begin{cases} +1 (\text{mod } p) & \text{ if there is an integer x such that } a \equiv x^2(\text{mod }p) \\ -1 (\text{mod } p)& \text{ if there is no such integer} \end{cases}.$$
以下為二維 MURA 編碼遮罩的 MATLAB 範例:
function [ t ] = generateMURAs2D( p )
% Generate MURA mask
% Input: MURAs length p
% Output: MURA mask t
if isprime(p)
t=zeros(p,p);
[i,j]=ndgrid(1:p,1:p);
residuelist=unique( mod( (0:(abs(p)/2)).^2,p ) );
i_qrm=ismember(i-1,residuelist);
j_qrm=ismember(j-1,residuelist);
ij_AndNor=~xor(i_qrm,j_qrm);
t(ij_AndNor)=1;
t(1,:)=0;
t(2:end,1)=1;
else
fprintf('p is NOT a prime number.\n');
t=[];
end
end
如果輸入的質數為 59,則結果如下:
而其對應的解碼矩陣的 MATLAB 範例如下:
function [ t_hat ] = decodeMURAs2D( t )
%Generate decode MURAs mask
% Input: encoded mask A
% output: decoding mask G
t_hat = double(t==1);
t_hat = t_hat + double(t==0) * (-1);
t_hat(1,1) = 1;
end
Reference
- Optical Imaging and Spectroscopy. By David J. Brady
- 維基百科