import cv2
import numpy as np
img= cv2. imread( '5.jpg' , 1 )
rnum= img. shape[ 0 ]
cnum= img. shape[ 1 ]
cursel = [ ]
gray= cv2. cvtColor( img, cv2. COLOR_BGR2GRAY)
dst= np. zeros( [ rnum, cnum, 3 ] , np. uint8)
for i in range ( 4 , rnum- 4 ) :
for j in range ( 4 , cnum- 4 ) :
array1= np. zeros( 8 , np. uint8)
for m in range ( - 4 , 4 ) :
for n in range ( - 4 , 4 ) :
p1= int ( gray[ i+ m, j+ n] / 32 )
array1[ p1] = array1[ p1] + 1
currentMax= array1[ 0 ]
l= 0
for k in range ( 0 , 8 ) :
if currentMax< array1[ k] :
currentMax= array1[ k]
l= k
for m in range ( - 4 , 4 ) :
for n in range ( - 4 , 4 ) :
if gray[ i+ m, j+ n] >= ( l* 32 ) and gray[ i+ m, j+ n] <= ( ( l+ 1 ) * 32 ) :
cursel= img[ i+ m, j+ n]
dst[ i, j] = cursel
cv2. imshow( 'dst' , dst)
cv2. waitKey( 0 )
import cv2
import numpy as np
img= cv2. imread( '0.jpg' , 0 )
rnum= img. shape[ 0 ]
cnum= img. shape[ 1 ]
dst= np. zeros( img. shape, np. uint8)
for i in range ( rnum) :
for j in range ( cnum- 1 ) :
gray0= int ( img[ i, j] )
gray1= int ( img[ i, j+ 1 ] )
newpix= gray0- gray1+ 150
if newpix> 255 :
newpix= 255 - newpix
if newpix< 0 :
newpix= 255 + newpix
dst[ i, j] = newpix
cv2. imshow( 'dst' , dst)
cv2. waitKey( 0 )