%%classify16
%%takes a vector,v16, of LH and LH (from wavelet transform) of 16x16 block that was part 
%%of a 32x32 block who's classification was undetermined
%%classifies 16x16 block and edits the final image according to the classification
%%of this block.

variance=var(v16);

if variance < .1    %background -> image will be black
   color=black;
   modify16
elseif variance < T3    %picture  -> image will be white
      color=white;
      modify16
elseif variance > T4     %text   -> image will be  gray
      color=gray;
      modify16
else   % classification of 16x16 block is undetermined

   %%check if 32x32 mother block has both adjacent text and picture blocks

   [adjtext,adjpic] = checkadjacent(blocknum,intermimage,I,J);
   %%adjtext = 1 if block has adjacent text block
   %%adjpic = 1 if block has adjacent picture block

   if (adjtext == 1) & (adjpic == 1)      %%this block has both adjacent text and picture blocks

               if variance < T0   %%16x16 block is picture
                    color=white;
                    modify16
               else               %%16x16 block is text
                    color=gray;
                    modify16
               end            
   else    %block doesn't have adjacent text and picture blocks

     %%form a larger 96 x 96 block that includes the 32x32 mother block of 16x16 block 
     %%and the 8 blocks surrounding this block, and use wavelet coeffs of this big block
     %%to classify 16x16 bloack
     
     vbig=vcoeff96(vcoeffmatrix,blocknum,I,J,intermimage);
     %%vbig is a vector of LH and HL wavelet coefficients for 96x96 block

     variance=var(vbig);
     if variance < T0   %%16x16 block is picture
         color=white;
         modify16
     else         %%16x16 block is text
         color=gray;
         modify16

     end
   end
end
adjtext=0;
adjpic=0;
