TASK 4
1.Creating Image Using Python Code.
Step 1: Install cv2 Module.
command : pip install opencv-python.
|| OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision. ||
Step 2: Import cv2 and Numpy
Importing cv2 and numpy
Step 3: Create an Blank image using Numpy.
command : numpy.zeros((height,width,3))
numpy.zeros : It is having 3 colors in the form of
i.e , (B , G , R) = ( 0 , 0, 0 ) so ‘3’:BGR color
numpy.uint8 : Unsigned integer (0 to 255)
Step 4 : Start to draw the image as per your wish using some functions.
I have just created a nested for loop for assigning colors dividing the image
for i in range(h) : the range of height which we have given as 512
for j in range(w) : the range of width which we have given as 512
we have already intialized A in previous steps
Therefore, we start assigning colors to the given height and width.
step 4 : To see the output:
Syntax: cv2.imshow(window_name, image) #display image
cv2.waitkey(time in ms) # wait for a specific time in milliseconds
cv2.destroyAllWindows() # destroy the window after displaying the image
Output :
We Have Completed Task 4.1
Thank You..!!
2.Crop and Swap 2 images using Python
Step 1: Install cv2 Module.
command : pip install opencv-python.
|| OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision. ||
Step 2: Import cv2 and Numpy
Importing cv2 module and Importing numpy as np
Step 3: Reading the First and Second photo
synatx : cv2.imread(‘filename’)
Step 4: Lets check Shape of the photo
synatx : variablename.shape
Shape of the 1 image
Shape of the second image
Step 5: Lets Join both the image horizontally:
As we have imported numpy as np so we have join horizontally by using
np.hstack(img1 , img2)
Step 6: Lets check the Image
Syntax: cv2.imshow(window_name, image) #display image
cv2.waitkey(time in ms) # wait for a specific time in milliseconds
cv2.destroyAllWindows() # destroy the window after displaying the image
Output :
Step 7: Crop the Second Photo
crop the Second Photo.
Swap the Photo.
and saved as the final_photo1.
Step 8: Crop the First Photo
Crop the First Photo
Swap the part with the second photo.
and Saved as the Final_photo2
Step 9: Again we will join the Photo Horizontally
As we have got the output
we will merge the image horizontally and save the image in variable name photo
Step 10: Output:
Output:
We Have Completed TASK 4.2
Thank you ..!!
3.Combine 2 Images to Form a Single Image
Step 1: Install cv2 Module.
command : pip install opencv-python.
|| OpenCV (Open Source Computer Vision Library) is a library of programming functions mainly aimed at real-time computer vision. ||
Step 2: Import cv2 and Numpy
Importing cv2 module and Importing numpy
Importing cv2 and numpy
Step 3 : Lets Read and Display the Particular Image.
#syntax:
cv2.imread (‘image’) #reading the image
cv2.imshow(window_name, image) #display image
cv2.waitkey(time in ms) # wait for a specific time in milliseconds
cv2.destroyAllWindows() # destroy the window after displaying the image
Image 1 :
Output:
Image 2 :
#Same Syntax
#For Reading and Display the Image.
Output:
Step 4 : Lets Check The size of our Image
#syntax : variablename.shape
Step 5 : Crop or Resize the Photo
We will Crop or Resize the photo1 in the same shape of Photo2 to get an Proper Output with the Same Size in Height and Width.
Step 6: Attach The Image Horizontally.
we will attach both the image photo1_res and photo2 horizontally by using Numpy.
#numpy.hstack((image1 ,image2))
EX: we can see as the image in the form Collage
Step 7: Output:
Output:
We Have Completed Task 4.3
Hope you Find It Intresting..!!
Thank you..!!