Build 3-D color histogram of counts, r/g/b, c^2
| 87 | |
| 88 | // Build 3-D color histogram of counts, r/g/b, c^2 |
| 89 | ILboolean Hist3d(ILubyte *Ir, ILubyte *Ig, ILubyte *Ib, ILint *vwt, ILint *vmr, ILint *vmg, ILint *vmb, ILfloat *m2) |
| 90 | { |
| 91 | ILint ind, r, g, b; |
| 92 | ILint inr, ing, inb, table[2560]; |
| 93 | ILuint i; |
| 94 | |
| 95 | for (i = 0; i < 256; i++) |
| 96 | { |
| 97 | table[i] = i * i; |
| 98 | } |
| 99 | Qadd = (ILushort*)ialloc(sizeof(ILushort) * size); |
| 100 | if (Qadd == NULL) |
| 101 | { |
| 102 | return IL_FALSE; |
| 103 | } |
| 104 | |
| 105 | imemclear(Qadd, sizeof(ILushort) * size); |
| 106 | |
| 107 | for (i = 0; i < size; i++) |
| 108 | { |
| 109 | r = Ir[i]; g = Ig[i]; b = Ib[i]; |
| 110 | inr = (r>>3) + 1; |
| 111 | ing = (g>>3) + 1; |
| 112 | inb = (b>>3) + 1; |
| 113 | Qadd[i] = ind = (inr<<10)+(inr<<6)+inr+(ing<<5)+ing+inb; |
| 114 | //[inr][ing][inb] |
| 115 | vwt[ind]++; |
| 116 | vmr[ind] += r; |
| 117 | vmg[ind] += g; |
| 118 | vmb[ind] += b; |
| 119 | m2[ind] += (ILfloat)(table[r]+table[g]+table[b]); |
| 120 | } |
| 121 | return IL_TRUE; |
| 122 | } |
| 123 | |
| 124 | /* At conclusion of the histogram step, we can interpret |
| 125 | * wt[r][g][b] = sum over voxel of P(c) |