@@ -126,4 +126,66 @@ static < B extends BooleanType< B >, L extends IntegerType< L > > void relabel(
126126 }
127127 }
128128
129+ /**
130+ *
131+ * Relabel all pixels into the representative id of their containing
132+ * sets as defined by {@code unionFind}.
133+ *
134+ * @param labeling
135+ * Output parameter to store labeling: background pixels are
136+ * labeled zero, foreground pixels are greater than zero: 1, 2,
137+ * ..., N. Note that this is expected to be zero as background
138+ * values will not be written.
139+ * @param unionFind
140+ * {@link UnionFind}
141+ * @param idForPixel
142+ * Create id from pixel location and value. Multiple calls with
143+ * the same argument should always return the same result.
144+ * @param idForSet
145+ * Create id for a set from the root id of a set. Multiple calls
146+ * with the same argument should always return the same result.
147+ */
148+ public default < B extends BooleanType < B >, L extends IntegerType < L > > void relabel (
149+ final RandomAccessibleInterval < L > labeling ,
150+ final ToLongBiFunction < Localizable , L > idForPixel ,
151+ final LongUnaryOperator idForSet )
152+ {
153+ final Cursor < L > label = Views .flatIterable ( labeling ).localizingCursor ();
154+ while ( label .hasNext () )
155+ {
156+ final L l = label .next ();
157+ final long root = findRoot ( idForPixel .applyAsLong ( label , l ) );
158+ l .setInteger ( idForSet .applyAsLong ( root ) );
159+ }
160+ }
161+
162+ /**
163+ * Relabel all pixels into the representative id of their containing
164+ * sets as defined by {@code unionFind}.
165+ *
166+ * @param labeling
167+ * Output parameter to store labeling: background pixels are
168+ * labeled zero, foreground pixels are greater than zero: 1, 2,
169+ * ..., N. Note that this is expected to be zero as background
170+ * values will not be written.
171+ * @param unionFind
172+ * {@link UnionFind}
173+ * @param idForPixel
174+ * Create id from pixel location and value. Multiple calls with
175+ * the same argument should always return the same result.
176+ * @param idForSet
177+ * Create id for a set from the root id of a set. Multiple calls
178+ * with the same argument should always return the same result.
179+ */
180+ public default < L extends IntegerType < L > > void relabel (
181+ final RandomAccessibleInterval < L > labeling )
182+ {
183+ final Cursor < L > label = Views .flatIterable ( labeling ).localizingCursor ();
184+ while ( label .hasNext () )
185+ {
186+ final L l = label .next ();
187+ final long root = findRoot ( l .getIntegerLong () );
188+ l .setInteger ( root );
189+ }
190+ }
129191}
0 commit comments