| 1105 | } |
| 1106 | |
| 1107 | CGV_FLOAT GetQuantizeIndex(CGV_UINT32 index_packed_out[2], |
| 1108 | CGV_UINT8 index_out[MAX_SUBSET_SIZE], // OUT: |
| 1109 | CGV_FLOAT image_src[SOURCE_BLOCK_SIZE * MAX_CHANNELS], |
| 1110 | CGV_INT numEntries, //IN: range 0..15 (MAX_SUBSET_SIZE) |
| 1111 | CGU_INT numClusters, |
| 1112 | CGU_UINT8 channels3or4) |
| 1113 | { // IN: 3 = RGB or 4 = RGBA (4 = MAX_CHANNELS) |
| 1114 | CGV_FLOAT image_centered[SOURCE_BLOCK_SIZE * MAX_CHANNELS]; |
| 1115 | CGV_FLOAT image_mean[MAX_CHANNELS]; |
| 1116 | CGV_FLOAT eigen_vector[MAX_CHANNELS]; |
| 1117 | CGV_FLOAT covariance_vector[MAX_CHANNELS * MAX_CHANNELS]; |
| 1118 | |
| 1119 | GetImageCentered(image_centered, image_mean, image_src, numEntries, channels3or4); |
| 1120 | GetCovarianceVector(covariance_vector, image_centered, numEntries, channels3or4); |
| 1121 | |
| 1122 | //----------------------------------------------------- |
| 1123 | // check if all covariances are the same |
| 1124 | // if so then set all index to same value 0 and return |
| 1125 | // use EPSILON to set the limit for all same limit |
| 1126 | //----------------------------------------------------- |
| 1127 | |
| 1128 | CGV_FLOAT image_covt = 0.0F; |
| 1129 | for (CGU_UINT8 ch = 0; ch < channels3or4; ch++) |
| 1130 | image_covt = image_covt + covariance_vector[ch + ch * 4]; |
| 1131 | |
| 1132 | if (image_covt < EPSILON) |
| 1133 | { |
| 1134 | SetDefaultIndex(index_out); |
| 1135 | index_packed_out[0] = 0; |
| 1136 | index_packed_out[1] = 0; |
| 1137 | return 0.; |
| 1138 | } |
| 1139 | |
| 1140 | GetEigenVector(eigen_vector, covariance_vector, channels3or4); |
| 1141 | |
| 1142 | CGV_FLOAT image_projected[SOURCE_BLOCK_SIZE]; |
| 1143 | |
| 1144 | GetProjecedImage(image_projected, image_centered, numEntries, eigen_vector, channels3or4); |
| 1145 | GetProjectedIndex(index_out, image_projected, numClusters, numEntries); |
| 1146 | |
| 1147 | //========================================== |
| 1148 | // Refine |
| 1149 | //========================================== |
| 1150 | CGV_FLOAT image_q = 0.0F; |
| 1151 | for (CGU_UINT8 ch = 0; ch < channels3or4; ch++) |
| 1152 | { |
| 1153 | eigen_vector[ch] = 0; |
| 1154 | for (CGV_INT k = 0; k < numEntries; k++) |
| 1155 | eigen_vector[ch] = eigen_vector[ch] + image_centered[k + (ch * SOURCE_BLOCK_SIZE)] * index_out[k]; |
| 1156 | image_q = image_q + eigen_vector[ch] * eigen_vector[ch]; |
| 1157 | } |
| 1158 | |
| 1159 | image_q = sqrt(image_q); |
| 1160 | |
| 1161 | // direction needs to be normalized |
| 1162 | if (image_q != 0.0F) |
| 1163 | for (CGU_UINT8 ch = 0; ch < channels3or4; ch++) |
| 1164 | eigen_vector[ch] = eigen_vector[ch] / image_q; |
no test coverage detected