It is a memorandum when displaying the histogram of the brightness value of the image with python
histgram.py
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
def color_hist(filename):
img = np.asarray(Image.open(filename).convert("RGB")).reshape(-1,3)
plt.hist(img, color=["red", "green", "blue"], bins=128)
plt.show()
color_hist("./test.jpg ")
histgram.py
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
def color_hist(filename):
img = np.asarray(Image.open(filename).convert("L")).reshape(-1,1)
plt.hist(img, bins=128)
plt.show()
color_hist("./test.jpg ")
The original image
When cropping an image
from PIL import Image
import matplotlib.pyplot as plt
import numpy as np
import cv2
def color_hist(filename):
img = np.asarray(Image.open(filename).convert("L")).reshape(-1,1)
plt.hist(img, bins=256)
plt.show()
def cut_image(filename):
im = cv2.imread(filename,0)
dst = im[0:400,250:410] #y,x
cv2.imwrite('./tmp.jpg',dst)
cut_image("./test.jpg ")
color_hist("./tmp.jpg ")
nothing special
Pixel manipulation of images in Python Grayscale with Python Easy way to display a color histogram of an image in Python
Recommended Posts