Skip to content

Instantly share code, notes, and snippets.

@blackball
Created August 10, 2014 16:30
Show Gist options
  • Save blackball/402262085c777af25c8f to your computer and use it in GitHub Desktop.
Save blackball/402262085c777af25c8f to your computer and use it in GitHub Desktop.
// Codes to show the 'uniform pattern' of LBP
#include <stdio.h>
typedef unsigned char uint8_t;
#define BIT_AT(v, pos) (((v) >> (pos)) & 1)
static int
numOfTran(uint8_t v) {
int n = 0;
for (int i = 1; i < 8; ++i)
n += BIT_AT(v, i) != BIT_AT(v, i-1);
n += BIT_AT(v,0) != BIT_AT(v, 7);
return n;
}
static void
binaryRep(uint8_t v) {
char rep[9] = {0};
// for little endian
for (int i = 0; i < 8; ++i)
rep[7-i] = BIT_AT(v, i) + '0';
puts(rep);
}
static void
test() {
int cnt = 0;
for (int i = 0; i < 256; ++i) {
binaryRep(i);
int t = numOfTran(i);
printf("%d\n", t);
cnt += t <= 2;
}
printf("\n%d\n", cnt);
}
int
main(int ac, char **av) {
test();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment