Skip to content

Commit ac5e7e5

Browse files
AverageDownsample
- Centered regions are supported for non-discrete widths - Improved vertical pass and runs much faster now
1 parent c037eed commit ac5e7e5

File tree

8 files changed

+1337
-894
lines changed

8 files changed

+1337
-894
lines changed

main/boofcv-ip/src/benchmark/java/boofcv/alg/filter/misc/BenchmarkAverageDownSample.java

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2023, Peter Abeles. All Rights Reserved.
2+
* Copyright (c) 2025, Peter Abeles. All Rights Reserved.
33
*
44
* This file is part of BoofCV (http://boofcv.org).
55
*
@@ -24,7 +24,9 @@
2424
import boofcv.struct.image.GrayF32;
2525
import boofcv.struct.image.GrayS8;
2626
import boofcv.struct.image.GrayU8;
27+
import org.ddogleg.struct.DogArray_F32;
2728
import org.openjdk.jmh.annotations.*;
29+
import pabeles.concurrency.GrowArray;
2830

2931
import java.util.Random;
3032
import java.util.concurrent.TimeUnit;
@@ -44,7 +46,9 @@ public class BenchmarkAverageDownSample {
4446

4547
GrayU8 inputU8 = new GrayU8(1,1);
4648
GrayS8 inputS8 = new GrayS8(1,1);
49+
GrayU8 inputF32 = new GrayU8(1,1);
4750
GrayU8 out8 = new GrayU8(1,1);
51+
GrayF32 tmpF32 = new GrayF32(1,1);
4852
GrayF32 outF32 = new GrayF32(1,1);
4953

5054
@Setup public void setup() {
@@ -53,11 +57,14 @@ public class BenchmarkAverageDownSample {
5357

5458
inputU8.reshape(size, size);
5559
inputS8.reshape(size, size);
60+
inputF32.reshape(size, size);
5661
out8.reshape(size, size);
62+
tmpF32.reshape(size/2, size/2);
5763
outF32.reshape(size/2, size/2);
5864

5965
ImageMiscOps.fillUniform(inputU8,rand,0,200);
6066
ImageMiscOps.fillUniform(inputS8,rand,0,200);
67+
ImageMiscOps.fillUniform(inputF32,rand,0,200);
6168
}
6269

6370
@Benchmark public void general_8_U8() {
@@ -93,14 +100,29 @@ public class BenchmarkAverageDownSample {
93100
}
94101

95102
@Benchmark public void general_HV_U8() {
96-
outF32.reshape(size/2, size);
103+
tmpF32.reshape(size/2, size);
97104
out8.reshape(size/2, size/2);
105+
var workspace = new GrowArray<>(DogArray_F32::new);
106+
107+
if( BoofConcurrency.USE_CONCURRENT ) {
108+
ImplAverageDownSample_MT.horizontal(inputU8, false, tmpF32);
109+
ImplAverageDownSample_MT.vertical(tmpF32, false, out8, workspace);
110+
} else {
111+
ImplAverageDownSample.horizontal(inputU8, false, tmpF32);
112+
ImplAverageDownSample.vertical(tmpF32, false, out8, workspace);
113+
}
114+
}
115+
116+
@Benchmark public void general_HV_F32() {
117+
tmpF32.reshape(size/2, size);
118+
out8.reshape(size/2, size/2);
119+
98120
if( BoofConcurrency.USE_CONCURRENT ) {
99-
ImplAverageDownSample_MT.horizontal(inputU8, outF32);
100-
ImplAverageDownSample_MT.vertical(outF32, out8);
121+
ImplAverageDownSample_MT.horizontal(inputF32, false, tmpF32);
122+
ImplAverageDownSample_MT.vertical(tmpF32, false, outF32);
101123
} else {
102-
ImplAverageDownSample.horizontal(inputU8, outF32);
103-
ImplAverageDownSample.vertical(outF32, out8);
124+
ImplAverageDownSample.horizontal(inputF32, false, tmpF32);
125+
ImplAverageDownSample.vertical(tmpF32, false, outF32);
104126
}
105127
}
106128
}

main/boofcv-ip/src/generate/java/boofcv/alg/filter/misc/GenerateImplAverageDownSample.java

Lines changed: 0 additions & 214 deletions
This file was deleted.

0 commit comments

Comments
 (0)