
A = double(imread('image1.jpg'));
B = double(imread('image2.jpg'));
C = double(imread('image3.jpg'));


A=round(A/255)*255;B=round(B/255)*255;C=round(C/255)*255;

sizeA=size(A); mI=sizeA(1); nI=sizeA(2);

image1=zeros(mI,nI);
newimage1=zeros(2*mI,2*nI); 

for a=1:mI;
   for b=1:nI;
         image1(a,b) = A(a,b);       
        if image1(a,b) == 0
         newimage1(2*a-1,2*b-1) = 0; 
         newimage1(2*a,2*b-1) = 0; 
         newimage1(2*a-1,2*b) = 0; 
         newimage1(2*a,2*b) = 255;
        else
         newimage1(2*a-1,2*b-1) = 255; 
         newimage1(2*a,2*b-1) = 0; 
         newimage1(2*a-1,2*b) = 0; 
         newimage1(2*a,2*b) = 255;
        end
   end
end

image2=zeros(mI,nI);
image3=zeros(mI,nI);
newimage2=zeros(2*mI,2*nI); 

for a=1:mI;
   for b=1:nI;
         image2(a,b)=B(a,b);  image3(a,b)=C(a,b);                
      if and(image2(a,b) == 0,image3(a,b) == 0)
         newimage2(2*a-1,2*b-1) = 0; 
         newimage2(2*a,2*b-1) = 255; 
         newimage2(2*a-1,2*b) = 0; 
         newimage2(2*a,2*b) = 0;
      end
      if and(image2(a,b) == 255,image3(a,b) == 0)
         newimage2(2*a-1,2*b-1) = 0; 
         newimage2(2*a,2*b-1) = 255; 
         newimage2(2*a-1,2*b) = 255; 
         newimage2(2*a,2*b) = 0;
      end
      if and(image2(a,b) == 0,image3(a,b) == 255)
         newimage2(2*a-1,2*b-1) = 0; 
         newimage2(2*a,2*b-1) = 0; 
         newimage2(2*a-1,2*b) = 0; 
         newimage2(2*a,2*b) = 255;
      end
      if and(image2(a,b) == 255,image3(a,b) == 255)
         newimage2(2*a-1,2*b-1) = 0; 
         newimage2(2*a,2*b-1) = 0; 
         newimage2(2*a-1,2*b) = 255; 
         newimage2(2*a,2*b) = 255;
      end  
   end
end


for a=1:mI
   for b=1:nI
      r=round(rand);       
      if r==1
         mem1=newimage1(2*a,2*b-1);mem2=newimage1(2*a,2*b);
         newimage1(2*a,2*b-1)=mem2;newimage1(2*a,2*b)=mem1;
         mem1=newimage2(2*a,2*b-1);mem2=newimage2(2*a,2*b);
         newimage2(2*a,2*b-1)=mem2;newimage2(2*a,2*b)=mem1;
      end
   end
end

for a=1:2*mI;
   newimage1(a,1) = 128; 
   newimage1(a,2*nI)=128;
   newimage2(a,1) = 128; 
   newimage2(a,2*nI)=128;
end
   
 for b=1:2*nI;
   newimage1(1,b) = 128; 
   newimage1(2*mI,b)=128;
   newimage2(1,b) = 128; 
   newimage2(2*mI,b)=128;
end



imwrite(newimage1/255,'newimage1.jpg'); 
imwrite(newimage2/255,'newimage2.jpg');