%Step 1 & 2 of the algorithm as listed on page 1611 of Li & Gray

function [List,m, CInew] = step12(CItemp,blocksize, originalImage)
m=0;
List=[];

CI = CItemp;
[a, b,c]=size(CI);

for i=1:a
   for j=1:b
      if CI(i,j,2)==4 % 4 represents unclassified blocks
      AdjNeighbor=checkAdjNeighbor(i,j,CI); %checks if unclassified block has classified neighbors

			if AdjNeighbor==0 %if no classified neighbors, add block to list L
         	List=[List; [i j createList(i,j,CI)]];
      	else
			%if there are classified neighbors, pass block into microclassifier       
         classtype=microclassifier(CI, i,j,originalImage, blocksize);
         
          	if classtype==4 %if microclassifier cannot classify block
            	List=[List; [i j createList(i,j,CI)]];
            else
               %classified blocks, update CI matrix
               [bivalue_1, bivalue_2] = bivalue2(originalImage((i-1)*blocksize +1:i*blocksize, (j-1)*blocksize+1:j*blocksize));
               
               [tt, ttt] = meanSD(i,j,blocksize,originalImage);
               temptemp = cat(3, -1, classtype, tt,ttt, bivalue_1, bivalue_2);
               
               CI(i,j,:)= temptemp;
               
               m=m+1;

           end
         end
      end
   end
end
CInew = CI;

