Skip to content

Commit 6a6a950

Browse files
- Added generalized functions for horizontal and vertical down sampling
1 parent acd7abb commit 6a6a950

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

main/boofcv-ip/src/main/java/boofcv/alg/filter/misc/AverageDownSampleOps.java

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import boofcv.alg.filter.misc.impl.*;
2222
import boofcv.concurrency.BoofConcurrency;
2323
import boofcv.struct.image.*;
24+
import org.ddogleg.struct.DogArray_F32;
2425
import org.jetbrains.annotations.Nullable;
26+
import pabeles.concurrency.GrowArray;
2527

2628
///
2729
/// Operations related to down sampling image by computing the average within square regions. The first square region is
@@ -180,6 +182,78 @@ void down( T input, boolean centered, T output, @Nullable ImageGray middle ) {
180182
}
181183
}
182184

185+
/// Downsample the horizontal axis only. Output must be [GrayF32] or [GrayF64], depending on image type.
186+
public static void horizontal( ImageGray input, boolean centered, ImageGray output ) {
187+
if (ImageGray.class.isAssignableFrom(input.getClass())) {
188+
if (BoofConcurrency.USE_CONCURRENT) {
189+
if (input instanceof GrayU8) {
190+
ImplAverageDownSample_MT.horizontal((GrayU8)input, centered, (GrayF32)output);
191+
} else if (input instanceof GrayU16) {
192+
ImplAverageDownSample_MT.horizontal((GrayU16)input, centered, (GrayF32)output);
193+
} else if (input instanceof GrayF32) {
194+
ImplAverageDownSample_MT.horizontal((GrayF32)input, centered, (GrayF32)output);
195+
} else if (input instanceof GrayF64) {
196+
ImplAverageDownSample_MT.horizontal((GrayF64)input, centered, (GrayF64)output);
197+
} else {
198+
throw new IllegalArgumentException("Unknown image type");
199+
}
200+
} else {
201+
if (input instanceof GrayU8) {
202+
ImplAverageDownSample.horizontal((GrayU8)input, centered, (GrayF32)output);
203+
} else if (input instanceof GrayU16) {
204+
ImplAverageDownSample.horizontal((GrayU16)input, centered, (GrayF32)output);
205+
} else if (input instanceof GrayF32) {
206+
ImplAverageDownSample.horizontal((GrayF32)input, centered, (GrayF32)output);
207+
} else if (input instanceof GrayF64) {
208+
ImplAverageDownSample.horizontal((GrayF64)input, centered, (GrayF64)output);
209+
} else {
210+
throw new IllegalArgumentException("Unknown image type");
211+
}
212+
}
213+
} else if (Planar.class.isAssignableFrom(input.getClass())) {
214+
throw new IllegalArgumentException("Image type not supported yet");
215+
}
216+
}
217+
218+
/// Downsample vertical axis only. Input must be [GrayF32] or [GrayF64]. The workspace is only
219+
/// used with integer output image types
220+
public static void vertical( ImageBase input, boolean centered, ImageBase output,
221+
@Nullable GrowArray<DogArray_F32> workspaces ) {
222+
if (workspaces == null && output.getImageType().getDataType().isInteger()) {
223+
workspaces = new GrowArray<>(DogArray_F32::new);
224+
}
225+
226+
if (ImageGray.class.isAssignableFrom(input.getClass())) {
227+
if (BoofConcurrency.USE_CONCURRENT) {
228+
if (input instanceof GrayU8) {
229+
ImplAverageDownSample_MT.vertical((GrayF32)input, centered, (GrayI8)output, workspaces);
230+
} else if (input instanceof GrayU16) {
231+
ImplAverageDownSample_MT.vertical((GrayF32)input, centered, (GrayU16)output, workspaces);
232+
} else if (input instanceof GrayF32) {
233+
ImplAverageDownSample_MT.vertical((GrayF32)input, centered, (GrayF32)output);
234+
} else if (input instanceof GrayF64) {
235+
ImplAverageDownSample_MT.vertical((GrayF64)input, centered, (GrayF64)output);
236+
} else {
237+
throw new IllegalArgumentException("Unknown image type");
238+
}
239+
} else {
240+
if (input instanceof GrayU8) {
241+
ImplAverageDownSample.vertical((GrayF32)input, centered, (GrayI8)output, workspaces);
242+
} else if (input instanceof GrayU16) {
243+
ImplAverageDownSample.vertical((GrayF32)input, centered, (GrayU16)output, workspaces);
244+
} else if (input instanceof GrayF32) {
245+
ImplAverageDownSample.vertical((GrayF32)input, centered, (GrayF32)output);
246+
} else if (input instanceof GrayF64) {
247+
ImplAverageDownSample.vertical((GrayF64)input, centered, (GrayF64)output);
248+
} else {
249+
throw new IllegalArgumentException("Unknown image type");
250+
}
251+
}
252+
} else if (Planar.class.isAssignableFrom(input.getClass())) {
253+
throw new IllegalArgumentException("Image type not supported yet");
254+
}
255+
}
256+
183257
/// Down samples a planar image. Type checking is done at runtime.
184258
///
185259
/// @param input Input image. Not modified.

0 commit comments

Comments
 (0)