Loading... $$ \begin{align*} \begin{split} g(i,j)= \left \{ \begin{array}{ll} \alpha f(i,j),&0\le f(i,j)< a\\ \beta (f(i,j)-a)+g_{a},&a\le f(i,j)< b\\ \gamma (f(i,j)-b)+g_{b},&b\le f(i,j)< 255 \end{array} \right. \end{split} \end{align*} $$ ```python from turtle import width from matplotlib import pyplot as plt import cv2,matplotlib fa, fb = 80, 200 a, b, c = 1.1, 1.2, 1.3 cat = cv2.imread("cat.jpg") cat = cv2.cvtColor(cat, cv2.COLOR_BGR2GRAY) change_cat = cat.copy() width = cat.shape[0] height = cat.shape[1] for i in range(0, width): for j in range(0, height): if 0 <= change_cat[i][j] < fa: change_cat[i][j] = 0 elif fa <= change_cat[i][j] < fb: change_cat[i][j] = 255 * ((change_cat[i][j] - fa) / (fb - fa)) else: change_cat[i][j] = 255 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/2395936215.png) Last modification:October 4, 2022 © Allow specification reprint Like 0 如果觉得我的文章对你有用,请随意赞赏
Comment here is closed