wrong image slicing [closed]
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
Wow am I the only one who doesnt see what is wrong? The only deforment now is due to the fact you built OpenCV with Qt support and that those Qt windows try to automatically scale the image. Thats all.
@StevenPuttemans But why the original image is displaying without the aliasing problem then unlike the other 4 blocks ?
It is NOT the aliasing effect ... The original image is scaled correctly because it dimensions are large enough not to trigger this rescaling effect. Just build OpenCV without QT support and you will see the problems dissapear :)
@StevenPuttemans yes, you were right. Thank you very much