wrong image slicing [closed]

asked 2015-04-14 03:33:26 -0600

begueradj gravatar image

updated 2015-04-14 03:33:47 -0600

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:

image description

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

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by StevenPuttemans
close date 2015-04-20 03:30:17.253189

Comments

4

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 gravatar imageStevenPuttemans ( 2015-04-14 04:02:21 -0600 )edit
1

@StevenPuttemans But why the original image is displaying without the aliasing problem then unlike the other 4 blocks ?

begueradj gravatar imagebegueradj ( 2015-04-14 07:14:00 -0600 )edit
1

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 gravatar imageStevenPuttemans ( 2015-04-15 06:54:49 -0600 )edit
1

@StevenPuttemans yes, you were right. Thank you very much

begueradj gravatar imagebegueradj ( 2015-04-20 01:35:11 -0600 )edit