-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathS_calculation.py
35 lines (28 loc) · 1.09 KB
/
S_calculation.py
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
from PIL import Image
import numpy as np
#from train import mask
import glob
import os
import cv2
path1 = 'data/tif/train_mask/*.tif'
path2 = 'predict/tif_result/*.tif'
path3 = 'predict/out1/*_bi.png' #人工核实png成功生成,png格式要'/255'
print('求耕地面积占比\n')
def whitepercent(a):
c=2*np.abs(a-0.5)
s=c.sum() #s=sum(sum(c))
n=a.sum() #n=sum(sum(a))
p=n/s
return p
for files in glob.glob(path1): #原始耕地面积生成
filepath,filename = os.path.split(files)
a = cv2.imread(files, -1) #np.asarray(Image.open(files))
print(filename+' ' +' %.8f \n' %whitepercent(a))
for files in glob.glob(path2): #tif耕地面积计算
filepath,filename = os.path.split(files)
a = cv2.imread(files, -1) #np.asarray(Image.open(files))
print(filename+' ' +' %.8f \n' %whitepercent(a))
for files in glob.glob(path3): #png耕地面积计算
filepath,filename = os.path.split(files)
a = cv2.imread(files, -1)/255 #np.asarray(Image.open(files))
print(filename+' ' +' %.8f \n' %whitepercent(a))