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
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public class CorrelateFFTF<I extends RealType<I> & NativeType<I>, O extends Real
@OpDependency(name = "create.img")
private BiFunction<Dimensions, O, RandomAccessibleInterval<O>> outputCreator;

@OpDependency(name = "filter.pad")
@OpDependency(name = "filter.padInputFFT")
private Functions.Arity4<RandomAccessibleInterval<I>, Dimensions, Boolean, OutOfBoundsFactory<I, RandomAccessibleInterval<I>>, RandomAccessibleInterval<I>> padOp;

@OpDependency(name = "filter.padShiftFFTKernel")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* #%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.filter.correlate;

import net.imglib2.RandomAccessibleInterval;
import net.imglib2.img.array.ArrayImgs;
import net.imglib2.type.numeric.complex.ComplexFloatType;
import net.imglib2.type.numeric.real.FloatType;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.scijava.ops.image.AbstractOpTest;

import java.util.Arrays;

/**
* Tests for {@code filter.correlate} Ops
*
* @author Gabriel Selzer
*/
public class CorrelateTest extends AbstractOpTest {

@Test
public void testCorrelate() {
// Create an image with the center pixel set
var img = ArrayImgs.unsignedBytes(9, 9);
var impulse = new long[] {4, 4};
img.randomAccess().setPositionAndGet(impulse).set(1);

// Create an identity kernel
var kernel = ArrayImgs.unsignedBytes(5, 5);
kernel.getAt(2, 2).set(1);

// Correlate with Ops
var output = ops.op("filter.correlate").input(img, kernel, new FloatType(), new ComplexFloatType()).apply();
Assertions.assertInstanceOf(RandomAccessibleInterval.class, output);
var actual = (RandomAccessibleInterval<FloatType>) output;

// Check the result
var cursor = actual.cursor();
while (cursor.hasNext()) {
var actualValue = cursor.next().get();
var pos = cursor.positionAsLongArray();
// The only pixel that should be set is the center pixel.
var expected = Arrays.equals(impulse, pos) ? 1 : 0;
Assertions.assertEquals(expected, actualValue, 1e-6);
}
}
}
Loading