Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Converters #47

Closed
wants to merge 24 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
8c0d2d0
ConvertImgPlus: Removed high-level command.
dietzc Sep 16, 2014
a20a28a
Introduced new set of converters replacing the old ones
dietzc Sep 16, 2014
6feca95
Merge branch 'master' into converters
dietzc Sep 16, 2014
f2198c2
Normalizers: Refactored existing Normalizeres to work with converters
dietzc Sep 16, 2014
ffab1e8
Merge branch 'normalizer' into converters
dietzc Sep 16, 2014
1cdb9e1
Merge branch 'master' into converters
dietzc Sep 16, 2014
e3db0ed
ConvertClip: Add JavaDoc
dietzc Sep 16, 2014
c1157e7
Rename ConvertClipIterableRT to ConvertClipIterable
dietzc Sep 16, 2014
2a8bd64
ConvertClipPixelRT: Add JavaDoc
dietzc Sep 16, 2014
9534d9d
ConvertCopy: Add JavaDoc
dietzc Sep 16, 2014
567c323
ConvertCopyIterableRT: Add JavaDoc
dietzc Sep 16, 2014
a7c6d86
ConvertCopyPixelRT: Add JavaDoc
dietzc Sep 16, 2014
73b1641
ConvertNormalizeScale: Add JavaDoc
dietzc Sep 16, 2014
7a28748
ConvertScale: Add JavaDoc
dietzc Sep 16, 2014
bdb790b
ConvertScaleIterableRT: Add JavaDoc
dietzc Sep 16, 2014
7091150
ConvertNormalizeScaleIterableRT: Add JavaDoc
dietzc Sep 16, 2014
33070cf
NormalizeImgRT: Add JavaDoc
dietzc Sep 16, 2014
c3fc70b
Refactor 'Create' interface to 'CreateImg'
dietzc Sep 17, 2014
33aa215
Introduced convenience Converters for Imgs
dietzc Sep 17, 2014
fde44bd
ConverterTests: Wrote more tests for converters
dietzc Sep 17, 2014
44e1950
Refactor ScalePixel interface
dietzc Sep 16, 2014
17ba38a
Merge branch 'createimg' into converters
dietzc Sep 17, 2014
36a3d58
Add possibility to run NornmalizeImgRT SliceWise
dietzc Sep 17, 2014
2e2a9b2
NormalizeImgPlusRT: Added High-Level Normalize
dietzc Sep 17, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/net/imagej/ops/DefaultOpService.java
Expand Up @@ -206,7 +206,7 @@ public Object convolve(Object... args) {
}

@Override
public Object create(Object... args) {
public Object createImg(Object... args) {
return run("create", args);
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/net/imagej/ops/OpService.java
Expand Up @@ -184,7 +184,7 @@ public interface OpService extends PTService<Op>, ImageJService {
Object convolve(Object... args);

/** Executes the "create" operation on the given arguments. */
Object create(Object... args);
Object createImg(Object... args);

/** Executes the "crop" operation on the given arguments. */
Object crop(Object... args);
Expand Down
51 changes: 0 additions & 51 deletions src/main/java/net/imagej/ops/convert/Convert.java

This file was deleted.

25 changes: 25 additions & 0 deletions src/main/java/net/imagej/ops/convert/ConvertClip.java
@@ -0,0 +1,25 @@
package net.imagej.ops.convert;

import net.imagej.ops.Function;

/**
* Base interface for "convert-clip" operations.
* <p>
* Implementing classes should be annotated with:
* </p>
*
* <pre>
* @Plugin(type = Op.class, name = ConvertClip.NAME)
* </pre>
*
* <p>
* Converts some <I> to another <O>. The values are copied. If a value of the
* input is lower/higher than the output minimum/maximum, it will be set to the
* minimum/maximum of the output.
* </p>
*
* @author Christian Dietz (University of Konstanz)
*/
public interface ConvertClip<I, O> extends Function<I, O> {
String NAME = "convert-clip";
}
Expand Up @@ -30,46 +30,40 @@

package net.imagej.ops.convert;

import net.imagej.ops.AbstractOutputFunction;
import net.imagej.ops.Op;
import net.imglib2.IterableInterval;
import net.imglib2.type.numeric.RealType;
import net.imagej.ops.OpService;
import net.imglib2.img.Img;

import org.scijava.Priority;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

/**
* @author Martin Horn
* Applies a {@link ConvertClip} on an {@link Iterable}.
*
* @author Christian Dietz (University of Konstanz)
*/
@Plugin(type = Op.class, name = Convert.NAME)
public class ConvertPixScale<I extends RealType<I>, O extends RealType<O>>
extends ConvertPix<I, O>
{

protected double inMin;

protected double outMin;
@Plugin(type = Op.class, name = ConvertClip.NAME, priority = Priority.HIGH_PRIORITY)
public class ConvertClipImg<T, V> extends
AbstractOutputFunction<Img<T>, Img<V>> implements
ConvertClip<Img<T>, Img<V>> {

protected double factor = 0;

@Override
public O compute(final I input, final O output) {
output.setReal((input.getRealDouble() - inMin) / factor + outMin);
return output;
}
@Parameter
private OpService ops;

@Override
public void checkInput(final I inType, final O outType) {
inMin = inType.getMinValue();
outMin = outType.getMinValue();
factor = (inType.getMaxValue() - inMin) / (outType.getMaxValue() - outMin);
}
@Parameter
private V outType;

@SuppressWarnings("unchecked")
@Override
public void checkInput(IterableInterval<I> in) {
// nothing to do here
public Img<V> createOutput(Img<T> input) {
return (Img<V>) ops.createImg(input, outType);
}

@Override
public boolean conforms() {
return true;
protected Img<V> safeCompute(Img<T> input, Img<V> output) {
ops.run(ConvertClip.class, output, input);
return output;
}
}
Expand Up @@ -33,36 +33,39 @@
import net.imagej.ops.AbstractFunction;
import net.imagej.ops.Op;
import net.imagej.ops.OpService;
import net.imglib2.IterableInterval;
import net.imglib2.type.numeric.RealType;
import net.imagej.ops.map.Map;

import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

/**
* @author Martin Horn
* Applies a {@link ConvertClip} on an {@link Iterable}.
*
* @author Christian Dietz (University of Konstanz)
*/
@Plugin(type = Op.class, name = Convert.NAME)
public class ConvertII<I extends RealType<I>, O extends RealType<O>> extends
AbstractFunction<IterableInterval<I>, IterableInterval<O>> implements
Convert<IterableInterval<I>, IterableInterval<O>>
{
@Plugin(type = Op.class, name = ConvertClip.NAME)
public class ConvertClipIterable<T, V> extends
AbstractFunction<Iterable<T>, Iterable<V>> implements
ConvertClip<Iterable<T>, Iterable<V>> {

@Parameter
private ConvertPix<I, O> pixConvert;
private OpService ops;

@Parameter
private OpService ops;
private T outMin;

@Parameter
private V outMax;

@SuppressWarnings("unchecked")
@Override
public IterableInterval<O> compute(final IterableInterval<I> input,
final IterableInterval<O> output)
{
pixConvert.checkInput(input.firstElement().createVariable(), output
.firstElement().createVariable());
pixConvert.checkInput(input);
return (IterableInterval<O>) ops.run("map", output, input, pixConvert);
}
public Iterable<V> compute(final Iterable<T> input, final Iterable<V> output) {

ConvertClip<T, V> op = (ConvertClip<T, V>) ops.op(ConvertClip.class,
outMin, outMax);

ops.run(Map.class, output, input, op);

return output;
}
}
Expand Up @@ -30,54 +30,41 @@

package net.imagej.ops.convert;

import net.imagej.ops.AbstractFunction;
import net.imagej.ops.Op;
import net.imglib2.IterableInterval;
import net.imglib2.type.numeric.RealType;

import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

/**
* @author Martin Horn
* {@link ConvertClip} implementation for {@link RealType}s.
*
* @author Christian Dietz (University of Konstanz)
*
* @param <T>
* @param <V>
*/
@Plugin(type = Op.class, name = Convert.NAME)
public class ConvertPixClip<I extends RealType<I>, O extends RealType<O>>
extends ConvertPix<I, O>
{

private double outMax;
@Plugin(type = Op.class, name = ConvertClip.NAME)
public class ConvertClipPixelRT<T extends RealType<T>, V extends RealType<V>>
extends AbstractFunction<T, V> implements ConvertClip<T, V> {

@Parameter
private double outMin;

@Parameter
private double outMax;

@Override
public O compute(final I input, final O output) {
public V compute(T input, V output) {
final double v = input.getRealDouble();
if (v > outMax) {
output.setReal(outMax);
}
else if (v < outMin) {
} else if (v < outMin) {
output.setReal(outMin);
}
else {
} else {
output.setReal(v);
}
return output;
}

@Override
public void checkInput(final I inType, final O outType) {
outMax = outType.getMaxValue();
outMin = outType.getMinValue();

}

@Override
public void checkInput(IterableInterval<I> in) {
// nothing to do here
}

@Override
public boolean conforms() {
return true;
}

}
23 changes: 23 additions & 0 deletions src/main/java/net/imagej/ops/convert/ConvertCopy.java
@@ -0,0 +1,23 @@
package net.imagej.ops.convert;

import net.imagej.ops.Function;

/**
* Base interface for "convert-copy" operations.
* <p>
* Implementing classes should be annotated with:
* </p>
*
* <pre>
* @Plugin(type = Op.class, name = ConvertCopy.NAME)
* </pre>
*
* <p>
* Converts from <I> to <O> by just copying the values.
* </p>
*
* @author Christian Dietz
*/
public interface ConvertCopy<I, O> extends Function<I, O> {
String NAME = "convert-copy";
}
71 changes: 71 additions & 0 deletions src/main/java/net/imagej/ops/convert/ConvertCopyImg.java
@@ -0,0 +1,71 @@
/*
* #%L
* ImageJ software for multidimensional image processing and analysis.
* %%
* Copyright (C) 2014 Board of Regents of the University of
* Wisconsin-Madison and University of Konstanz.
* %%
* 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 net.imagej.ops.convert;

import net.imagej.ops.AbstractOutputFunction;
import net.imagej.ops.Op;
import net.imagej.ops.OpService;
import net.imagej.ops.create.CreateImg;
import net.imglib2.img.Img;
import net.imglib2.type.NativeType;

import org.scijava.Priority;
import org.scijava.plugin.Parameter;
import org.scijava.plugin.Plugin;

/**
* Applies a {@link ConvertCopy} on an {@link Iterable}.
*
* @author Christian Dietz (University of Konstanz)
*/
@Plugin(type = Op.class, name = ConvertClip.NAME, priority = Priority.HIGH_PRIORITY)
public class ConvertCopyImg<T, V extends NativeType<V>> extends
AbstractOutputFunction<Img<T>, Img<V>> implements
ConvertCopy<Img<T>, Img<V>> {

@Parameter
private OpService ops;

@Parameter
private NativeType<V> outType;

@SuppressWarnings("unchecked")
@Override
public Img<V> createOutput(Img<T> input) {
return (Img<V>) ops.run(CreateImg.class, input, outType);
}

@Override
protected Img<V> safeCompute(Img<T> input, Img<V> output) {
ops.run(ConvertCopy.class, output, input);
return output;
}
}