Oil painting image

principle:

1, the image acquiring gradation (Gray) picture
2, to design a small box (4x4 or 8x8 or 10x10, etc.), the statistical value of each small pixel block
3, dividing into several gray 0-255 level, and the results are mapped to the respective second-step treatment level set and counted
4, to find all the pixels in each block up to the gray scale, and obtaining the mean of these pixels
5, figured out with the average value of pixel values to replace the original

CV2 Import 
Import numpy AS NP

IMG = cv2.imread ( 'D: /pythonob/imageinpaint/img/zidan.jpg',. 1)
imgInfo img.shape =
height = imgInfo [0]
width = imgInfo [. 1]
Gray = CV2. cvtColor (IMG, cv2.COLOR_BGR2GRAY)
DST = np.zeros ((height, width,. 3), np.uint8)
pixel_class. 4 =
sectionTop = int (256 / pixel_class)
# use two for each data loop traversed image
I in Range for (. 3, height -. 3):
for J in Range (. 3, width -. 3):
# current gray level is defined in the program 4
# define an array of pixels to a load in four grades number
array1 = np.zeros (pixel_class, np.uint8)
# small squares procedure is currently defined in the 6x6
for m in Range (-3,. 3):
for n-in Range (-3,. 3):
# P1 is dividing the pixel level segment, represented by the subscripts 0-3
int = P1 (Gray [I + m, n-J +] / sectionTop)
# next level of the pixel counts, the subscripts represent array1 pixel level,
a # pixel values are representative of the pixel in the small block level number
array1 [P1] = array1 [P1] +. 1
# next block determines which pixels within a small pixel segments up
CurrentMax = array1 [0]
l = 0 to l # here provided a recording pixel segment count up array subscript
for K in Range (0, pixel_class):
IF CurrentMax <array1 [K]:
CurrentMax array1 = [K]
L = K
# mean treatment
U = V = W = 0
for m in Range (-3,. 3 ):
for n-in Range (-3,. 3):
IF Gray [I + m, n-J +]> = (L * sectionTop) and Gray [I + m, n-J +] <= ((L +. 1) * section):
(b, g, r) = img[i + m, j + n]
u += b
v += g
w += r
u = int(u / array1[l])
v = int(v / array1[l])
w = int(w / array1[l])
dst[i, j] = [u, v, w]
cv2.imshow('dst', dst)
cv2.imshow('img', img)
cv2.waitKey(0)

 

FIG effect;

 

Guess you like

Origin www.cnblogs.com/cxxBoo/p/11460215.html