Closed mtxslv closed 4 years ago
Here we go, up to this moment I already have the frames for calibration code (calcula_media_variancia_hsv_2
). I plan to suit the calibration code such that I'd only need to apply blob_colours_2
inside it and get as far as possible.
I can already see I'll need something to arrange the blobs' colours so I can averave them properly. I'll need to be careful not to average different blobs colours (like summing red blob average colour from i-th frame to what I believe is the red blob average colour from i+1-th frame).
Anyway, blob_colours_2
need the following inputs:
As I said before, I have already got all the calibration frames from the video. The threshold values are manually selected. I still need the boundingbox
,ndetect
and wframe_log
.
to test , use this: [media, variancia] = calcula_media_variancia_hsv_2(video, tempo_inicial, tempo_final, wbackg,Vrm, nanimais, mascara, minpix, maxpix, threshold, aviobj2, criavideodiff, tipsubfundo, caixa, l, c, colorida, cor, tipfilt , INTENSO)
We will use kmeans to find the blobs' mean. Here we have some instructions:
>> load('C:\Users\mateu\Documents\zebtrack\ZebTrack\test_variables_and_results\variaveis_calculaMediaVarianciaHSV.mat')
>> [media, variancia] = calcula_media_variancia_hsv_2(video, tempo_inicial, tempo_final, wbackg,Vrm, nanimais, mascara, minpix, maxpix, threshold, aviobj2, criavideodiff, tipsubfundo, caixa, l, c, colorida, cor, tipfilt , INTENSO);
>> [idx,C] = kmeans(media, 2,'Replicates',5);
I am using 5 kmeans replicates (run 5 times and get persistent cluster centroids) because it is MATLAB example. It is very important to use kmeans replicates, to guarantee the picked centroids won't be wrong.
To plot kmeans result, run this:
figure;
plot3(media(idx==1,1),media(idx==1,2),media(idx==1,3),'r.','MarkerSize',12)
hold on
plot3(media(idx==2,1),media(idx==2,2),media(idx==2,3),'b.','MarkerSize',12)
plot3(C(:,1),C(:,2),C(:,3),'kx','MarkerSize',15,'LineWidth',3)
legend('Cluster 1','Cluster 2','Centroids','Location','NW')
title 'Cluster Assignments and Centroids'
hold off
value_threshold = 0.15 saturation_threshold = 0.5
calcula_media_variancia_hsv_2.m
is out now! Here you have how to test it:
[media,variancia] = calcula_media_variancia_hsv_2(video, tempo_inicial, tempo_final, wbackg,Vrm, nanimais, mascara, minpix, maxpix, threshold, aviobj2, criavideodiff, tipsubfundo, colorida, cor, 0.15,0.5,5)
If everything is fine, the result must be:
media =
23.3055 25.0995 57.2719
72.8047 22.3412 30.9006
variancia =
25.5100 34.3325 143.4295
24.3727 22.9286 39.1767
I test swaping thresholds. This made an error appear on variance concatenation (on line 37). To this example, means were null vectors.
this test was made while using var
instead of cov
(on line 37). Be careful while using such test!
I just changed variance by covariance (also changed variable var
from array to cell). After running the code, the result must equal:
24.3727 -0.4904 3.7522
-0.4904 22.9286 20.8271
3.7522 20.8271 39.1767
25.5100 27.2358 56.3421
27.2358 34.3325 63.7181
56.3421 63.7181 143.4295
Each 3x3 grid is a variance matrix. They are associated to the centroids:
media =
72.8047 22.3412 30.9006
23.3055 25.0995 57.2719
just changed file, function call and returned variables' names:
[media,variancia] = calcula_centroids_cov_rgb(video, tempo_inicial, tempo_final, wbackg,Vrm, nanimais, mascara, minpix, maxpix, threshold, aviobj2, criavideodiff, tipsubfundo, colorida, cor, 0.15,0.5,5)
Aparently, from line 85 to line 183 on file
calculaMediaVarianciaHSV.m
we haveblob_colours
file.