Created
March 11, 2020 12:55
-
-
Save bogovicj/cce1b51576274484c287ed6eedff74f2 to your computer and use it in GitHub Desktop.
Some programically generated images in imglib2.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.BiConsumer; | |
import net.imglib2.FinalInterval; | |
import net.imglib2.Interval; | |
import net.imglib2.Localizable; | |
import net.imglib2.RandomAccessibleInterval; | |
import net.imglib2.img.Img; | |
import net.imglib2.loops.LoopBuilder; | |
import net.imglib2.position.FunctionRandomAccessible; | |
import net.imglib2.type.numeric.RealType; | |
import net.imglib2.type.numeric.real.DoubleType; | |
import net.imglib2.util.Util; | |
import net.imglib2.view.IntervalView; | |
import net.imglib2.view.Views; | |
public class GenImages | |
{ | |
public static <T extends RealType<T>> RandomAccessibleInterval<T> expChirpImage( | |
final T type, final Interval interval, | |
double f0, double f1, final boolean copy ) | |
{ | |
// exp chirp | |
final double w = interval.realMax( 0 ); | |
final double k = Math.pow( (f1 / f0), 1 / w ); | |
BiConsumer<Localizable,T> fun = new BiConsumer<Localizable,T>(){ | |
@Override | |
public void accept( Localizable p, T t ) | |
{ | |
t.setReal( 1 * Math.cos( p.getDoublePosition( 0 ) * f0 * Math.pow( k, p.getDoublePosition( 0 ) ) )); | |
} | |
}; | |
FunctionRandomAccessible<T> freqSweep = new FunctionRandomAccessible<>( interval.numDimensions(), fun, type::createVariable ); | |
IntervalView<T> virtualimg = Views.interval( freqSweep, interval ); | |
if( copy ) | |
{ | |
Img<T> memimg = Util.getSuitableImgFactory( interval, type).create(interval); | |
LoopBuilder.setImages( virtualimg, memimg ).forEachPixel( (x,y) -> y.set(x) ); | |
return memimg; | |
} | |
else | |
return virtualimg; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment