Loading... ## 公式 $$ g[i][j] = clog_{10}(f[i][j]) $$ ## 代码实现 ```python import cv2,math,skimage from matplotlib import pyplot as plt from copy import copy def change(img, w, l, channel): if channel == 3: img = skimage.img_as_float(img) for i in range(w): for j in range(l): for k in range(channel): img[i][j][k] = 2 * math.log((1 + img[i][j][k]), 10) elif channel == 2: for i in range(w): for j in range(l): img[i][j] = 20 * math.log((1 + img[i][j]), 10) return img cat = cv2.imread("D:\\work\\cv\\1002\\cat.jpg") cat = cv2.cvtColor(cat, cv2.COLOR_BGR2GRAY) change_cat = cat.copy() # print(change_cat.ndim) change_cat = change(change_cat, change_cat.shape[0], change_cat.shape[1], change_cat.ndim) if change_cat.ndim == 3: plt.rcParams['font.family'] = 'SimHei' plt.figure(figsize=(10, 8), dpi = 100) plt.subplot(121),plt.imshow(cat[:,:,::-1]),plt.title('原图') plt.subplot(122),plt.imshow(change_cat[:,:,::-1]),plt.title('调整后') plt.show() elif change_cat.ndim == 2: plt.rcParams['font.family'] = 'SimHei' plt.figure(figsize=(10, 8), dpi = 100) plt.subplot(121),plt.imshow(cat, cmap='gray'),plt.title('原图') plt.subplot(122),plt.imshow(change_cat, cmap='gray'),plt.title('调整后') plt.show() ``` ### 输出: ![image.png](https://mioe-xyz.oss-cn-shanghai.aliyuncs.com/usr/uploads/2022/10/2526917559.png) Last modification:October 6, 2022 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed