-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path14_big_image_binary.py
More file actions
63 lines (52 loc) · 1.81 KB
/
14_big_image_binary.py
File metadata and controls
63 lines (52 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import cv2 as cv
import numpy as np
from matplotlib import pyplot as plt
#超大图像二值化(分割)
def big_image_binary(image):
print(image.shape)
cw = 256
ch = 256
h,w = image.shape[:2]
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
for row in range(0,h,ch):
for col in range(0,w,cw):
roi = gray[row:row+ch,col:col+cw]
ret,dst = cv.threshold(roi,0,255,cv.THRESH_BINARY|cv.THRESH_OTSU)
gray[row:row + ch, col:col + cw] =dst
print((np.std(dst)),np.mean(dst))
cv.imwrite("C:/1/text.png",gray)
def big_image_binary2(image):
print(image.shape)
cw = 256
ch = 256
h,w = image.shape[:2]
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
for row in range(0,h,ch):
for col in range(0,w,cw):
roi = gray[row:row+ch,col:col+cw]
dst = cv.adaptiveThreshold(roi,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,cv.THRESH_BINARY,127,20)
gray[row:row + ch, col:col + cw] =dst
print((np.std(dst)),np.mean(dst))
cv.imwrite("C:/1/text.png",gray)
def big_image_binary3(image):
print(image.shape)
cw = 256
ch = 256
h,w = image.shape[:2]
gray = cv.cvtColor(image,cv.COLOR_BGR2GRAY)
for row in range(0,h,ch):
for col in range(0,w,cw):
roi = gray[row:row+ch,col:col+cw]
dev = np.std(roi)
if dev < 15:
gray[row:row + ch, col:col + cw] =255
else:
dst = cv.adaptiveThreshold(roi,255,cv.ADAPTIVE_THRESH_GAUSSIAN_C,cv.THRESH_BINARY,127,20)
gray[row:row + ch, col:col + cw] = dst
cv.imwrite("C:/1/text.png",gray)
src = cv.imread("C:/1/1118.png")
cv.namedWindow('input_image', cv.WINDOW_AUTOSIZE)
cv.imshow("input_image",src)
big_image_binary2(src)
cv.waitKey(0)
cv.destroyAllWindows()