- Statistics From NumPy Official Docs.
https://numpy.org/doc/stable/reference/routines.statistics.html
- Order statistics
numpy.percentile
numpy.percentile(a, q, axis=None, out=None, overwrite_input=False, method='linear', keepdims=False, *, weights=None, interpolation=None)
- Averages and variances
- Correlating
- Histograms
- 5 Best Ways to Grayscale Images with Python Using OpenCV
March 11, 2024 by Emily Rosemary Collins
- Problem Formulation
In image processing, grayscaling is a procedure of converting color images into shades of gray, indicating that each pixel now represents the intensity of light only, not color. Programmers often need to perform this task to simplify or prepare images for further processing, such as edge detection or thresholding. A common input would be a colored image (JPEG, PNG, etc.), and the desired output is its grayscale version.
- cv2
# Load the image
image = cv2.imread('path_to_image.jpg')
# Convert the image to grayscale
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
# Save the grayscale image
cv2.imwrite('gray_image.jpg', gray_image)
- cv2
import cv2
# Load the image directly in grayscale
gray_image = cv2.imread('path_to_image.jpg', cv2.IMREAD_GRAYSCALE)
# Save the grayscale image
cv2.imwrite('gray_image.jpg', gray_image)
- cv2
import cv2
import numpy as np
# Load the image
image = cv2.imread('path_to_image.jpg')
# Manually convert to grayscale using channel mixing
weights = [0.1140, 0.5870, 0.2989] # BGR weights
gray_image = np.dot(image[...,:3], weights).astype(np.uint8)
# Save the grayscale image
cv2.imwrite('gray_image.jpg', gray_image)
- cv2
import cv2
# Load the image
image = cv2.imread('path_to_image.jpg')
# Split the image into its individual color channels
b, g, r = cv2.split(image)
# Use the red channel for grayscale effect
gray_image = cv2.merge([r, r, r])
# Save the grayscale image
cv2.imwrite('red_channel_gray_image.jpg', gray_image)
- cv2
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
# Load the image
image = mpimg.imread('path_to_image.jpg')
# Display the image in grayscale
plt.imshow(image, cmap='gray')
plt.axis('off') # Hide axis
plt.show()
标签:gray,Statistics,NumPy,image,cv2,jpg,grayscale,SciTech
From: https://www.cnblogs.com/abaelhe/p/18310404