How to Cut an Image Vertically into Two Equal Sized Images
you can define following function to simply slice every image you want to two vertical parts.
def imCrop(x):
height,width,depth = x.shape
return [x[height , :width//2] , x[height, width//2:]]
and then you can simply for example plot the right part of the image by:
plt.imshow(imCrop(yourimage)[1])
import cv2
# Read the image
img = cv2.imread('your file name')
print(img.shape)
height = img.shape[0]
width = img.shape[1]
# Cut the image in half
width_cutoff = width // 2
s1 = img[:, :width_cutoff]
s2 = img[:, width_cutoff:]
cv2.imwrite("file path where to be saved", s1)
cv2.imwrite("file path where to be saved", s2)
You can try the following code which will create two numpy.ndarray
instances which you can easily display or write to new files.
from scipy import misc
# Read the image
img = misc.imread("face.png")
height, width = img.shape
# Cut the image in half
width_cutoff = width // 2
s1 = img[:, :width_cutoff]
s2 = img[:, width_cutoff:]
# Save each half
misc.imsave("face1.png", s1)
misc.imsave("face2.png", s2)
The face.png
file is an example and needs to be replaced with your own image file.