1

我有一个图像,例如矩阵 A;

A = [156 159 158 155 158 156 159 158 157 158;

160 154 157 158 157 159 158 158 158 160;

156 159 158 155 158 156 159 158 157 158;

160 154 157 158 157 159 158 158 158 160;

156 153 155 159 159 155 156 155 155 157;

155 155 155 157 156 159 152 158 156 158;

156 153 157 156 153 155 154 155 157 156;

159 159 156 158 156 159 157 161 162 157;

158 155 158 154 156 160 162 155 159 161;

155 154 157 158 160 160 159 160 158 161]

要获得 RSAT(x,y) 的像素值,RSAT(x,y) = RSAT(x-1,y-1) + RSAT(x-1,y+1) - RSAT(x-2,y) + I(x-1,y)+ I(x,y); 我是原始图像(矩阵A)。

矩阵 B(计算 RSAT 后):

[0 0 0 0 0 0 0 0 0 0 0;

0 156 159 158 155 158 156 159 158 157 158;

156 475 627 629 629 626 632 631 632 631 475;

475 943 1258 1413 1413 1418 1416 1422 1420 1265 949;

943 1574 2042 2357 2515 2518 2523 2522 2371 2053 1583;

1574 2358 2980 3456 3779 3936 3938 3786 3468 3002 2370;

2358 3291 4080 4712 5193 5514 5513 5192 4730 4096 3317;

3291 4391 5331 6129 6760 7079 7082 6763 6133 5358 4410;

4391 5646 6752 7692 8329 8637 8643 8334 7707 6766 5671;

5646 7069 8321 9266 9881 10205 10208 9906 9283 8341 7084;

7069 8634 9892 10825 11454 11768 11788 11478 10855 9918 8663]

矩阵 A = 2041 处区域(粗体区域)的总和。但是,矩阵 B 处的区域总和(粗体区域 )= 1880。作为积分图像理论,它假设返回与矩阵 A 相同的值,2041。

这是我的代码(matlab)

请帮助我。谢谢你。

I= [156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 159 158 155 158 156 159 158 157 158;
160 154 157 158 157 159 158 158 158 160;
156 153 155 159 159 155 156 155 155 157;
155 155 155 157 156 159 152 158 156 158;
156 153 157 156 153 155 154 155 157 156;
159 159 156 158 156 159 157 161 162 157;
158 155 158 154 156 160 162 155 159 161;
155 154 157 158 160 160 159 160 158 161];

Dummy_Ori_Img =padarray(I,[1 1],'pre') ;
Dummy_Ori_Img2 =padarray(Dummy_Ori_Img,[0 1],'replicate','post') ;

%calculate RSAT
RSAT = zeros(size(Dummy_Ori_Img2));
[Height_Dummy,Width_Dummy]=size (Dummy_Ori_Img2);
for x =1:Height_Dummy
for  y = 1:Width_Dummy
    if x-2<=0 || (x-2)>Height_Dummy || y>=Width_Dummy ||y==1
        RSAT1=0;
    else
        RSAT1= RSAT(x-2,y);
    end
    if x-1<=0 || y-1<=0 || (x-1)>Height_Dummy || (y-1)>Width_Dummy
        RSAT2=0;
    else
        RSAT2=RSAT(x-1,y-1);
    end
    if x-1<=0 ||  (x-1)>Height_Dummy || (y+1)>Width_Dummy 
        RSAT3=0;
    else
        RSAT3=RSAT(x-1,y+1);
    end 
    if x-1<=0 || y<=0 || x>Width_Dummy || y>Height_Dummy
        DOI1=0;
    else
        DOI1=Dummy_Ori_Img(x-1,y);
    end
    if x<=0 || y<=0 || x>Width_Dummy || y>Height_Dummy
        DOI2=0;
    else
        DOI2=Dummy_Ori_Img(x,y);
    end
    RSAT(x,y)= RSAT3 + RSAT2-RSAT1 + DOI2 + DOI1;
end
end
RSATnew  = RSAT (1:size(Dummy_Ori_Img,1),1: size(Dummy_Ori_Img,2)  );
outer_upright_kernel = ones (3,3);
TiltedKernel=ceil(imrotate(outer_upright_kernel,45,'bilinear','loose'));
[Height_tilt,Width_tilt]=size (TiltedKernel);
HalfTilt_x= floor(Width_tilt/2);
HalfTilt_y= floor(Height_tilt/2);
% calculate sum of region
xi=6;
yi=6;
fourpoints = [xi yi HalfTilt_x HalfTilt_y];
row_val=fourpoints(1,1);
col_val=fourpoints(1,2);
img_width=fourpoints(1,3);
img_length=fourpoints(1,4);
if row_val-1<=0 ||col_val-img_width<=0
    T1to = 0;
else
    T1to = RSATnew(row_val-1,col_val-img_width);
    TiltOuter1 = [row_val-1,col_val-img_width];
end
if row_val-1-img_length<=0 || col_val-1<=0
    T2to =  0;
else
    T2to = RSATnew(row_val-1-img_length,col_val);
    TiltOuter2 = [row_val-1-img_length,col_val];
end
if row_val + img_length<=0 ||col_val<=1
    T3to = 0;
else
    T3to = RSATnew(row_val + img_length,col_val);
    TiltOuter3 = [row_val + img_length,col_val];
end
if col_val+img_width+1 <=0
    T4to = 0;
else
    T4to = RSATnew(row_val,col_val+img_width+1);
    TiltOuter4 = [row_val,col_val+img_width+1];
end
TiltOuterSum = T2to + T3to - T1to - T4to;
4

1 回答 1

-1

基于 Lienhart(2002) ( http://www.multimedia-computing.de/mediawiki/images/5/52/MRL-TR-May02-revised-Dec02.pdf ),

RSAT (x,y)= RSAT(x-1,y-1) + RSAT(x+1,y-1) - RSAT(x,y-2) + I(x,y) + I(x, y-1)

对于您的矩阵,A

[156 159 158 155 158 156 159 158 157 158;

160 154 157 158 157 159 158 158 158 160;

156 159 158 155 158 156 159 158 157 158;

160 154 157 158 157 159 158 158 158 160;

156 153 155 159 159 155 156 155 155 157;

155 155 155 157 156 159 152 158 156 158;

156 153 157 156 153 155 154 155 157 156;

159 159 156 158 156 159 157 161 162 157;

158 155 158 154 156 160 162 155 159 161;

155 154 157 158 160 160 159 160 158 161]。

那么,矩阵 A 的 RSAT 应该是:

[156 159 158 155 158 156 159 158 157 158;

475 627 629 629 626 # 632 # 631 632 631 475;

787 1258 1413 1413 1418 1416 1422 1420 1265 791;

1099 1886 2357 2515 2518 2523 2522 2371 1895 1108;

1415 2505 # 3300 # 3779 3936 3938 3786 3310 # 2527 # 1421;

1717 3137 4237 5037 5514 5513 5034 4255 3147 1734;

2033 3757 5186 6285 6923 6924 6288 5184 3775 2040;

2355 4394 6118 7386 8004 # 8012 # 7385 6124 4396 2354;

2678 5030 6908 8149 8787 8784 8167 6913 5024 2674;

2988 5501 7376 8621 9245 9262 8633 7382 5508 2992]

区域的总和(矩阵 A 中的粗体区域 - 我根据论文进行了更改)为2817。基于 RSAT,应计算为8012 + 632 - 3300 - 2527 = 2817

于 2015-01-29T07:15:53.917 回答