|
12 | 12 | import java.util.stream.IntStream;
|
13 | 13 | import java.util.stream.Stream;
|
14 | 14 |
|
| 15 | +import org.janelia.saalfeldlab.n5.universe.metadata.MetadataUtils; |
15 | 16 | import org.janelia.saalfeldlab.n5.universe.metadata.N5Metadata;
|
16 | 17 | import org.janelia.saalfeldlab.n5.universe.metadata.N5SpatialDatasetMetadata;
|
17 | 18 | import org.janelia.saalfeldlab.n5.universe.metadata.SpatialMetadata;
|
@@ -312,6 +313,32 @@ public static <T, M extends N5Metadata, A extends AxisMetadata & N5Metadata> Pai
|
312 | 313 | return new ValuePair<>(img, meta);
|
313 | 314 | }
|
314 | 315 |
|
| 316 | + public static <T, M extends N5Metadata, A extends AxisMetadata & N5Metadata> Pair<RandomAccessibleInterval<T>, M> permuteImageAndMetadataForImagePlus( |
| 317 | + final int[] p, final RandomAccessibleInterval<T> img, final M meta) { |
| 318 | + |
| 319 | + // store the permutation for metadata |
| 320 | + final int[] metadataPermutation = Arrays.stream(p).filter(x -> x >= 0).toArray(); |
| 321 | + |
| 322 | + // pad the image permutation |
| 323 | + AxisUtils.fillPermutation(p); |
| 324 | + |
| 325 | + RandomAccessibleInterval<T> imgTmp = img; |
| 326 | + while (imgTmp.numDimensions() < 5) |
| 327 | + imgTmp = Views.addDimension(imgTmp, 0, 0); |
| 328 | + |
| 329 | + RandomAccessibleInterval<T> imgOut; |
| 330 | + M datasetMeta; |
| 331 | + if (AxisUtils.isIdentityPermutation(p)) { |
| 332 | + imgOut = imgTmp; |
| 333 | + datasetMeta = meta; |
| 334 | + } else { |
| 335 | + imgOut = AxisUtils.permute(imgTmp, AxisUtils.invertPermutation(p)); |
| 336 | + datasetMeta = (M)MetadataUtils.permuteSpatialMetadata(meta, metadataPermutation); |
| 337 | + } |
| 338 | + |
| 339 | + return new ValuePair<>(imgOut, datasetMeta); |
| 340 | + } |
| 341 | + |
315 | 342 | public static <T> RandomAccessibleInterval<T> reverseDimensions(final RandomAccessibleInterval<T> img) {
|
316 | 343 |
|
317 | 344 | final int nd = img.numDimensions();
|
|
0 commit comments