In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces Python how to achieve a specific scene to remove highlights algorithm, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, let the editor take you to know about it.
Algorithm idea
1. Obtain the average gray level of source image I, and record rows and cols.
2. According to a certain size, it is divided into Numerm squares, the average value of each block is obtained, and the brightness matrix D of the subblock is obtained.
3. Subtract the average gray level of the source image from each element of the matrix D to obtain the luminance difference matrix E of the subblock.
4. Through the interpolation algorithm, the difference of matrix E is transformed into the luminance distribution matrix R of the same size as the source image.
5. Get the corrected image result=I-R
Application scenario
Objects with uneven overall color, such as industrial parts and ocr scenes.
Code implementation import cv2import numpy as np def unevenLightCompensate (gray, blockSize): # gray = cv2.cvtColor (img, cv2.COLOR_BGR2GRAY) average = np.mean (gray) rows_new = int (np.ceil (gray.shape [0] / blockSize)) cols_new = int (np.ceil (gray.shape [1] / blockSize)) blockImage = np.zeros ((rows_new, cols_new) Dtype=np.float32) for r in range (rows_new): for c in range (cols_new): rowmin = r * blockSize rowmax = (r + 1) * blockSize if (rowmax > gray.shape [0]): rowmax = gray.shape [0] colmin = c * blockSize colmax = (c + 1) * blockSize If (colmax > gray.shape [1]): colmax = gray.shape [1] imageROI = gray [rowmin:rowmax Colmin:colmax] temaver = np.mean (imageROI) blockImage [r, c] = temaver blockImage = blockImage-average blockImage2 = cv2.resize (blockImage, (gray.shape [1], gray.shape [0]), interpolation=cv2.INTER_CUBIC) gray2 = gray.astype (np.float32) dst = gray2-blockImage2 dst [dst > dst] = 255dst [dst
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.