;label&  --  labeling images having more than 255 objects
;            Add your analysis to this command file
;expects:    binary source image in a
;destroys:   p, q
;result:     in q
;
int numobj 
int ready = 0
int seq = 0
int nn
int total = 0

dis p

repeat
  seq += 1
  numobj = label a        ;if more than 255 labels rpar is negative
  copy p q                ;save labeled image part to 'q'
  thre 1                  ;make labeled image part in 'p' binary
  xor p a >a              ;remove labeled part from source
  if numobj < 0           ;if negative:
    print "Sequence ", seq
    numobj *= -1          ;make numobj positive for analysis
  else
    print "Last sequence ..."
    ready = 1 ;           ;if positive this is last sequence
  endif
  ;
  ;here goes the image analysis of the labeled image in 'q'
   call analysis
  ;
until ready == 1          ;as long as not ready label image
print "----------------------------------------------"
print "Total:" @20 total "objects analyzed"
stop


analysis:                 ;simple object processing
  dis q
  mark 1 0                ;first object separate to learn position
  for nn = 2 to numobj step 1   
    mark nn 0 /           ;further objects by incremental search (/)
  endfor
  print @20 numobj "objects analyzed"
  total += numobj
  dis p
  return
