|
| 1 | +function information=computeEntropy(points,Vnorm) |
| 2 | + |
| 3 | + |
| 4 | +global MemoPoints; |
| 5 | + |
| 6 | +totalPoints = size(Vnorm,1)*size(Vnorm,2); |
| 7 | + |
| 8 | +information = 0; |
| 9 | +%for each point |
| 10 | + |
| 11 | +%MemoPoints |
| 12 | + |
| 13 | +for i=1:length(points) |
| 14 | + |
| 15 | + % Take a patch |
| 16 | + |
| 17 | + %Vpatch = Vnorm(points(i,1)-1:points(i,1)+1,points(i,2)-1:points(i,2)+1,:); |
| 18 | + |
| 19 | + entropyPatch =0; |
| 20 | + points=int32(points); |
| 21 | + size(points) |
| 22 | + %VpatchVec = reshape(Vpatch,size(Vpatch,1)*size(Vpatch,2), 4); |
| 23 | + |
| 24 | + |
| 25 | + %for j=1:length(VpatchVec) |
| 26 | + if(MemoPoints(points(i,1)-1,points(i,2)-1) == -1) |
| 27 | + |
| 28 | + Vpoint = Vnorm(points(i,1)-1,points(i,2)-1,:); |
| 29 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 30 | + prob =count/totalPoints; |
| 31 | + |
| 32 | + MemoPoints(points(i,1)-1,points(i,2)-1) = prob; |
| 33 | + entropyPatch = entropyPatch -prob*log(prob); |
| 34 | + else |
| 35 | + prob = MemoPoints(points(i,1)-1,points(i,2)-1); |
| 36 | + entropyPatch = entropyPatch -prob*log(prob); |
| 37 | + % 'memo' |
| 38 | + end |
| 39 | + |
| 40 | + if(MemoPoints(points(i,1),points(i,2)-1) == -1) |
| 41 | + Vpoint = Vnorm(points(i,1),points(i,2)-1,:); |
| 42 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 43 | + prob =count/totalPoints; |
| 44 | + |
| 45 | + MemoPoints(points(i,1),points(i,2)-1) = prob; |
| 46 | + entropyPatch = entropyPatch -prob*log(prob); |
| 47 | + else |
| 48 | + prob = MemoPoints(points(i,1),points(i,2)-1); |
| 49 | + entropyPatch = entropyPatch -prob*log(prob); |
| 50 | + %'memo' |
| 51 | + end |
| 52 | + |
| 53 | + if(MemoPoints(points(i,1)+1,points(i,2)-1) == -1) |
| 54 | + Vpoint = Vnorm(points(i,1)+1,points(i,2)-1,:); |
| 55 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 56 | + prob =count/totalPoints; |
| 57 | + |
| 58 | + MemoPoints(points(i,1)+1,points(i,2)-1) = prob; |
| 59 | + entropyPatch = entropyPatch -prob*log(prob); |
| 60 | + else |
| 61 | + prob = MemoPoints(points(i,1)+1,points(i,2)-1); |
| 62 | + entropyPatch = entropyPatch -prob*log(prob); |
| 63 | + % 'memo' |
| 64 | + end |
| 65 | + |
| 66 | + |
| 67 | + |
| 68 | + if(MemoPoints(points(i,1)-1,points(i,2)) == -1) |
| 69 | + Vpoint = Vnorm(points(i,1)-1,points(i,2),:); |
| 70 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 71 | + prob =count/totalPoints; |
| 72 | + |
| 73 | + MemoPoints(points(i,1)-1,points(i,2)) = prob; |
| 74 | + entropyPatch = entropyPatch -prob*log(prob); |
| 75 | + else |
| 76 | + prob = MemoPoints(points(i,1)-1,points(i,2)); |
| 77 | + entropyPatch = entropyPatch -prob*log(prob); |
| 78 | + % 'memo' |
| 79 | + end |
| 80 | + |
| 81 | + if(MemoPoints(points(i,1),points(i,2)) == -1) |
| 82 | + Vpoint = Vnorm(points(i,1),points(i,2),:); |
| 83 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 84 | + prob =count/totalPoints; |
| 85 | + |
| 86 | + MemoPoints(points(i,1),points(i,2)) = prob; |
| 87 | + entropyPatch = entropyPatch -prob*log(prob); |
| 88 | + else |
| 89 | + prob = MemoPoints(points(i,1),points(i,2)); |
| 90 | + entropyPatch = entropyPatch -prob*log(prob); |
| 91 | + % 'memo' |
| 92 | + end |
| 93 | + |
| 94 | + if(MemoPoints(points(i,1)+1,points(i,2)) == -1) |
| 95 | + Vpoint = Vnorm(points(i,1)+1,points(i,2),:); |
| 96 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 97 | + prob =count/totalPoints; |
| 98 | + |
| 99 | + MemoPoints(points(i,1)+1,points(i,2)) = prob; |
| 100 | + entropyPatch = entropyPatch -prob*log(prob); |
| 101 | + else |
| 102 | + prob = MemoPoints(points(i,1)+1,points(i,2)); |
| 103 | + entropyPatch = entropyPatch -prob*log(prob); |
| 104 | + % 'memo' |
| 105 | + end |
| 106 | + |
| 107 | + if(MemoPoints(points(i,1)-1,points(i,2)+1) == -1) |
| 108 | + Vpoint = Vnorm(points(i,1)-1,points(i,2)+1,:); |
| 109 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 110 | + prob =count/totalPoints; |
| 111 | + |
| 112 | + MemoPoints(points(i,1)-1,points(i,2)+1) = prob; |
| 113 | + entropyPatch = entropyPatch -prob*log(prob); |
| 114 | + else |
| 115 | + prob = MemoPoints(points(i,1)-1,points(i,2)+1); |
| 116 | + entropyPatch = entropyPatch -prob*log(prob); |
| 117 | + % 'memo' |
| 118 | + end |
| 119 | + |
| 120 | + |
| 121 | + if(MemoPoints(points(i,1),points(i,2)+1) == -1) |
| 122 | + Vpoint = Vnorm(points(i,1),points(i,2)+1,:); |
| 123 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 124 | + prob =count/totalPoints; |
| 125 | + |
| 126 | + MemoPoints(points(i,1),points(i,2)+1) = prob; |
| 127 | + entropyPatch = entropyPatch -prob*log(prob); |
| 128 | + else |
| 129 | + prob = MemoPoints(points(i,1),points(i,2)+1); |
| 130 | + entropyPatch = entropyPatch -prob*log(prob); |
| 131 | + % 'memo' |
| 132 | + end |
| 133 | + |
| 134 | + |
| 135 | + if(MemoPoints(points(i,1)+1,points(i,2)+1) == -1) |
| 136 | + Vpoint = Vnorm(points(i,1)+1,points(i,2)+1,:); |
| 137 | + count = sum(sum(Vnorm(:,:,1) == Vpoint(1) & Vnorm(:,:,2) == Vpoint(2) & Vnorm(:,:,3) == Vpoint(3) & Vnorm(:,:,4) == Vpoint(4))); |
| 138 | + prob =count/totalPoints; |
| 139 | + |
| 140 | + MemoPoints(points(i,1)+1,points(i,2)+1) = prob; |
| 141 | + entropyPatch = entropyPatch -prob*log(prob); |
| 142 | + |
| 143 | + |
| 144 | + else |
| 145 | + prob = MemoPoints(points(i,1)+1,points(i,2)+1); |
| 146 | + entropyPatch = entropyPatch -prob*log(prob); |
| 147 | + % 'memo' |
| 148 | + end |
| 149 | + |
| 150 | + |
| 151 | + |
| 152 | + |
| 153 | + |
| 154 | + %end |
| 155 | + |
| 156 | + information = information + entropyPatch |
| 157 | + %else |
| 158 | + |
| 159 | +end |
| 160 | + |
| 161 | + % DO a memoization. |
| 162 | + |
| 163 | + |
| 164 | +end |
| 165 | + |
| 166 | + |
0 commit comments