I want to divide a picture into 4 blocks of the same size. Here is my code:
import numpy as np
import cv2
import cv
im=cv2.imread('homer.jpg')
print im.shape # (548, 500, 3)
im1=im[0:273,0:249]
im2=im[274:547,0:249]
im3=im[0:273,250:499]
im4=im[274:547,250:499]
cv2.namedWindow('im1',cv2.WINDOW_AUTOSIZE)
cv2.namedWindow('im2',cv2.WINDOW_AUTOSIZE)
cv2.namedWindow('im3',cv2.WINDOW_AUTOSIZE)
cv2.namedWindow('im4',cv2.WINDOW_AUTOSIZE)
a=np.hstack((im1,im3))
b=np.hstack((im2,im4))
r=np.vstack((a,b))
cv2.namedWindow('original',cv2.WINDOW_AUTOSIZE)
cv2.imshow('original',im)
cv2.imshow('im1',im1.copy())
cv2.imshow('im2',im2.copy())
cv2.imshow('im3',im3.copy())
cv2.imshow('im4',im4.copy())
cv2.imwrite('im1.jpg',im1)
cv2.imwrite('im2.jpg',im2)
cv2.imwrite('im3.jpg',im3)
cv2.imwrite('im4.jpg',im4)
cv2.imwrite('rebuilt_image.jpg',r)
cv2.waitKey(0)
cv2.destroyAllWindows()
Here are the results:
My problem:
As you can see, there is aliasing effect that can clearly be seen in the 4 blocks unlike in the original image. This means the image slicing into 4 blocks is not enough good.
Someone could tell me what's wrong and how to correct ?
Thank you in advance