You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Populating the interactive namespace from numpy and matplotlib
"""function to change the cv2 color scheme from BGR to RGB"""defTurnRGB(image_or_frame):
returncv2.cvtColor(image_or_frame, cv2.COLOR_BGR2RGB)
"""function to convert to grayscale"""defTurnGray(image_or_frame):
returncv2.cvtColor(image_or_frame, cv2.COLOR_BGR2GRAY)
"""function to print grayscale images"""defShowGray(image_or_frame):
plt.imshow(image_or_frame, cmap='gray')
plt.show() # this line is not necessary if we have the magic function %pylab
"""function to print RGB images"""defShowColor(image_or_frame):
RGB=cv2.cvtColor(image_or_frame, cv2.COLOR_BGR2RGB)
plt.imshow(RGB)
plt.show()
"""loading the image"""loaded_image=cv2.imread('landscape.jpg')
#Direct_GrayScale_image = cv2.imread('landscape.jpg',0) # loading the image in grayscale
#converting the image to grayscaleGrayScale_image=TurnGray(loaded_image)
#plt.axis('off') # to hide the axis of scaleShowGray(GrayScale_image)
cv2.imwrite('Grayscale image.jpg',GrayScale_image)
# nice to know functionprint("the height and width dimensions of the image")
height, width=loaded_image.shape[:2]
print (loaded_image.shape) # prints the image dimensions and color channelprint ('\n the above shape was for the loaded image below is for the gragscale version')
print (GrayScale_image.shape) # prints the image dimensions and color channelprint("\n total number of pixels")
print(GrayScale_image.size)
print("\n image data type")
print(GrayScale_image.dtype)
the height and width dimensions of the image
(1414, 2121, 3)
the above shape was for the loaded image below is for the gragscale version
(1414, 2121)
total number of pixels
2999094
image data type
uint8
delloaded_image# to save memory
plt.axis("off")
ShowColor(Color_image)
Histogram Equalization
equ=cv2.equalizeHist(GrayScale_image)
cv2.imwrite('Equalized histogram image.jpg',equ)
res=np.hstack((GrayScale_image,equ)) #stacking images side-by-sidecv2.imwrite('Black & white image vs Equalized histogram.jpg',res)
res2=np.hstack((GrayScale_image,equ,cl1)) #stacking images side-by-sideShowGray(res2)
cv2.imwrite('Black & white vs Equalized histogram vs C.L.A.H.E.jpg',res2)
True
bc=np.hstack((GrayScale_image,cl1)) #stacking images side-by-sideShowGray(bc)
cv2.imwrite('Black & white vs C.L.A.H.E.jpg',bc)