function vcoeffbig=vcoeff96(vcoeffmatrix,blocknum,I,J,intermimage)
vbig=zeros(1,4608);
global black 
global white
global gray

vbig=[vcoeffmatrix(blocknum,:)];
vcoeff=vcoeffmatrix;

leftop=blocknum-17;
above=blocknum-16;
righttop=blocknum-15;
left=blocknum-1;
right=blocknum+1;
leftbottom=blocknum+15;
bottom=blocknum+16;
rightbottom=blocknum+17;

%%make intermediate image into a 256 long vector
intermimagevector=[intermimage(1,:)];   
for row=2 : 16
  intermimagevector=[intermimagevector,intermimage(row,:)];
end

%%if the surrounding block is not classified as background,
%%add wavelet coefficient vector of that block to the wavelet coefficient vector
%%of 96x96 block, otherwise the block is not merged into 96x96 block
      if (I ~= 1) & (I ~= 16) & (J ~= 1) & (J ~= 16)  %%block not on edge
          if (intermimagevector(leftop) ~= black)
             vbig=[vbig,vcoeff(leftop,:)];
          end
          if (intermimagevector(righttop) ~= black)
             vbig=[vbig,vcoeff(righttop,:)];
	    end
          if (intermimagevector(left) ~= black)
             vbig=[vbig,vcoeff(left,:)];
          end
          if (intermimagevector(right) ~= black)
             vbig=[vbig,vcoeff(right,:)];
          end
          if (intermimagevector(leftbottom) ~= black)
             vbig=[vbig,vcoeff(leftbottom,:)];
          end
          if (intermimagevector(rightbottom) ~= black)
             vbig=[vbig,vcoeff(rightbottom,:)];
          end
          if (intermimagevector(above) ~= black)
             vbig=[vbig,vcoeff(above,:)];
          end
          if (intermimagevector(bottom) ~= black)
             vbig=[vbig,vcoeff(bottom,:)];
          end

      end
      if (I == 1) & (J == 1) %%block on upper left hand corner
          if (intermimagevector(right) ~= black)
             vbig=[vbig,vcoeff(right,:)];
          end     
          if (intermimagevector(rightbottom) ~= black)
             vbig=[vbig,vcoeff(rightbottom,:)];
          end
          if (intermimagevector(bottom) ~= black)
             vbig=[vbig,vcoeff(bottom,:)];
          end          	    
      end
      if (I == 1) & (J==16)  %%block on upper right hand corner
          if (intermimagevector(left) ~= black)
             vbig=[vbig,vcoeff(left,:)];
          end
          if (intermimagevector(leftbottom) ~= black)
             vbig=[vbig,vcoeff(leftbottom,:)];
          end
          if (intermimagevector(bottom) ~= black)
             vbig=[vbig,vcoeff(bottom,:)];
          end       
      end

      if (I == 16) & (J==1)  %%block on lower left hand corner
          if (intermimagevector(righttop) ~= black)
             vbig=[vbig,vcoeff(righttop,:)];
	    end
          if (intermimagevector(right) ~= black)
             vbig=[vbig,vcoeff(right,:)];
          end
          if (intermimagevector(above) ~= black)
             vbig=[vbig,vcoeff(above,:)];
          end
      end
      if (I == 16) & (J==16)  %%block on lower right hand corner
          if (intermimagevector(leftop) ~= black)
             vbig=[vbig,vcoeff(leftop,:)];
          end
          if (intermimagevector(left) ~= black)
             vbig=[vbig,vcoeff(left,:)];
          end
          if (intermimagevector(above) ~= black)
             vbig=[vbig,vcoeff(above,:)];
          end          
      end
       
      if (I == 1) & (J ~= 1) & (J ~= 16)  %%block on top row, but not on corner
          if (intermimagevector(left) ~= black)
             vbig=[vbig,vcoeff(left,:)];
          end
          if (intermimagevector(right) ~= black)
             vbig=[vbig,vcoeff(right,:)];
          end
          if (intermimagevector(leftbottom) ~= black)
             vbig=[vbig,vcoeff(leftbottom,:)];
          end
          if (intermimagevector(rightbottom) ~= black)
             vbig=[vbig,vcoeff(rightbottom,:)];
          end
          if (intermimagevector(bottom) ~= black)
             vbig=[vbig,vcoeff(bottom,:)];
          end     
       end

      if (I == 16) & (J ~= 1) & (J ~= 16)  %%block on bottom row, but not on corner
          if (intermimagevector(leftop) ~= black)
             vbig=[vbig,vcoeff(leftop,:)];
          end
          if (intermimagevector(righttop) ~= black)
             vbig=[vbig,vcoeff(righttop,:)];
	    end
          if (intermimagevector(left) ~= black)
             vbig=[vbig,vcoeff(left,:)];
          end
          if (intermimagevector(right) ~= black)
             vbig=[vbig,vcoeff(right,:)];
          end
          if (intermimagevector(above) ~= black)
             vbig=[vbig,vcoeff(above,:)];
          end        
      end
      if (I ~= 1) & (I ~= 16) & (J == 1)  %%block in left col, but not on corner
          if (intermimagevector(righttop) ~= black)
             vbig=[vbig,vcoeff(righttop,:)];
	    end
          if (intermimagevector(right) ~= black)
             vbig=[vbig,vcoeff(right,:)];
          end
          if (intermimagevector(rightbottom) ~= black)
             vbig=[vbig,vcoeff(rightbottom,:)];
          end
          if (intermimagevector(above) ~= black)
             vbig=[vbig,vcoeff(above,:)];
          end
          if (intermimagevector(bottom) ~= black)
             vbig=[vbig,vcoeff(bottom,:)];
          end
      end

      if (I ~= 1) & (I ~= 16) & (J == 16)  %%block in right col, but not on corner
           if (intermimagevector(leftop) ~= black)
             vbig=[vbig,vcoeff(leftop,:)];
          end
          if (intermimagevector(left) ~= black)
             vbig=[vbig,vcoeff(left,:)];
          end
          if (intermimagevector(leftbottom) ~= black)
             vbig=[vbig,vcoeff(leftbottom,:)];
          end
          if (intermimagevector(above) ~= black)
             vbig=[vbig,vcoeff(above,:)];
          end
          if (intermimagevector(bottom) ~= black)
             vbig=[vbig,vcoeff(bottom,:)];
          end         
      end
vcoeffbig=vbig;
