COMBINE 2 IMAGES TO FORM A SINGLE IMAGE

Saranya. S
3 min readJun 4, 2021

PRE-REQUITIES ::

* Install cv2 module
command: pip install OpenCV-python

|| OpenCV is a cross-platform library using which we can develop real-time computer vision applications.

**It mainly focuses on image processing, video capture and analysis including features like face detection and object detection.

|| OpenCV-Python makes use of Numpy , which is a highly optimized library for numerical operations with a MATLAB-style syntax.

1.Import cv2 and numpy.

2. Load Images.

* cv2.imread() :: loads an image from the specified file.
SYNTAX: cv2.imread (path)

3. Crop the images

By this slicing, images get halved

4. See the desired output.

# Add an image in the window : display  
SYNTAX :: cv2.imshow (window_name, image)
# wait for a specific time in milliseconds
SYNTAX :: cv2.waitKey()
# Destroys the window showing image
SYNTAX :: cv2.destroyAllWindows()

OUTPUT :

5. we are going to take 4 images.

6. Make all images of same size.

SYNTAX: resizeImg = cv2.resize(img, (new_w, new_h))

7. To attach images.

* numpy.hstack() function is used to stack the sequence of input arrays horizontally (i.e. column wise) to make a single array. SYNTAX : numpy.hstack (tup)
Where,
tup - sequence of ndarrays

8. To combine images.

* numpy.vstack() function is used to stack the sequence of input arrays vertically (i.e. row wise) to make a single array.SYNTAX : numpy.vstack (tup)
Where,
tup - sequence of ndarrays

9. See the desired output.

# Add an image in the window : display  
SYNTAX :: cv2.imshow (window_name, image)
# wait for a specific time in milliseconds
SYNTAX :: cv2.waitKey()
# Destroys the window showing image
SYNTAX :: cv2.destroyAllWindows()

FINAL CODE :

OUTPUT ::

DONE !!!

--

--