Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
WIP: Write wrapper focusers
  • Loading branch information
gselzer committed Feb 10, 2025
commit 0e7c585fb4a97b15be08ab04948570f070617a8b
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import org.scijava.ops.api.*;
import org.scijava.ops.engine.BaseOpHints;
import org.scijava.ops.engine.InfoTreeGenerator;
import org.scijava.ops.engine.matcher.impl.DefaultOpRequest;
import org.scijava.ops.engine.matcher.impl.InfoMatchingOpRequest;
import org.scijava.types.Nil;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
import org.scijava.ops.engine.matcher.OpMatcher;
import org.scijava.ops.engine.matcher.impl.MatchingUtils.TypeVarInfo;
import org.scijava.priority.Priority;
import org.scijava.struct.Member;
import org.scijava.common3.Types;
import org.scijava.types.infer.GenericAssignability;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,14 @@
package org.scijava.ops.image.convert;

import net.imglib2.Dimensions;
import net.imglib2.IterableInterval;
import net.imglib2.RandomAccessibleInterval;
import net.imglib2.Sampler;
import net.imglib2.converter.Converters;
import net.imglib2.converter.readwrite.SamplerConverter;
import net.imglib2.converter.readwrite.WriteConvertedIterableRandomAccessibleInterval;
import net.imglib2.img.basictypeaccess.DoubleAccess;
import net.imglib2.img.basictypeaccess.LongAccess;
import net.imglib2.loops.LoopBuilder;
import net.imglib2.type.logic.BitType;
import net.imglib2.type.numeric.ComplexType;
Expand All @@ -39,6 +46,7 @@
import net.imglib2.type.numeric.integer.*;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.type.numeric.real.FloatType;
import net.imglib2.util.Util;
import org.scijava.function.Computers;
import org.scijava.ops.spi.OpDependency;

Expand All @@ -53,24 +61,33 @@ public final class ConvertImages {

/**
* @implNote op names='convert.bit, engine.convert', type=Function
* @param creator a {@link BiFunction} to create the output image
* @param converter a {@link Computers.Arity1} to convert the type to a
* {@link BitType}
* @param input the input image
* @return an output image whose values are equivalent to {@code input}s
* values but whose element types are {@link BitType}s.
*/
public static <C extends ComplexType<C>, RAIC extends RandomAccessibleInterval<C>>
RandomAccessibleInterval<BitType> typeToBit(@OpDependency(
name = "create.img") BiFunction<Dimensions, BitType, RandomAccessibleInterval<BitType>> creator,
@OpDependency(
name = "convert.bit") Computers.Arity1<C, BitType> converter,
final RAIC input)
RandomAccessibleInterval<BitType> typeToBit(final RAIC input)
{
var output = creator.apply(input,
new BitType());
LoopBuilder.setImages(input, output).forEachPixel(converter);
return output;
final C ZERO = Util.getTypeFromInterval(input).createVariable();
ZERO.setZero();
final C ONE = Util.getTypeFromInterval(input).createVariable();
ONE.setOne();

return Converters.convert(input, sampler -> new BitType(new LongAccess() {
@Override
public long getValue(int index) {
return sampler.get().equals(ZERO) ? 0L : 1L;
}

@Override
public void setValue(int index, long value) {
if (value == 0L) {
sampler.get().set(ZERO);
} else {
sampler.get().set(ONE);
}
}
}));
}

/**
Expand Down Expand Up @@ -387,48 +404,59 @@ RandomAccessibleInterval<ComplexFloatType> typeToComplexFloat32(
}

/**
* @param creator a {@link BiFunction} to create the output image
* @param converter a {@link Computers.Arity1} to convert the type to a
* {@link DoubleType}
* @param input the input image
* @return an output image whose values are equivalent to {@code input}'s
* values but whose element types are {@link DoubleType}s.
* @implNote op names='convert.float64, engine.convert', type=Function
*/
public static <C extends ComplexType<C>, RAIC extends RandomAccessibleInterval<C>>
RandomAccessibleInterval<DoubleType> typeToDouble32(@OpDependency(
name = "create.img") BiFunction<Dimensions, DoubleType, RandomAccessibleInterval<DoubleType>> creator,
@OpDependency(
name = "convert.float64") Computers.Arity1<C, DoubleType> converter,
final RAIC input)
RandomAccessibleInterval<DoubleType> typeToDoubleType(final RAIC input)
{
var output = creator.apply(input,
new DoubleType());
LoopBuilder.setImages(input, output).forEachPixel(converter);
return output;
return Converters.convert(input, sampler -> new DoubleType(new DoubleAccess() {

@Override
public double getValue(int index) {
return sampler.get().getRealDouble();
}

@Override
public void setValue(int index, double value) {
sampler.get().setReal(value);
sampler.get().setImaginary(0);
}
}));
}

/**
* @param creator a {@link BiFunction} to create the output image
* @param converter a {@link Computers.Arity1} to convert the type to a
* {@link ComplexDoubleType}
* @param input the input image
* @return an output image whose values are equivalent to {@code input}'s
* values but whose element types are {@link ComplexDoubleType}s.
* @implNote op names='convert.cfloat64, engine.convert', type=Function
*/
public static <C extends ComplexType<C>, RAIC extends RandomAccessibleInterval<C>>
RandomAccessibleInterval<ComplexDoubleType> typeToComplexDouble32(
@OpDependency(
name = "create.img") BiFunction<Dimensions, ComplexDoubleType, RandomAccessibleInterval<ComplexDoubleType>> creator,
@OpDependency(
name = "convert.cfloat64") Computers.Arity1<C, ComplexDoubleType> converter,
final RAIC input)
{
var output = creator.apply(input,
new ComplexDoubleType());
LoopBuilder.setImages(input, output).forEachPixel(converter);
return output;
return Converters.convert(input, sampler -> new ComplexDoubleType(new DoubleAccess() {

@Override
public double getValue(int index) {
if (index % 2 == 0) {
return sampler.get().getRealDouble();
} else {
return sampler.get().getImaginaryDouble();
}
}

@Override
public void setValue(int index, double value) {
if (index % 2 == 0) {
sampler.get().setReal(value);
} else {
sampler.get().setImaginary(value);
}
}
}));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*-
* #%L
* Image processing operations for SciJava Ops.
* %%
* Copyright (C) 2014 - 2025 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.convert;

import net.imglib2.img.array.ArrayImgs;
import org.junit.jupiter.api.Test;
import org.scijava.common3.MersenneTwisterFast;

public class ConvertImagesCorrectnessTest {

@Test
public void realTypeToComplexTypeTest() {
MersenneTwisterFast mt = new MersenneTwisterFast(0xdeadbeefL);
int width = 10, height = 10;
var backing = ArrayImgs.doubles(width, height);
var cursor = backing.cursor();
while(cursor.hasNext()) {
cursor.next().setReal(mt.nextDouble());
}
}



}
Loading