I'm not getting any speed gain with this method, for 'real' image. Not sure, why to expect this gain, if instead of matching for sequence of non-zero bytes we just trying to match for non-zero byte followed by sequence of zeroes? And there's additional work to do: xor-ing, chopping, etc.
Plus, what if object "32" happens to be in 1st column?
$s = join '', map { chr } qw/ 32 0 1 1 0 0 2/; $t = ' ' . $s ^ $s; chop $t; while ( $t =~ m[[^\0]\0*]g ) { printf "%d\t%d\t%d\n", ord( substr $s, $-[0], 1 ), $-[0], $+[0] - +1; }
It looks we have to prepend a zero byte (because, it seems, original eily's solution was strictly for alphabetical strings). Then speed drops below that of "buk3" - loop spends lot of time finding bbox of background. Inserting "next unless $c", leads to, again, the same performance as "buk3".
Well, for now, "buk3"'s speed is "good enough" (amazingly good compared to 'elegant' PDL-only solution), thank you everyone who contributed.
In reply to Re^5: Faster regex to split a string into runs of similar characters?
by vr
in thread Faster regex to split a string into runs of similar characters?
by BrowserUk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |