Merge branch 'main' of https://arnweb.nl/gitea/arne/EV5_Beeldherk_Bomen
This commit is contained in:
commit
6162f5a3c1
161
src/experiments/algorithms/colour_FE.py
Normal file
161
src/experiments/algorithms/colour_FE.py
Normal file
@ -0,0 +1,161 @@
|
||||
import cv2
|
||||
import cv2.typing
|
||||
from cv2.mat_wrapper import Mat as Mat
|
||||
import os
|
||||
import numpy as np
|
||||
import csv
|
||||
from enum import Enum
|
||||
|
||||
CSV_PATH = "src\\experiments\\algorithms\\data\\"
|
||||
IMG_PATH = "dataset\\accasia_1210048 (2023_09_28 12_19_26 UTC).JPG"
|
||||
BARK_TYPES = 8
|
||||
|
||||
class Tree(Enum):
|
||||
ACCASIA = 0
|
||||
BERK = 1
|
||||
EIK = 2
|
||||
ELS = 3
|
||||
ESDOORN = 4
|
||||
ES = 5
|
||||
LINDE = 6
|
||||
PLATAAN = 7
|
||||
|
||||
class ColourSpace(Enum):
|
||||
BGR = 0
|
||||
HSV = 1
|
||||
|
||||
class colourTester:
|
||||
def __init__(self) -> None:
|
||||
self.bgr_curves = [[[], [], []] for x in range(BARK_TYPES)]
|
||||
self.bgr_ids = ["", "", ""]
|
||||
self.hsv_curves = [[[], [], []] for x in range(BARK_TYPES)]
|
||||
self.hsv_ids = ["", "", ""]
|
||||
self.labels = ["" for x in range(BARK_TYPES)]
|
||||
|
||||
def loadImage(self) -> None:
|
||||
img = cv2.imread(self.im_path, 1)
|
||||
assert img is not None, \
|
||||
"Failed to load an image, check path"
|
||||
self.bgr_img = img
|
||||
self.hsv_img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
|
||||
return
|
||||
|
||||
def setImPath(self, path : str) -> None:
|
||||
if os.path.isfile(path):
|
||||
self.im_path = path
|
||||
else:
|
||||
print("file does not exist")
|
||||
return
|
||||
|
||||
def setCsvBgrPath(self, path : str) -> None:
|
||||
if os.path.isfile(path):
|
||||
self.csv_bgr_path = path
|
||||
else:
|
||||
print("file does not exist")
|
||||
return
|
||||
|
||||
def setCsvHsvPath(self, path : str) -> None:
|
||||
if os.path.isfile(path):
|
||||
self.csv_hsv_path = path
|
||||
else:
|
||||
print("file does not exist")
|
||||
return
|
||||
|
||||
def getData(self, img : cv2.typing.MatLike) -> (float, float):
|
||||
mean = np.zeros(3)
|
||||
std = np.zeros(3)
|
||||
for i in range(img.shape[2]):
|
||||
mean[i] = np.mean(img[:, :, i])
|
||||
std[i] = np.std(img[:, :, i])
|
||||
return (mean, std)
|
||||
|
||||
def loadCurves(self) -> None:
|
||||
with open(self.csv_bgr_path, 'r') as bgr_file:
|
||||
reader = csv.reader(bgr_file, delimiter=',')
|
||||
j = 0
|
||||
i = -1
|
||||
for row in reader:
|
||||
j+=1
|
||||
i += 1 if (j-1) % 3 == 0 else 0
|
||||
self.labels[i] = row[0]
|
||||
self.bgr_ids[(j-1)%3] = row[1]
|
||||
for col in row[2:]:
|
||||
self.bgr_curves[i][(j-1)%3].append(col)
|
||||
|
||||
with open(self.csv_hsv_path, 'r') as hsv_file:
|
||||
reader = csv.reader(hsv_file, delimiter=',')
|
||||
j = 0
|
||||
i = -1
|
||||
for row in reader:
|
||||
j+=1
|
||||
i += 1 if (j-1) % 3 == 0 else 0
|
||||
self.labels[i] = row[0]
|
||||
self.hsv_ids[(j-1)%3] = row[1]
|
||||
for col in row[2:]:
|
||||
self.hsv_curves[i][(j-1)%3].append(col)
|
||||
return
|
||||
|
||||
def correlate(self, mean : float, tree : Tree, space : ColourSpace) -> [float, float, float]:
|
||||
results = [0, 0, 0]
|
||||
if space == ColourSpace.BGR:
|
||||
curve = self.bgr_curves
|
||||
elif space == ColourSpace.HSV:
|
||||
curve = self.hsv_curves
|
||||
for i in range(3):
|
||||
results[i] = float(curve[tree.value][i][int(mean[i])])
|
||||
return results
|
||||
|
||||
def testImage(self) -> Tree:
|
||||
# load an image
|
||||
self.loadImage()
|
||||
|
||||
# load curves
|
||||
self.loadCurves()
|
||||
|
||||
# extract data
|
||||
bgr_mean, bgr_std = self.getData(self.bgr_img)
|
||||
hsv_mean, hsv_std = self.getData(self.hsv_img)
|
||||
|
||||
# correlate with curves
|
||||
av_results = np.zeros(BARK_TYPES)
|
||||
for tree in Tree:
|
||||
bgr_res = self.correlate(bgr_mean, tree, ColourSpace.BGR)
|
||||
hsv_res = self.correlate(hsv_mean, tree, ColourSpace.HSV)
|
||||
av_results[tree.value] = (np.mean(bgr_res)+np.mean(hsv_res) / 2)
|
||||
# print(str(IMG_PATH.split('_')[0])+';'+tree.name + ';' + str(np.mean(bgr_res)) + ';' + str(np.mean(hsv_res)))
|
||||
return np.argmax(av_results)
|
||||
|
||||
def testDataset(self, path : str) -> None:
|
||||
n_t = 0
|
||||
n_f = 0
|
||||
tree_type_cor = np.zeros(BARK_TYPES)
|
||||
tree_type_inc = np.zeros(BARK_TYPES)
|
||||
res = np.zeros(BARK_TYPES)
|
||||
i = -1
|
||||
last_name = ""
|
||||
for file in os.listdir(path):
|
||||
file_path = os.path.join(path, file)
|
||||
self.setImPath(file_path)
|
||||
name = file_path.split('_')[0].split('\\')[1].upper()
|
||||
result = Tree(self.testImage()).name
|
||||
|
||||
if last_name != name:
|
||||
i += 1
|
||||
last_name = name
|
||||
|
||||
if(name == result):
|
||||
tree_type_cor[i] += 1
|
||||
else:
|
||||
tree_type_inc[i] += 1
|
||||
|
||||
res = tree_type_cor / (tree_type_cor + tree_type_inc) * 100
|
||||
for i in range(BARK_TYPES):
|
||||
print("%s: %d%% correct"%(Tree(i).name, res[i]))
|
||||
return
|
||||
|
||||
if __name__ == "__main__":
|
||||
tester = colourTester()
|
||||
tester.setCsvBgrPath(CSV_PATH + "bgr_curve.csv")
|
||||
tester.setCsvHsvPath(CSV_PATH + "hsv_curve.csv")
|
||||
tester.testDataset("dataset")
|
||||
pass
|
24
src/experiments/algorithms/data/bgr_curve.csv
Normal file
24
src/experiments/algorithms/data/bgr_curve.csv
Normal file
File diff suppressed because one or more lines are too long
9
src/experiments/algorithms/data/bgr_stats.csv
Normal file
9
src/experiments/algorithms/data/bgr_stats.csv
Normal file
@ -0,0 +1,9 @@
|
||||
label,avg_b,avg_g,avg_r,std_b,std_g,std_r,
|
||||
accasia,69.59916027137541,93.23599740738842,92.76413721475456,29.650789354560942,28.164331202979742,28.33379470933227,
|
||||
berk,87.54178037532186,107.36707160860637,105.9353394079013,41.72180441785215,40.129023307835965,38.64035787139545,
|
||||
eik,103.74168566057762,119.53735094782796,117.95327527937933,34.77238255525745,33.829618649660944,32.82833612530793,
|
||||
els,138.35231618986808,177.39126510134065,181.7525877978574,51.65085237511483,43.383068821542174,42.175152137736305,
|
||||
esdoorn,47.365041621150056,77.05362430457048,69.52487212460042,25.207693719301673,24.628219686465727,22.25080719620302,
|
||||
es,63.945103048399794,95.91903641356423,90.20861703612438,20.389426811481062,18.395161770474054,17.716844447273072,
|
||||
linde,111.6252480236714,123.48265354152022,129.6323361059727,35.25451067293944,34.66671249273108,33.99378641928277,
|
||||
plataan,47.74452753592992,82.96830215527001,85.52863037536183,14.8187819404046,18.13170218888685,19.52480824126827,
|
|
24
src/experiments/algorithms/data/hsv_curve.csv
Normal file
24
src/experiments/algorithms/data/hsv_curve.csv
Normal file
File diff suppressed because one or more lines are too long
9
src/experiments/algorithms/data/hsv_stats.csv
Normal file
9
src/experiments/algorithms/data/hsv_stats.csv
Normal file
@ -0,0 +1,9 @@
|
||||
label,avg_b,avg_g,avg_r,std_b,std_g,std_r,
|
||||
accasia,35.90440242881845,79.12766192516973,96.03904497370279,10.316069136947837,32.12312271750131,28.112318716352682,
|
||||
berk,37.269905856891874,66.77426733032776,109.28940151500194,12.477741919995777,32.92938477640848,39.80902152951404,
|
||||
eik,39.76121762093227,41.20602771946309,121.12686669901616,23.03425646554001,25.365001089124593,33.494192142922856,
|
||||
els,27.25760648235924,68.91241506727702,182.27155476463224,4.423353762285157,34.149610367865485,42.029268409707505,
|
||||
esdoorn,40.44041857512247,131.63818552294646,77.84993286553097,9.535383780285505,39.540648429565636,24.46222201958771,
|
||||
es,38.37579404108352,98.88868379328436,96.68345708286985,6.84651057363783,30.56118627938561,18.229878712396474,
|
||||
linde,36.8388961321136,41.02522196067761,130.70675471758108,31.06746560545738,22.601057153094764,34.24357220627512,
|
||||
plataan,30.208627954766115,123.22600953975079,88.02246907749901,4.833302068080008,20.980674302352114,19.054660495972172,
|
|
111
src/experiments/algorithms/data/sift.csv
Normal file
111
src/experiments/algorithms/data/sift.csv
Normal file
@ -0,0 +1,111 @@
|
||||
Accasia_out
|
||||
698.7577929496765,3.1334430177115538,14.639884948730469,1.828372937292583,0.019404600608275344,4.3272259356454015,223
|
||||
835.5868207216263,3.2014820717303687,12.595267295837402,1.6907475606337812,0.019033726119218657,4.96780251711607,261
|
||||
1322.7272791862488,3.06897280553654,31.375614166259766,1.9465412537508602,0.020197111614083055,8.704955105669796,431
|
||||
616.1432831287384,2.948053986261906,10.182110786437988,1.3003369871725294,0.01828445773126121,3.8214516658335924,209
|
||||
2042.4658575057983,3.370405705455113,41.08128356933594,2.6347973287004307,0.025092723959190124,15.206190719269216,606
|
||||
679.9872843027115,3.2849627261000554,19.78511619567871,2.3892941334247926,0.020702168241971068,4.285348826088011,207
|
||||
702.1195831298828,2.901320591445797,12.382240295410156,1.3507806557012718,0.01787308056661782,4.325285497121513,242
|
||||
809.6343139410019,2.772720253222609,7.978091716766357,1.095115195842802,0.017495756149164415,5.108760795556009,292
|
||||
991.9575394392014,3.4562980468264857,37.2266845703125,3.4535018683730523,0.02128367463146249,6.108414619229734,287
|
||||
883.6591415405273,2.814201087708686,19.852262496948242,1.35472176718185,0.01984180409200252,6.230326484888792,314
|
||||
1665.44428896904,3.284899978242682,26.174636840820312,2.252376816106766,0.024839076586435062,12.593411829322577,507
|
||||
1716.247862815857,3.7391020976380327,34.431396484375,3.7368679730976226,0.027567605871488068,12.653531095013022,459
|
||||
1033.3027093410492,3.093720686649848,26.645557403564453,2.403131773101099,0.022129791454149936,7.391350345686078,334
|
||||
1002.2664128541946,3.318762956470843,17.658721923828125,2.2496636828812204,0.020582417291373212,6.21589002199471,302
|
||||
905.6036241054535,3.1554133244092455,24.95030975341797,2.079331380141301,0.01953536727326153,5.606650407426059,287
|
||||
1573.2526054382324,3.1654982000769265,22.565237045288086,1.8844591835561313,0.027768299585092117,13.800844893790781,497
|
||||
1344.9189388751984,3.0705911846465717,10.925896644592285,1.3562763371500577,0.018900907925887195,8.278597671538591,438
|
||||
2635.2527647018433,3.4313187040388584,21.754484176635742,2.423580701045881,0.03490584164925773,26.80768638662994,768
|
||||
1274.166908979416,3.201424394420643,20.968454360961914,2.089842708717911,0.01874925658790086,7.462204121984541,398
|
||||
780.677412033081,3.500795569655072,29.299978256225586,3.1758027558377497,0.017996931807743595,4.0133157931268215,223
|
||||
Berk_out
|
||||
2687.594747185707,3.7172818080023613,48.48632049560547,3.884212269938133,0.02503235707572181,18.098394165746868,723
|
||||
2449.5360144376755,3.9129968281752006,48.72830581665039,4.190141018929445,0.026578323430598925,16.638030467554927,626
|
||||
2248.9365841150284,3.6687383101387088,24.20957374572754,2.434784715027513,0.02334839300378598,14.312564911320806,613
|
||||
2386.9925570487976,3.6221434856582664,24.51873779296875,2.503845528850179,0.028970138332347226,19.091321161016822,659
|
||||
2558.578493118286,3.773714591619891,50.86576843261719,3.418055103617325,0.02585626285314384,17.530546214431524,678
|
||||
2592.295235991478,3.635757694237697,52.358192443847656,3.2337805396374515,0.024524578845538565,17.486024716868997,713
|
||||
2561.138155579567,3.2378484899868103,16.90852165222168,1.978250128109907,0.024490677895243416,19.37212621513754,791
|
||||
3345.3579272031784,3.64815477339496,39.54557418823242,2.880069078600365,0.02579340783446507,23.65255498420447,917
|
||||
2192.156372189522,3.4740988465761045,48.14958953857422,3.5506460162235087,0.027054107882283192,17.071142073720694,631
|
||||
2484.008170723915,3.5384731776693945,37.6187629699707,2.9612951727148524,0.03286086464900407,23.068326983600855,702
|
||||
1462.3458621501923,3.4735056108080578,22.076406478881836,2.3849241758099997,0.024276126959226194,10.220249449834228,421
|
||||
2419.1333129405975,3.495857388642482,29.215726852416992,2.7948339211851914,0.03273452721762261,22.652292834594846,692
|
||||
2687.440049767494,3.467664580345154,34.797386169433594,2.5354207818312107,0.026453086143780138,20.501141761429608,775
|
||||
1468.780837059021,3.2785286541496004,19.688207626342773,1.8301759005766227,0.022607883232662322,10.12833168823272,448
|
||||
Eik_out
|
||||
1579.444641828537,3.6816891417914617,19.227346420288086,2.4975664779859987,0.031246154553893006,13.4046003036201,429
|
||||
1612.8415837287903,3.895752617702392,19.052034378051758,2.577455127470621,0.030227775289564603,12.514298969879746,414
|
||||
1352.4212625026703,3.8640607500076296,15.00854206085205,2.35411413545315,0.031208549745913063,10.922992411069572,350
|
||||
1538.6859678030014,3.780555203447178,40.99676513671875,3.3523572759224476,0.029105583906027258,11.845972649753094,407
|
||||
1225.0985703468323,3.3290722020294354,19.58705711364746,2.038351397338684,0.025498346643238936,9.383391564711928,368
|
||||
1365.3871425390244,3.447947329644001,19.194652557373047,2.2193953246091485,0.025410288173441934,10.062474116683006,396
|
||||
1097.9404437541962,2.9998372780169293,12.264142990112305,1.581511211694125,0.023072358251350823,8.444483119994402,366
|
||||
1291.582367658615,3.2864691289023287,28.83696937561035,2.3913841440343515,0.022361759129560933,8.788171337917447,393
|
||||
1363.1331936120987,3.549826025031507,19.18490219116211,2.6828781845914205,0.022771707088395488,8.744335521943867,384
|
||||
Els_out
|
||||
1359.8641113042831,3.2767809910946584,19.266313552856445,1.897638219600126,0.03115534636539867,12.929468741640449,415
|
||||
1134.7650756835938,3.327756820186492,18.936323165893555,1.7635501819834738,0.03266596192182684,11.13909301534295,341
|
||||
1632.902286529541,3.5040821599346375,24.11359214782715,2.5618395036682124,0.03067660743626466,14.295299065299332,466
|
||||
1536.4152345657349,3.5565167466799417,27.18216896057129,2.786383289622822,0.030237345891590748,13.062533425167203,432
|
||||
1107.7055238485336,3.886686048591346,22.485553741455078,2.9948413624608015,0.026233021696016455,7.476411183364689,285
|
||||
1616.8189809322357,4.429641043649961,45.3355827331543,4.300393576628321,0.025648677525148815,9.361767296679318,365
|
||||
1041.9242010116577,3.2764911981498672,20.875349044799805,2.3053497977427333,0.026208830522900482,8.334408106282353,318
|
||||
1111.8425114154816,3.3897637543154926,34.425537109375,2.6968539571918693,0.02739228969780592,8.984671020880342,328
|
||||
Esdoorn_out
|
||||
1804.0408366918564,3.280074248530648,16.878116607666016,2.014352156832684,0.023109257851134647,12.710091818124056,550
|
||||
1065.8392305374146,3.125628242045204,12.645761489868164,1.5616937783846487,0.023261115867152942,7.932040510699153,341
|
||||
1443.1293832063675,3.164757419312209,13.824272155761719,1.6381495412391829,0.023636438981874994,10.778216175734997,456
|
||||
2109.4739229679108,3.3859934558072404,22.446571350097656,1.9491651806275798,0.024649366696049755,15.356555451638997,623
|
||||
566.1849731206894,3.494968969880799,14.277800559997559,2.26332032519058,0.02264520879489956,3.668523824773729,162
|
||||
654.3276780843735,3.255361582509321,14.174254417419434,2.0223312092105425,0.0228689360798369,4.596656152047217,201
|
||||
2245.0964748859406,3.6804860244031814,24.625778198242188,2.75325816629717,0.028883854125733258,17.619151016697288,610
|
||||
2144.3980325460434,3.9060073452569095,23.537641525268555,2.982770847358778,0.0322847970131995,17.724353560246527,549
|
||||
716.7942097187042,3.303199123127669,12.021895408630371,1.8694689392752937,0.022289771651033706,4.836880448274314,217
|
||||
512.756842136383,3.308108658944407,12.388520240783691,1.9337408376098448,0.022146687284111975,3.4327365290373564,155
|
||||
203.3936928510666,2.676232800671929,9.652430534362793,1.0712162703218076,0.01939073234404388,1.473695658147335,76
|
||||
69.72195136547089,2.9050813068946204,8.56438159942627,1.3172613562659046,0.019768514127160113,0.4744443390518427,24
|
||||
760.4716109037399,3.456689140471545,15.6034517288208,1.8629395593771183,0.022623810722407968,4.977238358929753,220
|
||||
1182.883133649826,3.360463447868824,19.758787155151367,2.1385583241671227,0.022289208096811886,7.845801250077784,352
|
||||
Es_out
|
||||
321.85712587833405,2.7746303955028795,8.890114784240723,1.3376489632824087,0.01832420542707731,2.125607829540968,116
|
||||
552.8187339305878,3.2328580931613318,10.130751609802246,1.8025538661742508,0.018092449095470513,3.093808795325458,171
|
||||
588.2388911247253,3.0478699022006492,9.2846097946167,1.3144556549216149,0.017584343860649693,3.3937783651053905,193
|
||||
394.3926087617874,3.1301000695379955,10.9545259475708,1.6391168134480771,0.017145832527487997,2.1603748984634876,126
|
||||
553.2564067840576,2.8372123424823465,10.358263969421387,1.350251161044622,0.018460245196444867,3.599747813306749,195
|
||||
338.75891745090485,2.7996604748008664,9.217413902282715,1.283988791527709,0.018358958323201363,2.221433957107365,121
|
||||
720.4328188896179,3.0526814359729575,12.120339393615723,1.6056232318864754,0.018135199863937194,4.279907167889178,236
|
||||
849.7654691934586,3.255806395377236,10.75560474395752,1.4615165188330932,0.018580378411459056,4.849478765390813,261
|
||||
555.6458119153976,3.388084218996327,14.520678520202637,1.953400702594663,0.01816363431081721,2.9788360269740224,164
|
||||
1692.7979286909103,3.632613580881782,20.59199333190918,2.3585647083456562,0.018669820646455615,8.700136421248317,466
|
||||
749.9521169662476,3.1643549239082174,12.163043022155762,1.6879179665006827,0.01935904413335937,4.588093459606171,237
|
||||
495.28962099552155,2.983672415635672,12.046462059020996,1.60246979233263,0.017850231289504522,2.9631383940577507,166
|
||||
547.3506425619125,3.2008809506544593,12.70744514465332,1.6010494871239151,0.017072790629116066,2.9194471975788474,171
|
||||
609.8123083114624,3.06438345885157,11.177712440490723,1.6252859374605053,0.01953577640087311,3.887619503773749,199
|
||||
1049.4082342386246,3.915702366562032,40.334678649902344,4.186340109661006,0.021392696182618836,5.733242576941848,268
|
||||
98.67310166358948,2.666840585502418,5.462077617645264,0.8816751949777557,0.018322708311717253,0.6779402075335383,37
|
||||
Linde_out
|
||||
2461.9480855464935,3.647330497105916,31.023351669311523,2.935188384240195,0.028290224722414103,19.09590168762952,675
|
||||
1867.9105838537216,3.612979852715129,32.11227035522461,2.97824320863418,0.024062555778692377,12.440341337583959,517
|
||||
2124.3844242095947,3.4099268446381936,25.51401710510254,2.3428222023628127,0.023997853738801436,14.950662879273295,623
|
||||
1271.0833770036697,3.5210065844977003,30.341659545898438,2.694577657260915,0.022613988515928676,8.163649854250252,361
|
||||
2168.191069126129,3.6379044783995456,22.332868576049805,2.5124689591930625,0.024711657454565966,14.728147842921317,596
|
||||
2013.289783000946,3.653883453722225,25.39375114440918,2.890201927887927,0.024696742919714826,13.60790534876287,551
|
||||
Plataan_out
|
||||
393.0376785993576,6.238693311100914,54.77334213256836,8.288615256835522,0.018721998817036078,1.1794859254732728,63
|
||||
121.42510282993317,3.0356275707483293,6.407865047454834,1.2202699276482052,0.018214209564030172,0.7285683825612068,40
|
||||
535.1427782773972,2.9896244596502632,13.512324333190918,2.097842298338548,0.016643719497922413,2.979225790128112,179
|
||||
90.34654986858368,3.1153982713304718,6.734649181365967,1.3800949819155952,0.015865142681989176,0.4600891377776861,29
|
||||
437.9166510105133,2.9588962906115763,11.90050983428955,1.4047910909894616,0.01991794491186738,2.9478558469563723,148
|
||||
165.1281417608261,2.580127215012908,4.76331090927124,0.7642263750567146,0.018476538331015036,1.1824984531849623,64
|
||||
232.94678628444672,2.875886250425268,9.826898574829102,1.3727227350017257,0.019708929284487243,1.5964232720434666,81
|
||||
332.89813327789307,3.78293333270333,22.732511520385742,3.045459303553181,0.019926275486465205,1.753512242808938,88
|
||||
375.2972539663315,4.415261811368605,24.255054473876953,4.276442351754282,0.017834563169847516,1.515937869437039,85
|
||||
55.11076760292053,3.061709311273363,9.913771629333496,1.935650105177096,0.017019378021359444,0.30634880438447,18
|
||||
38.28573513031006,2.3928584456443787,3.611070394515991,0.5145855975780511,0.014993195189163089,0.23989112302660942,16
|
||||
599.6391468048096,5.259992515831663,40.99736404418945,5.811482494116048,0.01938449298113323,2.2098321998491883,114
|
||||
224.61611258983612,4.0110020105327875,38.507686614990234,6.750403253193775,0.01725217021469559,0.966121532022953,56
|
||||
316.32959711551666,4.108176585915801,40.63800048828125,6.427567028038508,0.017561782018414566,1.3522572154179215,77
|
||||
138.6963803768158,2.52175237048756,6.668946743011475,0.8272403842232803,0.016272347149523823,0.8949790932238102,55
|
||||
241.65850698947906,3.0207313373684883,19.399702072143555,2.1353345471026124,0.017683570575900375,1.41468564607203,80
|
|
179
src/experiments/algorithms/distribution_csv.py
Normal file
179
src/experiments/algorithms/distribution_csv.py
Normal file
@ -0,0 +1,179 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import cv2
|
||||
import os
|
||||
import math
|
||||
|
||||
def calcNormalFunc(mean : float, sd : float, len : int):
|
||||
f = np.zeros(len, dtype=np.longdouble)
|
||||
|
||||
for x in range(len):
|
||||
exp = (-(x - mean) ** 2)/(2 * sd ** 2)
|
||||
f[x] = 1 / math.sqrt(2 * np.pi * sd** 20 ) * (math.exp(exp))
|
||||
|
||||
max = np.amax(f)
|
||||
min = np.amin(f)
|
||||
for x in range(len):
|
||||
f[x] = (f[x] - min) / (max - min)
|
||||
|
||||
return f
|
||||
|
||||
## Constants ##
|
||||
DATASET_PATH = "dataset\\"
|
||||
CSV_PATH = "src\\experiments\\algorithms\\data\\"
|
||||
BARK_TYPES = 8
|
||||
|
||||
## Arrays ##
|
||||
avgs_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||
stds_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||
wgts_bgr = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||
|
||||
avgs_hsv = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||
stds_hsv = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||
wgts_hsv = [[[],[],[]] for x in range(BARK_TYPES)]
|
||||
|
||||
labels = ["" for x in range(BARK_TYPES)]
|
||||
|
||||
## Data extraction ##
|
||||
i = -1
|
||||
last_name = ""
|
||||
for file in os.listdir(DATASET_PATH):
|
||||
# Store name + iterate tree type #
|
||||
name = file.split('_')[0]
|
||||
if(name != last_name):
|
||||
last_name = name
|
||||
i += 1
|
||||
labels[i] = name
|
||||
|
||||
# Load picture #
|
||||
im_bgr = cv2.imread(os.path.join(DATASET_PATH + file), 1)
|
||||
assert im_bgr is not None, "Something went wrong"
|
||||
im_hsv = cv2.cvtColor(im_bgr, cv2.COLOR_BGR2HSV)
|
||||
|
||||
# Data storing #
|
||||
for j in range(3):
|
||||
avgs_bgr[i][j].append(np.mean(im_bgr[:, :, j]))
|
||||
stds_bgr[i][j].append(np.std(im_bgr[:, :, j]))
|
||||
wgts_bgr[i][j].append(len(im_bgr[:, :, j]))
|
||||
|
||||
avgs_hsv[i][j].append(np.mean(im_hsv[:, :, j]))
|
||||
stds_hsv[i][j].append(np.std(im_hsv[:, :, j]))
|
||||
wgts_hsv[i][j].append(len(im_hsv[:, :, j]))
|
||||
|
||||
## Arrays ##
|
||||
w_avg_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||
w_std_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||
w_std_bgr = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||
w_avg_hsv = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||
w_std_hsv = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||
w_std_hsv = [[0, 0, 0] for x in range(BARK_TYPES)]
|
||||
|
||||
## Statistics calculations ##
|
||||
for i in range(BARK_TYPES):
|
||||
for j in range(3):
|
||||
w_avg_bgr[i][j] = np.average(
|
||||
avgs_bgr[i][j],
|
||||
weights=wgts_bgr[i][j],
|
||||
axis=0)
|
||||
w_std_bgr[i][j] = np.average(
|
||||
stds_bgr[i][j],
|
||||
weights=wgts_bgr[i][j])
|
||||
|
||||
w_avg_hsv[i][j] = np.average(
|
||||
avgs_hsv[i][j],
|
||||
weights=wgts_hsv[i][j],
|
||||
axis=0)
|
||||
w_std_hsv[i][j] = np.average(
|
||||
stds_hsv[i][j],
|
||||
weights=wgts_hsv[i][j])
|
||||
|
||||
## Plots + Normal calculations ##
|
||||
fig, axs = plt.subplots(2,4)
|
||||
row = 0
|
||||
col = -1
|
||||
colours = ('b', 'g', 'r')
|
||||
for i in range(BARK_TYPES):
|
||||
# Rows and columns #
|
||||
row = 1 if i > 3 else 0
|
||||
col += 1
|
||||
if i == 4: col = 0
|
||||
|
||||
# Normal and plotting #
|
||||
for j in range(3):
|
||||
f = calcNormalFunc(w_avg_bgr[i][j], w_std_bgr[i][j], 255)
|
||||
label = "$\mu:$ %d, $\sigma: %d$"%(w_avg_bgr[i][j],w_std_bgr[i][j])
|
||||
axs[row, col].plot(f, c=colours[j], label=label)
|
||||
|
||||
# Plot params #
|
||||
axs[row, col].grid()
|
||||
axs[row, col].legend()
|
||||
axs[row, col].set_title(str(labels[i]))
|
||||
plt.show(block=False)
|
||||
|
||||
fig, axs = plt.subplots(2,4)
|
||||
row = 0
|
||||
col = -1
|
||||
for i in range(BARK_TYPES):
|
||||
# Rows and columns #
|
||||
row = 1 if i > 3 else 0
|
||||
col += 1
|
||||
if i == 4: col = 0
|
||||
|
||||
# Normal and plotting #
|
||||
for j in range(3):
|
||||
f = calcNormalFunc(w_avg_hsv[i][j], w_std_hsv[i][j], 255)
|
||||
label = "$\mu:$ %d, $\sigma: %d$"%(w_avg_hsv[i][j], w_std_hsv[i][j])
|
||||
axs[row, col].plot(f, label=label)
|
||||
|
||||
# Plot params #
|
||||
axs[row, col].grid()
|
||||
axs[row, col].legend()
|
||||
axs[row, col].set_title(str(labels[i]))
|
||||
plt.show()
|
||||
|
||||
## CSVs ##
|
||||
# BGR mean and std #
|
||||
with open(CSV_PATH + "bgr_stats.csv", 'w', newline='') as file:
|
||||
file.write("label,avg_b,avg_g,avg_r,std_b,std_g,std_r,\n")
|
||||
for i in range(BARK_TYPES):
|
||||
file.write(labels[i] + ',')
|
||||
for j in range(3):
|
||||
file.write(str(w_avg_bgr[i][j]) + ',')
|
||||
for j in range(3):
|
||||
file.write(str(w_std_bgr[i][j]) + ',')
|
||||
file.write('\n')
|
||||
|
||||
# BGR normal curve per channel #
|
||||
id = ('B', 'G', 'R')
|
||||
with open(CSV_PATH + "bgr_curve.csv", 'w', newline='') as file:
|
||||
for i in range(BARK_TYPES):
|
||||
for j in range(3):
|
||||
file.write(labels[i] + ',')
|
||||
file.write(id[j] + ',')
|
||||
f = calcNormalFunc(w_avg_bgr[i][j], w_std_bgr[i][j], 255)
|
||||
for k in range(255):
|
||||
file.write(str(f[k]) + ',')
|
||||
file.write('\n')
|
||||
|
||||
# HSV mean and std #
|
||||
with open(CSV_PATH + "hsv_stats.csv", 'w', newline='') as file:
|
||||
file.write("label,avg_b,avg_g,avg_r,std_b,std_g,std_r,\n")
|
||||
for i in range(BARK_TYPES):
|
||||
file.write(labels[i] + ',')
|
||||
for j in range(3):
|
||||
file.write(str(w_avg_hsv[i][j]) + ',')
|
||||
for j in range(3):
|
||||
file.write(str(w_std_hsv[i][j]) + ',')
|
||||
file.write('\n')
|
||||
|
||||
# BGR normal curve per channel #
|
||||
id = ('H', 'S', 'V')
|
||||
with open(CSV_PATH + "hsv_curve.csv", 'w', newline='') as file:
|
||||
for i in range(BARK_TYPES):
|
||||
for j in range(3):
|
||||
file.write(labels[i] + ',')
|
||||
file.write(id[j] + ',')
|
||||
f = calcNormalFunc(w_avg_hsv[i][j], w_std_hsv[i][j], 255)
|
||||
for k in range(255):
|
||||
file.write(str(f[k]) + ',')
|
||||
file.write('\n')
|
37
src/experiments/algorithms/distribution_curve.py
Normal file
37
src/experiments/algorithms/distribution_curve.py
Normal file
@ -0,0 +1,37 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import math
|
||||
|
||||
mean = 125
|
||||
sd = 20
|
||||
N = 255
|
||||
f = np.zeros(N, dtype=np.longdouble)
|
||||
|
||||
def calcNormalFunc(mean, sd, len):
|
||||
f = np.zeros(len, dtype=np.longdouble)
|
||||
|
||||
# calculate PDF
|
||||
for x in range(len):
|
||||
exp = (-(x - mean) ** 2)/(2 * sd ** 2)
|
||||
f[x] = 1 / math.sqrt(2 * np.pi * sd** 20 ) * (math.exp(exp))
|
||||
|
||||
# normalize PDF
|
||||
max = np.amax(f)
|
||||
min = np.amin(f)
|
||||
for x in range(len):
|
||||
f[x] = (f[x] - min) / (max - min)
|
||||
|
||||
return f
|
||||
|
||||
f = calcNormalFunc(mean, sd, N)
|
||||
|
||||
plt.title("PDF: $\mu = %d$, $\sigma = %d$"%(mean, sd))
|
||||
plt.plot(f)
|
||||
plt.grid()
|
||||
plt.xlim(0, 255)
|
||||
plt.ylim(0, 1.05)
|
||||
plt.show()
|
||||
|
||||
print("Score at 1 sigma: %f"%f[sd+mean])
|
||||
print("Score at 2 sigma: %f"%f[2*sd+mean])
|
||||
print("Score at 3 sigma: %f"%f[3*sd+mean])
|
86
src/experiments/algorithms/sift_plot.py
Normal file
86
src/experiments/algorithms/sift_plot.py
Normal file
@ -0,0 +1,86 @@
|
||||
import numpy as np
|
||||
import matplotlib.pyplot as plt
|
||||
import csv
|
||||
|
||||
def isFloat(num):
|
||||
try:
|
||||
float(num)
|
||||
return True
|
||||
except ValueError:
|
||||
return False
|
||||
|
||||
DATA_PATH = "src\\experiments\\algorithms\\data\\data.csv"
|
||||
BARK_TYPES = 8
|
||||
|
||||
tot_mag = [["", []] for x in range(BARK_TYPES)]
|
||||
avg_mag = [["", []] for x in range(BARK_TYPES)]
|
||||
max_mag = [["", []] for x in range(BARK_TYPES)]
|
||||
std_mag = [["", []] for x in range(BARK_TYPES)]
|
||||
avg_rep = [["", []] for x in range(BARK_TYPES)]
|
||||
max_rep = [["", []] for x in range(BARK_TYPES)]
|
||||
counts = [["", []] for x in range(BARK_TYPES)]
|
||||
i = 0
|
||||
|
||||
with open(DATA_PATH, 'r') as file:
|
||||
reader = csv.reader(file, delimiter=',')
|
||||
for row in reader:
|
||||
if isFloat(row[0]):
|
||||
tot_mag[i-1][1].append(float(row[0]))
|
||||
avg_mag[i-1][1].append(float(row[1]))
|
||||
max_mag[i-1][1].append(float(row[2]))
|
||||
std_mag[i-1][1].append(float(row[3]))
|
||||
avg_rep[i-1][1].append(float(row[4]))
|
||||
max_rep[i-1][1].append(float(row[5]))
|
||||
counts[i-1][1].append(float(row[6]))
|
||||
else:
|
||||
tot_mag[i][0] = row[0]
|
||||
avg_mag[i][0] = row[0]
|
||||
max_mag[i][0] = row[0]
|
||||
std_mag[i][0] = row[0]
|
||||
avg_rep[i][0] = row[0]
|
||||
max_rep[i][0] = row[0]
|
||||
counts[i][0] = row[0]
|
||||
i += 1
|
||||
|
||||
fig, axs = plt.subplots(2, 3)
|
||||
|
||||
for i in range(BARK_TYPES):
|
||||
axs[0, 0].scatter(tot_mag[i][1], avg_mag[i][1], label=tot_mag[i][0], alpha=0.6)
|
||||
axs[0, 1].scatter(tot_mag[i][1], max_mag[i][1], label=tot_mag[i][0], alpha=0.6)
|
||||
axs[1, 0].scatter(tot_mag[i][1], std_mag[i][1], label=tot_mag[i][0], alpha=0.6)
|
||||
axs[1, 1].scatter(tot_mag[i][1], counts[i][1], label=tot_mag[i][0], alpha=0.6)
|
||||
axs[0, 2].scatter(tot_mag[i][1], avg_rep[i][1], label=tot_mag[i][0], alpha=0.6)
|
||||
axs[1, 2].scatter(avg_rep[i][1], max_rep[i][1], label=tot_mag[i][0], alpha=0.6)
|
||||
|
||||
|
||||
axs[0, 0].set_xlabel("Total")
|
||||
axs[0, 0].set_ylabel("Average")
|
||||
axs[0, 0].grid()
|
||||
axs[0, 0].legend()
|
||||
|
||||
axs[0, 1].set_xlabel("Total")
|
||||
axs[0, 1].set_ylabel("Maximum")
|
||||
axs[0, 1].grid()
|
||||
axs[0, 1].legend()
|
||||
|
||||
axs[1, 0].set_xlabel("Total")
|
||||
axs[1, 0].set_ylabel("Standard deviation")
|
||||
axs[1, 0].grid()
|
||||
axs[1, 0].legend()
|
||||
|
||||
axs[1, 1].set_xlabel("Total")
|
||||
axs[1, 1].set_ylabel("Count")
|
||||
axs[1, 1].grid()
|
||||
axs[1, 1].legend()
|
||||
|
||||
axs[0, 2].set_xlabel("Total")
|
||||
axs[0, 2].set_ylabel("Average response")
|
||||
axs[0, 2].grid()
|
||||
axs[0, 2].legend()
|
||||
|
||||
axs[1, 2].set_xlabel("Average response")
|
||||
axs[1, 2].set_ylabel("Max response")
|
||||
axs[1, 2].grid()
|
||||
axs[1, 2].legend()
|
||||
|
||||
plt.show()
|
@ -1,69 +0,0 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import os
|
||||
import matplotlib.pyplot as plt
|
||||
import math
|
||||
|
||||
avg_magnitudes = np.zeros(10)
|
||||
max_magnitudes = np.zeros(10)
|
||||
avg_angle = np.zeros(10)
|
||||
counts = np.zeros(10)
|
||||
i = 0
|
||||
|
||||
for filename in os.listdir(os.path.join(os.getcwd(), "./res/trees/")):
|
||||
## Load an image ##
|
||||
directory = os.path.join(os.getcwd(), "./res/trees/")
|
||||
path = os.path.join(directory, filename)
|
||||
img = cv2.imread(path, 0)
|
||||
|
||||
## Detect Keypoints ##
|
||||
sift = cv2.SIFT.create(enable_precise_upscale=True)
|
||||
kp = sift.detect(img, None)
|
||||
img = cv2.drawKeypoints(
|
||||
img,
|
||||
kp,
|
||||
img,
|
||||
flags=cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
|
||||
|
||||
## Average and Max size ##
|
||||
magnitudes = [keypoint.size for keypoint in kp]
|
||||
max_magnitudes[i] = np.amax(magnitudes)
|
||||
avg_magnitudes[i] = np.sum(magnitudes)/len(kp)
|
||||
|
||||
## Number of keypoints ##
|
||||
counts[i] = len(kp)
|
||||
|
||||
## Average angle ##
|
||||
angle_radians = [math.radians(keypoint.angle) for keypoint in kp]
|
||||
sum_sin = sum(math.sin(angle) for angle in angle_radians)
|
||||
sum_cos = sum(math.cos(angle) for angle in angle_radians)
|
||||
avg_angle_rad = math.atan2(sum_sin, sum_cos)
|
||||
avg_angle[i] = math.degrees(avg_angle_rad) % 360
|
||||
|
||||
i += 1
|
||||
# break
|
||||
# cv2.imshow("output", img)
|
||||
# cv2.waitKey(0)
|
||||
|
||||
|
||||
plt.scatter(counts, avg_magnitudes)
|
||||
plt.title("Hoeveelheid keypoints vs gemiddelde magnitude")
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
plt.scatter(counts, max_magnitudes)
|
||||
plt.title("Hoeveelheid keypoints vs maximale magnitude")
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
plt.scatter(avg_magnitudes, max_magnitudes)
|
||||
plt.title("gemiddelde magnitude vs maximale magnitude")
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
plt.scatter(counts, avg_angle)
|
||||
plt.title("Hoeveelheid keypoints vs gemiddelde hoek")
|
||||
plt.grid()
|
||||
plt.show()
|
||||
|
||||
cv2.destroyAllWindows()
|
@ -2,13 +2,14 @@ import numpy as np
|
||||
import cv2
|
||||
import os
|
||||
import matplotlib.pyplot as plt
|
||||
import csv
|
||||
import pandas as pd
|
||||
|
||||
DATASET_PATH = "C:\\Users\\tomse\\Downloads\\Dataset\\"
|
||||
DATASET_PATH = "C:\\Users\\Tom\\Downloads\\Dataset_out\\"
|
||||
CSV_PATH = "C:\\Users\\Tom\\Desktop\\Files\\Repositories\\EV5_Beeldherk_Bomen\\src\\experiments\\algorithms\\data\\"
|
||||
DATASET_FOLDERS_LEN = len(os.listdir(DATASET_PATH))
|
||||
EARLY_BREAK = 0
|
||||
SCALE = 1
|
||||
|
||||
# Plataan, Berk, Accasia
|
||||
SCALE = .25
|
||||
|
||||
sift = cv2.SIFT.create(enable_precise_upscale=True)
|
||||
|
||||
@ -16,6 +17,9 @@ sift = cv2.SIFT.create(enable_precise_upscale=True)
|
||||
max_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
avg_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
tot_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
std_magnitudes = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
max_responses = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
avg_responses = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
counts = [[] for x in range(DATASET_FOLDERS_LEN)]
|
||||
|
||||
## Create other variables ##
|
||||
@ -50,17 +54,23 @@ for folder in os.listdir(DATASET_PATH):
|
||||
tot_magnitudes[i].append(np.sum(magnitudes))
|
||||
max_magnitudes[i].append(np.amax(magnitudes))
|
||||
avg_magnitudes[i].append(np.sum(magnitudes)/len(kp))
|
||||
std_magnitudes[i].append(np.std(magnitudes))
|
||||
|
||||
## Number of keypoints ##
|
||||
counts[i].append(len(kp))
|
||||
|
||||
## Response ##
|
||||
responses = [keypoint.response for keypoint in kp]
|
||||
max_responses[i].append(np.sum(responses))
|
||||
avg_responses[i].append(np.mean(responses))
|
||||
|
||||
# cv2.imshow("Opencv tech", image)
|
||||
# cv2.waitKey(0)
|
||||
|
||||
## Store labels ##
|
||||
labels[i] = folder
|
||||
|
||||
## Increment folder ##
|
||||
## Increment arrays ##
|
||||
i += 1
|
||||
|
||||
if(i == EARLY_BREAK):
|
||||
@ -68,8 +78,21 @@ for folder in os.listdir(DATASET_PATH):
|
||||
|
||||
print("Done!")
|
||||
|
||||
## CSV ##
|
||||
with open(CSV_PATH + "sift.csv" , 'w', newline='') as file:
|
||||
for i in range(len(labels)):
|
||||
file.write(labels[i] + '\n')
|
||||
for j in range(len(tot_magnitudes[i])):
|
||||
file.write(str(tot_magnitudes[i][j]) + ',')
|
||||
file.write(str(avg_magnitudes[i][j]) + ',')
|
||||
file.write(str(max_magnitudes[i][j]) + ',')
|
||||
file.write(str(std_magnitudes[i][j]) + ',')
|
||||
file.write(str(avg_responses[i][j]) + ',')
|
||||
file.write(str(max_responses[i][j]) + ',')
|
||||
file.write(str(counts[i][j]) + '\n')
|
||||
|
||||
## Plots ##
|
||||
fig, ax = plt.subplots()
|
||||
# fig, ax = plt.subplots()
|
||||
# for i in range(DATASET_FOLDERS_LEN):
|
||||
# ax.scatter(tot_magnitudes[i], max_magnitudes[i],label=labels[i], alpha=0.7)
|
||||
# ax.scatter(avg_magnitudes[0], max_magnitudes[0], label=labels[0], alpha=0.7)
|
||||
@ -80,11 +103,11 @@ fig, ax = plt.subplots()
|
||||
# ax.grid(True)
|
||||
# plt.show()
|
||||
|
||||
ax.scatter(tot_magnitudes[2], max_magnitudes[2], label='Berk', alpha=0.7)
|
||||
ax.scatter(tot_magnitudes[3], max_magnitudes[3], label='Els', alpha=0.7)
|
||||
ax.scatter(tot_magnitudes[7], max_magnitudes[7], label='Plataan', alpha=0.7)
|
||||
ax.set_xlabel("Total magnitude")
|
||||
ax.set_ylabel("Maximal magnitude")
|
||||
ax.legend()
|
||||
ax.grid(True)
|
||||
plt.show()
|
||||
# ax.scatter(tot_magnitudes[2], max_magnitudes[2], label='Berk', alpha=0.7)
|
||||
# ax.scatter(tot_magnitudes[3], max_magnitudes[3], label='Els', alpha=0.7)
|
||||
# ax.scatter(tot_magnitudes[7], max_magnitudes[7], label='Plataan', alpha=0.7)
|
||||
# ax.set_xlabel("Total magnitude")
|
||||
# ax.set_ylabel("Maximal magnitude")
|
||||
# ax.legend()
|
||||
# ax.grid(True)
|
||||
# plt.show()
|
@ -92,13 +92,16 @@ detector_params.adaptiveThreshWinSizeMax = 150 # Takes longer, but better chance
|
||||
dictionary = cv2.aruco.getPredefinedDictionary(cv2.aruco.DICT_ARUCO_ORIGINAL)
|
||||
detector = cv2.aruco.ArucoDetector(dictionary, detector_params)
|
||||
|
||||
images_converted = 0
|
||||
images_skipped = 0
|
||||
|
||||
### IMAGE CONVERSIE ###
|
||||
for folder in os.listdir(input_directory):
|
||||
if folder.endswith('.py'):
|
||||
print("Skipping", folder)
|
||||
continue
|
||||
|
||||
if folder.endswith('.jpg'):
|
||||
if folder.lower().endswith('.jpg'):
|
||||
continue
|
||||
|
||||
if SAVE:
|
||||
@ -147,10 +150,12 @@ for folder in os.listdir(input_directory):
|
||||
if ids is None:
|
||||
print("Skipping: ", filename)
|
||||
print("=============================================")
|
||||
images_skipped += 1
|
||||
continue
|
||||
if len(ids) != 4:
|
||||
print("Skipping: ", filename)
|
||||
print("=============================================")
|
||||
images_skipped += 1
|
||||
continue
|
||||
|
||||
if VERBOSE:
|
||||
@ -246,5 +251,10 @@ for folder in os.listdir(input_directory):
|
||||
cv2.waitKey(0)
|
||||
if VERBOSE:
|
||||
print("=============================================")
|
||||
images_converted += 1
|
||||
|
||||
if VERBOSE:
|
||||
print("%d van de %d succesvol"
|
||||
%(images_converted, (images_converted+images_skipped)))
|
||||
|
||||
cv2.destroyAllWindows()
|
@ -1,4 +1,5 @@
|
||||
import numpy as np
|
||||
import math
|
||||
|
||||
def imgStats(img):
|
||||
mean = np.zeros(3)
|
||||
@ -7,3 +8,19 @@ def imgStats(img):
|
||||
mean[i] = np.mean(img[:, :, i])
|
||||
std[i] = np.std(img[:, :, i])
|
||||
return mean, std
|
||||
|
||||
def calcNormalFunc(mean, sd, len):
|
||||
f = np.zeros(len, dtype=np.longdouble)
|
||||
|
||||
# calculate PDF
|
||||
for x in range(len):
|
||||
exp = (-(x - mean) ** 2)/(2 * sd ** 2)
|
||||
f[x] = 1 / math.sqrt(2 * np.pi * sd** 20 ) * (math.exp(exp))
|
||||
|
||||
# normalize PDF
|
||||
max = np.amax(f)
|
||||
min = np.amin(f)
|
||||
for x in range(len):
|
||||
f[x] = (f[x] - min) / (max - min)
|
||||
|
||||
return f
|
@ -282,6 +282,9 @@ class MainApp:
|
||||
for file in glob.glob(path + "/*.jpg"):
|
||||
images.append(file)
|
||||
|
||||
for file in glob.glob(path + "/*.png"):
|
||||
images.append(file)
|
||||
|
||||
self.img_max = len(images)
|
||||
self.img_name = os.path.split(images[self.img_current])
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user