type
Post
status
Published
date
Mar 12, 2023 02:58 AM
slug
summary
tags
TODO
category
技术折腾
icon
fas fa-trophy-alt
password
首先, 用wand 我还不会优雅的画histogram
如下, 因为img.histogram 是iter 类型, 没对应的items 输出.
My guess is that the function used to build the dict keys in __iter__
(PixelGetColorAsString
) is not the same as the one used in __getitem__
(PixelGetColorAsNormalizedString
).
import requests, os, cv2, random, wand, pyexiv2 import numpy as np import pandas as pd import matplotlib.pyplot as plt from wand.image import Image from wand.display import display with Image(filename='images/lena.jpg') as original: # 330, 252 img = original.clone() img.transform_colorspace('gray') # with img.channel_images['red'] as red_image: # plt.imshow(img, cmap='gray') # 不加cmap 的话, 图片异常 # plt.imshow(img) # 不加这句, py文件不显示图片 # plt.show() plt.plot(img.histogram.items()) plt.show()
用cv2 就很简单了
import cv2 import matplotlib.pyplot as plt image = cv2.imread('images/lena.jpg', cv2.IMREAD_COLOR) image_gray = cv2.imread('images/lena.jpg', cv2.IMREAD_GRAYSCALE) histb = cv2.calcHist([image], [0], None, [256], [0, 255]) histg = cv2.calcHist([image], [1], None, [256], [0, 255]) histr = cv2.calcHist([image], [2], None, [256], [0, 255]) hist_gray = cv2.calcHist([image_gray], [0], None, [256], [0, 255]) plt.plot(histb, color='b') plt.plot(histg, color='g') plt.plot(histr, color='r') plt.plot(hist_gray, color='black') plt.show()
但出的图是下面这样:

没有像ps这样的效果,

