Read and Write operations on Images using OpenCV Python
Hello all,
This is the tenth article in the series Python for Data Science. If you are new to this series, we would recommend you to read our previous articles
- Python for Data Science Series - Part 1
- Python for Data Science Series - Part 2
- Using Numpy in Python
- Using Pandas in Python
- Data Visualization using Matplotlib Python
- Parsing XML file in python
- Parsing Json file in python
- Interactive Data Visualization using Plotly in Python
- Logging in Python
To Install OpenCV Library in your python environment by using the following command
pip install opencv-contrib-python
Please refer the videos below for detailed explanation on how to use opencv to Read and Write Images in Python
Please refer the following code to understand on how to read and write image files in python
import cv2
import os
main_folder_path = r"E:\openknowledgeshare.blogspot.com\Python\Data"
image_file_path = os.path.join(main_folder_path,"IMG_20180116_130048.jpg")
my_image = cv2.imread(image_file_path)
type(my_image)
my_image.shape
import matplotlib.pyplot as plt
plt.imshow(my_image)
import numpy as np
np.max(my_image)
np.min(my_image)
my_image[0:400,0:1000,:] = 0
plt.imshow(my_image)
output_image_file_path = os.path.join(main_folder_path,"IMG_20180116_130048_modified.jpg")
cv2.imwrite(output_image_file_path,my_image)
Comments
Post a Comment