Tryag File Manager
Home
||
Turbo Force
||
B-F Config_Cpanel
Current Path :
/
paip
/
script
/
unused
/
Or
Select Your Path :
Upload File :
New :
File
Dir
//paip/script/unused/therImageAvgMax.py
# -*- coding: utf-8 -*- """ Created on Fri Jun 18 11:53:29 2021 @author: lbk """ import os import warnings warnings.filterwarnings("ignore") from itertools import count import sys import numpy as np import matplotlib.pyplot as plt import seaborn as sns from glob import glob import matplotlib.patches as patches from collections import Counter import pandas as pd #%% def readpgm(name): with open(name) as f: lines = f.readlines() # Ignores commented lines for l in list(lines): if l[0] == '#': lines.remove(l) # Makes sure it is ASCII format (P2) assert lines[0].strip() == 'P2' # Converts data to a list of integers data = [] for line in lines[1:]: data.extend([int(c) for c in line.split()]) return (np.array(data[3:]), (data[1], data[0]), data[2]) # different shades of gray from black (0) to white (up to 65,536) #%% pgm_path = glob(sys.argv[1]) data = readpgm(pgm_path[0]) #plt.imshow(np.reshape(data[0], data[1]),cmap='gray') #%% p_data = np.reshape(data[0], data[1]) p_data = p_data*150/4096 - 10 #print(p_data) #plt.imshow(p_data,cmap='gray') #%% p_data = pd.DataFrame(p_data) test = pd.melt(p_data,value_vars=p_data.columns, ignore_index=False) test.columns = ['x','value'] test['y'] = test.index test = test.reset_index(drop=True) #test0 = test[test.value < 10] test1 = test[test.value >= 10] #%% df = test1.drop(['value'],axis=1) from sklearn.cluster import DBSCAN model = DBSCAN(eps=np.sqrt(2), min_samples=5) pred = model.fit_predict(df) test1['group'] = pred result = test1['value'].groupby(test1['group']) size = result.size() size[size > size.median()*1.5] = 0 size[size < size.median()*0.5] = 0 size = size[size !=0 ] valid = size.index temp = [] for i in valid: sub = test1[test1.group == i] sub = sub.sort_values(by=['value'], axis=0, ascending=False) temp.append(sub[:9].value.mean()) avg_temp = np.round(np.median(temp),1) #max_temp = np.round(test1.value.max(),1) max_temp = np.round(np.max(temp),1) print(max_temp,avg_temp)