📄 lsk_main_encode_chen_bak.m
字号:
function output = LSK_main_encode_chen(x, max_bits, block_size, level)
% Matlab implementation of SPECK
%
% Encoder
%
% input: x : input image in wavelet domain
% max_bits : maximum bits can be used
% block_size : image size
% level : wavelet decomposition level
%
% output: out : bit stream
%
% Initially read image and scan it in MORTON's scan order and use Linear Indexing
%function [] = encode256()
% Om Sai
% Listless SpecK LSk, Set I is not considered for the reasons mentioned in
% the paper
% Code started 24/11/2003
% To be presented in some conference
% Its a Original work, to the best of my knowledge
% The pointers used are
% MS2 - 1, MS4 - 2, MS8 - 3, MS16 - 4, MS32 - 5, MS64 - 6, MS128 - 7, MS256 - 8
% MIP - 0, MSP - 15, MNP - 14, NULL - 13
% Initially read image and scan it in MORTON's scan order and use Linear Indexing
% clear all,clc
clear global
clear mark
global mark
mark(1:block_size*block_size)=13; % Initialize to NULL, Here zero is not considered
map=mapping(block_size);
%x=imread('lena2.bmp');
%figure,imshow(mat2gray(x))
% mee=fix(mean(mean(x)));
% fopt=1;
% [mat r s]=analw2d(x-mee,fopt,4);
% mat=fix(mat);
% seqt(map)=mat;
% clear r s P fopt x mee mat map
seqt(map) = x;
% seqt = x;
output=[];
% Start Initialization
mn=0;
var=[];
mark = mark_gen(block_size,level);
% for ii=1:64
% mark(ii)=0; % MIP
% end
%
% mark(65)=3;mark(129)=3;mark(193)=3;
% mark(257)=4;mark(513)=4;mark(769)=4;
% mark(1025)=5;mark(2049)=5;mark(3073)=5;
% mark(4097)=6;mark(8193)=6;mark(12289)=6;%%%%%%%128*128
% mark(16385) = 7; mark(32769) = 7; mark(49153) = 7;%%256*256
%-----------------------------------------------------------
seqt = double(seqt);
n=fix(log2(max(abs(seqt))));
disp('The figure of n is ');disp(n);
n1=n;%n=8;%我加的=8,上面是注释掉的
while n>=0
ii=1;
% INSIGNIFICANT PIXEL PASS
% for ii=1:64
% if mark(ii)==0 % i.e., if MIP
% if 2^n<=abs(seqt(ii)) & abs(seqt(ii))<2^(n+1)
% output=[output '1'];mn=mn+1;var=[var seqt(ii)];
% mark(ii)=14; % Mark MNP, Newly significant
% if seqt(ii)<0
% output=[output '1']; % -ve
% else
% output=[output '0']; % +ve
% end
% else
% output=[output '0'];
% end
% end
% end
%
% ii=ii+1;
% INSIGNIFICANT SET PASS
while ii<=block_size*block_size
if mark(ii)==0 % i.e., if MIP
if 2^n<=abs(seqt(ii)) & abs(seqt(ii))<2^(n+1)
output=[output '1'];mn=mn+1;var=[var seqt(ii)];
mark(ii)=14; % Mark MNP, Newly significant
if seqt(ii)<0
output=[output '1']; % -ve
else
output=[output '0']; % +ve
end
else
output=[output '0'];
end
ii=ii+1;
elseif mark(ii)>0 & mark(ii)<9
% O/p significance of Marker
arr=seqt(ii:ii+2^(2*mark(ii))-1); % Check for block significance
arr=sum([2^n<=abs(arr) & abs(arr)<2^(n+1)]);
if arr==0
output=[output '0'];
ii=ii+2^(2*mark(ii));
else
output=[output '1'];
partition(ii);
end
arr=0;
else
ii=ii+1;
end
end
% REFINEMENT PASS
ii=1;
while ii<=block_size*block_size
if mark(ii)==15
a=dec2bin(abs(seqt(ii)),n1+1);
output=[output a(n1-n+1)];
ii=ii+1;
elseif mark(ii)==14
mark(ii)=15;
ii=ii+1;
else
ii=ii+2^(2*mark(ii));
end
end
% GOTO STEP 2
n=n-1;disp('n is');disp(n);
end
% [ mn length(find(abs(seqt)>=2^(n+1))) length(find(mark==15))]
save filename output
disp(' D O N E ')
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -