[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Watersheds and Label_Region for 1d



Hello,

I have made some progress.  Well, I 've made some progress toward the
Label_Region function for vectors.

I tried a number of tricks including using the REVERSE_INDICES keyword for
HISTOGRAM.
In the end, I settled for the tried and true brute-force-and-ignorance
approach.  It's not dainty but seems
to work with all of the mocked-up data I could think of.

;---------SNIP-------
;+
; NAME:  LABEL_VECTOR
;
; PURPOSE: This function returns a labeled (blob-colored) vector
;  where each unique region bears a unique region number.
;  This function is analogous to the built in LABEL_REGION function for
IDL.
;
; CALLING SEQUENCE:
;  Result = LABEL_VECTOR(Vector, [BackGround])
;
; ARGUMENTS:
;  Vector  Set this value to a numeric vector (Byte,Integer, etc.)
;  BackGround  Set this argument equal to the background value
;    of the vector... that is, the value that separates the blobs.
;    If not provided, the default value of zero is used.
;
; KEYWORDS:
;
;  MAXLABEL Set this keyword to a named variable to retrieve the
; maximum label value.  (Saves a MAX(Result) later.)
;
; EXAMPLE:
;  Generate a dummy vector... then plot it with the colorings
;   superimposed.
;    IDL> v = indgen(20)
;    IDL> v = rebin(shift(v*5,5), 80,/sample)
;    IDL> f = Label_Vector(V)
;    IDL> plot, v
;    IDL> TEK_COLOR
;    IDL> plots, indgen(80), v, color=f, /data, psym = 6
;
; MODIFICATION HISTORY:
;   Written 6JULY2000, Ben Tupper
;   Bigelow Laboratoryu for Ocean Science
;   tupper@seadas.bigelow.org
;   pemaquidriver@tidewater.net
;-

;-------
; Label_Vector
;-------
FUNCTION Label_Vector, Vec, BackGround ,MaxLabel = MaxLabel

LabeledVec = Fix(Vec GT 0)
N = N_elements(Vec)
MaxLabel = 0

If N_Params() EQ 2 then Background = Background[0] Else Background = 0

A = Where(Labeledvec GT 0, Count)

If Count GT 0 Then Begin

 MaxLabel = 1


 For i = A[0] , N - 1L Do Begin

  If LabeledVec[i] GT 0 Then Begin

    LabeledVec[i] = MaxLabel

  EndIf Else Begin

    If i NE N-1L Then $
      If LabeledVec[i] NE LabeledVec[i+1L] Then $
        MaxLabel  = MaxLabel +1

  EndElse

 EndFor  ; i loop

EndIf ; Count GT 0

Return, LabeledVec

END
;--------SNIP-------


--
Ben Tupper

Bigelow Laboratory for Ocean Science
tupper@seadas.bigelow.org

pemaquidriver@tidewater.net