Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scijava-ops-image/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
requires net.imglib2.realtransform;

provides org.scijava.types.extract.TypeExtractor with
org.scijava.ops.image.types.ExtendedRAITypeExtractor,
org.scijava.ops.image.types.Histogram1dTypeExtractor,
org.scijava.ops.image.types.ImgFactoryTypeExtractor,
org.scijava.ops.image.types.ImgLabelingTypeExtractor,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,32 +29,21 @@

package org.scijava.ops.image.convert;

import java.util.function.BiFunction;

import net.imglib2.Dimensions;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.loops.LoopBuilder;
import net.imglib2.type.logic.BitType;
import net.imglib2.type.numeric.ComplexType;
import net.imglib2.type.numeric.complex.ComplexDoubleType;
import net.imglib2.type.numeric.complex.ComplexFloatType;
import net.imglib2.type.numeric.integer.ByteType;
import net.imglib2.type.numeric.integer.IntType;
import net.imglib2.type.numeric.integer.LongType;
import net.imglib2.type.numeric.integer.ShortType;
import net.imglib2.type.numeric.integer.Unsigned128BitType;
import net.imglib2.type.numeric.integer.Unsigned12BitType;
import net.imglib2.type.numeric.integer.Unsigned2BitType;
import net.imglib2.type.numeric.integer.Unsigned4BitType;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.integer.UnsignedIntType;
import net.imglib2.type.numeric.integer.UnsignedLongType;
import net.imglib2.type.numeric.integer.UnsignedShortType;
import net.imglib2.type.numeric.integer.*;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;
import org.scijava.function.Computers;
import org.scijava.ops.spi.OpDependency;

import java.util.function.BiFunction;

/**
* Converters for converting between images of Complex types
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* #%L
* Image processing operations for SciJava Ops.
* %%
* Copyright (C) 2014 - 2024 SciJava developers.
* %%
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* #L%
*/

package org.scijava.ops.image.types;

import net.imglib2.util.Util;
import net.imglib2.view.ExtendedRandomAccessibleInterval;
import org.scijava.priority.Priority;
import org.scijava.types.extract.SubTypeExtractor;
import org.scijava.types.extract.TypeExtractor;
import org.scijava.types.extract.TypeReifier;

import java.lang.reflect.Type;

/**
* {@link TypeExtractor} plugin which operates on
* {@link ExtendedRandomAccessibleInterval} objects.
*
* @author Gabriel Selzer
*/
public class ExtendedRAITypeExtractor extends
SubTypeExtractor<ExtendedRandomAccessibleInterval<?, ?>>
{

@Override
public double priority() {
return Priority.HIGH;
}

@Override
public Class<?> baseClass() {
return ExtendedRandomAccessibleInterval.class;
}

@Override
protected Type[] getTypeParameters( //
TypeReifier r, //
ExtendedRandomAccessibleInterval<?, ?> object //
) {
return new Type[] { //
r.reify(Util.getTypeFromInterval(object.getSource())), //
r.reify(object.getSource()) //
};
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -- DO NOT EDIT -- This file is autogenerated
# Instead, modify and re-run <basedir>/bin/generate-meta-inf.sh from the top-level
org.scijava.ops.image.types.ExtendedRAITypeExtractor
org.scijava.ops.image.types.Histogram1dTypeExtractor
org.scijava.ops.image.types.ImgFactoryTypeExtractor
org.scijava.ops.image.types.ImgLabelingTypeExtractor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import net.imglib2.outofbounds.OutOfBoundsRandomValueFactory;
import net.imglib2.type.numeric.integer.UnsignedByteType;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.view.ExtendedRandomAccessibleInterval;
import net.imglib2.view.Views;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.scijava.ops.image.AbstractOpTest;
Expand All @@ -56,6 +58,44 @@
*/
public class TypeExtractorTests extends AbstractOpTest {

@Test
public void testExtendedRAITypeExtractor() {
Img<DoubleType> data = ArrayImgs.doubles(20, 20);
// Use an Op to get a histogram
var eRAI = Views.extendZero(data);
// Get the generic type (indirectly using the Type reification system through ops)
Type objType = ops.genericType(eRAI);
Assertions.assertInstanceOf(ParameterizedType.class, objType);
ParameterizedType pType = (ParameterizedType) objType;
// Assert raw type
Assertions.assertEquals(ExtendedRandomAccessibleInterval.class, pType.getRawType());
// Assert first type parameter
Assertions.assertEquals(DoubleType.class, pType.getActualTypeArguments()[0]);
// Assert second type parameter
ParameterizedType secondArgType = (ParameterizedType) pType.getActualTypeArguments()[1];
Assertions.assertEquals(ArrayImg.class, secondArgType.getRawType());
Assertions.assertEquals(DoubleType.class, secondArgType.getActualTypeArguments()[0]);
Assertions.assertEquals(DoubleArray.class, secondArgType.getActualTypeArguments()[1]);
}

@Test
public void testHistogram1dTypeExtractor() {
Img<DoubleType> data = ArrayImgs.doubles(20, 20);
// Use an Op to get a histogram
Histogram1d<DoubleType> doubles = ops.op("image.histogram") //
.input(data) //
.outType(new Nil<Histogram1d<DoubleType>>() {}) //
.apply();
// Get the generic type (indirectly using the Type reification system through ops)
Type objType = ops.genericType(doubles);
Assertions.assertInstanceOf(ParameterizedType.class, objType);
ParameterizedType pType = (ParameterizedType) objType;
// Assert raw type
Assertions.assertEquals(Histogram1d.class, pType.getRawType());
// Assert first type parameter
Assertions.assertArrayEquals(new Type[] {DoubleType.class}, pType.getActualTypeArguments());
}

@Test
public void testOutOfBoundsConstantValueFactoryTypeExtractors() {
OutOfBoundsFactory<UnsignedByteType, RandomAccessibleInterval<UnsignedByteType>> oobf =
Expand Down Expand Up @@ -107,22 +147,4 @@ public void testRAITypeExtractor() {
pType.getActualTypeArguments() //
);
}

@Test
public void testHistogram1dTypeExtractor() {
Img<DoubleType> data = ArrayImgs.doubles(20, 20);
// Use an Op to get a histogram
Histogram1d<DoubleType> doubles = ops.op("image.histogram") //
.input(data) //
.outType(new Nil<Histogram1d<DoubleType>>() {}) //
.apply();
// Get the generic type (indirectly using the Type reification system through ops)
Type objType = ops.genericType(doubles);
Assertions.assertInstanceOf(ParameterizedType.class, objType);
ParameterizedType pType = (ParameterizedType) objType;
// Assert raw type
Assertions.assertEquals(Histogram1d.class, pType.getRawType());
// Assert first type parameter
Assertions.assertArrayEquals(new Type[] {DoubleType.class}, pType.getActualTypeArguments());
}
}