|
21 | 21 | import boofcv.alg.filter.misc.impl.*; |
22 | 22 | import boofcv.concurrency.BoofConcurrency; |
23 | 23 | import boofcv.struct.image.*; |
| 24 | +import org.ddogleg.struct.DogArray_F32; |
24 | 25 | import org.jetbrains.annotations.Nullable; |
| 26 | +import pabeles.concurrency.GrowArray; |
25 | 27 |
|
26 | 28 | /// |
27 | 29 | /// 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 ) { |
180 | 182 | } |
181 | 183 | } |
182 | 184 |
|
| 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 | + |
183 | 257 | /// Down samples a planar image. Type checking is done at runtime. |
184 | 258 | /// |
185 | 259 | /// @param input Input image. Not modified. |
|
0 commit comments