www.pudn.com > Blackfin_Mpeg_2_4.zip > test.m
%Desired SA Transform
%data =
% 0 0 0 0 0 0 0 0
% 0 0 0 0 0 0 0 0
% 0 0 0 0 0 0 0 0
% 0 0 0 0 0 0 0 0
% 0 0 0 28 24 20 16 12
% 0 0 0 35 0 0 20 15
% 0 0 0 42 36 30 24 18
% 0 0 0 49 42 35 28 21
%
%F =
%
% 117.1541 32.0013 5.1371 7.4007 -0.1093
% -24.4003 -6.7814 -0.4730 -1.0272 0.0101
% -2.0083 -0.9106 1.7697 1.4734 -0.0377
% -1.2812 -0.4483 -0.1294 0 0
%******************************************************
clear
img=zeros(128);
img(30:50,30:50)=ones(21).*255;
shape_img=edge(img);
data=img(27:34,29:36);
shape=shape_img(27:34,29:36);
%*********************************************************
%To extract the Alpha Map from the edge image
shape1=zeros(8);
for i=1:8
flag=0;
for j=1:8
if(flag == 1 & shape(i,j) == 1) flag=0; end;
if(shape(i,j) == 1) flag=1;end;
if(flag == 1) shape1(i,j)=255; end;
end
end
shape1(4,3:5)=zeros(1,3);
shape1(5,3:4)=zeros(1,2);
shape1(7,5:6)=zeros(1,2);
shape1(6:7,6)=zeros(2,1);
for i=1:8
for j=1:8
if(shape1(i,j)==0) data(i,j)=0;end;
end
end
%**********************
for i=1:8
for j=1:8
% if((i>4) & (j>3))
if((i+j) > 8)
shape1(i,j)=255;
% data(i,j)=(i-1)*(10-(j-1));
data(i,j)=(i+1-1)*(30-j+1);
else
shape1(i,j)=0;
data(i,j)=0;
end
end
end
%data(6,5:6)=zeros(1,2);
%shape1(6,5:6)=zeros(1,2);
%*********************************************************
%***********Coloumn Alignment*************************
shift_shape=zeros(8);
for i=1:8
pels_count=1;
for j=1:8
if(shape1(j,i)==255)
shift_texture(pels_count,i)=data(j,i);
shift_shape(pels_count,i)=255;
pels_count=pels_count+1;
end
end
pels_height(i)=pels_count-1;
end
%***********Coloumn SADCT*************************
for i=1:8
if(pels_height(i)~=0)
F_intermediate(1:pels_height(i),i)=sacos(pels_height(i))* ...
shift_texture(1:pels_height(i),i);
end
end
pause
%***************Row Alignment*************************
for i=1:8
coeff_count=1;
for j=1:8
if(shift_shape(i,j)==255)
shift_intermediate(i,coeff_count)=F_intermediate(i,j);
coeff_count=coeff_count+1;
end
end
coeff_width(i)=coeff_count-1;
end
%****************Row SADCT*************************
for i=1:8
if(coeff_width(i)~=0)
F(i,1:coeff_width(i))= (sacos(coeff_width(i))* ...
shift_intermediate(i,1:coeff_width(i))')';
end
end
pause
%*************************************************************************
%Reconstruction
%*************************************************************************
shift_shape=zeros(8);
for i=1:8
pels_count=1;
for j=1:8
if(shape1(j,i)==255)
shift_shape(pels_count,i)=255;
pels_count=pels_count+1;
end
end
pels_height(i)=pels_count-1;
end
for i=1:8
coeff_count=0;
for j=1:8
if(shift_shape(i,j)==255)
coeff_count=coeff_count+1;
end
end
coeff_width(i)=coeff_count;
end
%*****************************************************************************
%1D Row I-SADCT
%*****************************************************************************
for i=1:8
if(coeff_width~=0)
shift_intermediate(i,1:coeff_width(i))=(sacos(coeff_width(i))'* ...
F(i,1:coeff_width(i))')';
end
end
%********************************************************************************
%Row Shift
%*******************************************************************************
for i=1:8
coeff_count=1;
for j=1:8
if(shift_shape(i,j)==255)
F_intermediate(i,j)=shift_intermediate(i,coeff_count);
coeff_count=coeff_count+1;
end
end
end
%*****************************************************************************
%1D Coloumn I-SADCT
%*****************************************************************************
for i=1:8
if(pels_height(i)~=0)
shift_texture(1:pels_height(i),i)=sacos(pels_height(i))'* ...
F_intermediate(1:pels_height(i),i);
end
end
%********************************************************************************
%Coloumn Shift
%*******************************************************************************
f=zeros(8);
for i=1:8
pels_count=1;
for j=1:8
if(shape1(j,i)==255)
f(j,i)=shift_texture(pels_count,i);
pels_count=pels_count+1;
end
end
end
norm(f-data)
f;
data;