from Listless SPECK (LSk) by Ravi Lakkundi
Listless Speck Codec

LSk_main_encode.m
% 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
global mark

mark(1:128*128)=13; % Initialize to NULL, Here zero is not considered

map=mapping(128);
% ####################
choice=3;
% ####################
if choice==1
    load lena.mat
    x=lena;
    x=x(80:80+127,70:70+127);
elseif choice==2
    load kitten
    x=kitten(50:50+127,50:50+127);
elseif choice==3
    load penny
    x=P;
elseif choice==4
    x=imread('barbara.tif');
    x=im2double(x);
    x=220*x./x(1);
    x=x(50:50+127,300:300+127);
elseif choice==5
    x=imread('baboon','tif');
    x=im2double(x);
    x=164*x./x(1);
    x=x(40:40+127,70:70+127);
elseif choice==6
    x=imread('testpat1','tif');
    x=im2double(x);
    x=169*x./x(1);
    x=x(60:60+127,65:65+127);
elseif choice==7
    x=imread('enamel','tif');
    x=x(60:60+127,65:65+127);
    x=im2double(x);
    x=255*x./x(1);
end
%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
output=[];
% Start Initialization

for ii=1:64
    mark(ii)=0; % MIP
end
mn=0;
var=[];
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;
%-----------------------------------------------------------
n=fix(log2(max(abs(seqt))))
n1=n;
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<=128*128        
        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<=128*128
        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;
end
[ mn length(find(abs(seqt)>=2^(n+1))) length(find(mark==15))]
save filename output
disp(' D O N E ')

Contact us at files@mathworks.com