Last active
February 4, 2019 13:06
-
-
Save foolishflyfox/5a3dc87690067ae68a2fcf1871dbf88f to your computer and use it in GitHub Desktop.
常用的python计算机视觉操作函数
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 对一幅灰度图像进行直方图均衡化 | |
def myhisteq(im, nbr_bins=256): | |
""" | |
@im: PIL.Image.Image, mode is L | |
@return: PIL.Image.Image | |
""" | |
np_im = np.asarray(im) | |
imhist, bins = np.histogram(np_im.flatten(), nbr_bins) | |
csum = np.cumsum(imhist) | |
csum = 255 * csum / csum[-1] | |
new_np_im = np.interp(np_im.flatten(), bins[:-1], csum) | |
return Image.fromarray(new_np_im.reshape(np_im.shape).astype(np.uint8)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment