From b5143c51d2d92767f4e5c315268687499c7bed46 Mon Sep 17 00:00:00 2001 From: Tom Selier Date: Thu, 28 Sep 2023 20:57:10 +0200 Subject: [PATCH] Added more statistics to sift --- src/experiments/algorithms/data/data.csv | 111 +++++++++++++++++++++++ src/experiments/algorithms/sift_plot.py | 86 ++++++++++++++++++ src/experiments/algorithms/sift_v3.py | 66 +++++++++++--- 3 files changed, 249 insertions(+), 14 deletions(-) create mode 100644 src/experiments/algorithms/data/data.csv create mode 100644 src/experiments/algorithms/sift_plot.py diff --git a/src/experiments/algorithms/data/data.csv b/src/experiments/algorithms/data/data.csv new file mode 100644 index 0000000..aa803bc --- /dev/null +++ b/src/experiments/algorithms/data/data.csv @@ -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 diff --git a/src/experiments/algorithms/sift_plot.py b/src/experiments/algorithms/sift_plot.py new file mode 100644 index 0000000..6ac684c --- /dev/null +++ b/src/experiments/algorithms/sift_plot.py @@ -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 = "C:\\Users\\Tom\\Desktop\\Files\\Repositories\\EV5_Beeldherk_Bomen\\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() diff --git a/src/experiments/algorithms/sift_v3.py b/src/experiments/algorithms/sift_v3.py index ddef7fc..8e8dbb7 100644 --- a/src/experiments/algorithms/sift_v3.py +++ b/src/experiments/algorithms/sift_v3.py @@ -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,36 @@ for folder in os.listdir(DATASET_PATH): print("Done!") +## Pandas ## +with open(CSV_PATH + "data.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') + +## CSV ## +# with open(CSV_PATH + "data.csv" , 'w', newline='') as file: + # writer = csv.writer(file, delimiter=',') + + # for i in range(len(tot_magnitudes)): + # writer.writerow(tot_magnitudes[i]) + # writer.writerow(avg_magnitudes[i]) + # writer.writerow(max_magnitudes[i]) + # writer.writerow(counts[i]) + # writer.writerow('') + + # writer.writerows(max_magnitudes) + # writer.writerows(avg_magnitudes) + # writer.writerows(counts) + ## 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 +118,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() \ No newline at end of file +# 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() \ No newline at end of file