diff options
author | leochanj105 <leochanj@live.unc.edu> | 2020-10-19 23:09:30 -0400 |
---|---|---|
committer | leochanj105 <leochanj@live.unc.edu> | 2020-10-20 02:40:39 -0400 |
commit | f618466c25d43f3bae9e40920273bf77de1e1149 (patch) | |
tree | 460e739e2165b8a9c37a9c7ab1b60f5874903543 /SD-VBS/benchmarks/texture_synthesis/src/matlab/entropy2.m | |
parent | 47ced4e96bbb782b9e780e8f2cfc637b2c21ff44 (diff) |
initial sd-vbs
initial sd-vbs
add sd-vbs
sd-vbs
Diffstat (limited to 'SD-VBS/benchmarks/texture_synthesis/src/matlab/entropy2.m')
-rwxr-xr-x | SD-VBS/benchmarks/texture_synthesis/src/matlab/entropy2.m | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/SD-VBS/benchmarks/texture_synthesis/src/matlab/entropy2.m b/SD-VBS/benchmarks/texture_synthesis/src/matlab/entropy2.m new file mode 100755 index 0000000..68a2a9f --- /dev/null +++ b/SD-VBS/benchmarks/texture_synthesis/src/matlab/entropy2.m | |||
@@ -0,0 +1,31 @@ | |||
1 | % E = ENTROPY2(MTX,BINSIZE) | ||
2 | % | ||
3 | % Compute the first-order sample entropy of MTX. Samples of VEC are | ||
4 | % first discretized. Optional argument BINSIZE controls the | ||
5 | % discretization, and defaults to 256/(max(VEC)-min(VEC)). | ||
6 | % | ||
7 | % NOTE: This is a heavily biased estimate of entropy when you | ||
8 | % don't have much data. | ||
9 | |||
10 | % Eero Simoncelli, 6/96. | ||
11 | |||
12 | function res = entropy2(mtx,binsize) | ||
13 | |||
14 | %% Ensure it's a vector, not a matrix. | ||
15 | vec = mtx(:); | ||
16 | [mn,mx] = range2(vec); | ||
17 | |||
18 | if (exist('binsize') == 1) | ||
19 | nbins = max((mx-mn)/binsize, 1); | ||
20 | else | ||
21 | nbins = 256; | ||
22 | end | ||
23 | |||
24 | [bincount,bins] = histo(vec,nbins); | ||
25 | |||
26 | %% Collect non-zero bins: | ||
27 | H = bincount(find(bincount)); | ||
28 | H = H/sum(H); | ||
29 | |||
30 | res = -sum(H .* log2(H)); | ||
31 | |||