Skip to content

Instantly share code, notes, and snippets.

@gylns
Last active July 1, 2016 03:29
Show Gist options
  • Save gylns/b11d8be4a0e04215634272b7c859fec3 to your computer and use it in GitHub Desktop.
Save gylns/b11d8be4a0e04215634272b7c859fec3 to your computer and use it in GitHub Desktop.
/*
histogram sort, from vlfeat/mser.c
*/
/* -----------------------------------------------------------------
* Sort pixels by intensity
* -------------------------------------------------------------- */
{
vl_uint buckets [ VL_MSER_PIX_MAXVAL ] ;
/* clear buckets */
memset (buckets, 0, sizeof(vl_uint) * VL_MSER_PIX_MAXVAL ) ;
/* compute bucket size (how many pixels for each intensity
value) */
for(i = 0 ; i < (int) nel ; ++i) {
vl_mser_pix v = im [i] ;
++ buckets [v] ;
}
/* cumulatively add bucket sizes */
for(i = 1 ; i < VL_MSER_PIX_MAXVAL ; ++i) {
buckets [i] += buckets [i-1] ;
}
/* empty buckets computing pixel ordering */
for(i = nel ; i >= 1 ; ) {
vl_mser_pix v = im [ --i ] ;
vl_uint j = -- buckets [v] ;
perm [j] = i ;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment