Search in sources :

Example 1 with SourceAndConverter

use of bdv.viewer.SourceAndConverter in project bigwarp by saalfeldlab.

the class BigWarpBatchTransformFOV method applyBigWarpHelper.

public static <T> BigWarpExporter<T> applyBigWarpHelper(AbstractSpimData<?>[] spimDataP, AbstractSpimData<?>[] spimDataQ, ImagePlus impP, LandmarkTableModel ltm, Interpolation interpolation) {
    String[] names = generateNames(impP);
    BigWarpData data = BigWarpInit.createBigWarpData(spimDataP, spimDataQ, names);
    int numChannels = impP.getNChannels();
    int[] movingSourceIndexList = new int[numChannels];
    for (int i = 0; i < numChannels; i++) {
        movingSourceIndexList[i] = i;
    }
    int[] targetSourceIndexList = data.targetSourceIndices;
    @SuppressWarnings("unchecked") List<SourceAndConverter<T>> sourcesxfm = BigWarp.wrapSourcesAsTransformed(data.sources, ltm.getNumdims(), data);
    ThinPlateR2LogRSplineKernelTransform xfm = ltm.getTransform();
    for (int i = 0; i < numChannels; i++) {
        WrappedIterativeInvertibleRealTransform irXfm = new WrappedIterativeInvertibleRealTransform<>(new ThinplateSplineTransform(xfm));
        ((WarpedSource<?>) (sourcesxfm.get(i).getSpimSource())).updateTransform(irXfm.copy());
        ((WarpedSource<?>) (sourcesxfm.get(i).getSpimSource())).setIsTransformed(true);
    }
    ProgressWriter progressWriter = new ProgressWriterConsole();
    BigWarpExporter<?> exporter = null;
    // return exporter;
    return null;
}
Also used : BigWarpData(bigwarp.BigWarp.BigWarpData) WarpedSource(bdv.img.WarpedSource) ProgressWriter(bdv.export.ProgressWriter) ThinplateSplineTransform(net.imglib2.realtransform.ThinplateSplineTransform) ImgLoaderHint(mpicbg.spim.data.generic.sequence.ImgLoaderHint) TimePoint(mpicbg.spim.data.sequence.TimePoint) ThinPlateR2LogRSplineKernelTransform(jitk.spline.ThinPlateR2LogRSplineKernelTransform) SourceAndConverter(bdv.viewer.SourceAndConverter) WrappedIterativeInvertibleRealTransform(net.imglib2.realtransform.inverse.WrappedIterativeInvertibleRealTransform) ProgressWriterConsole(bdv.export.ProgressWriterConsole)

Example 2 with SourceAndConverter

use of bdv.viewer.SourceAndConverter in project bigwarp by saalfeldlab.

the class BigWarp method addGridSource.

@SuppressWarnings({ "unchecked", "rawtypes" })
private static <T> SourceAndConverter<FloatType> addGridSource(final BigWarpData<T> data, final String name) {
    // TODO think about whether its worth it to pass a type parameter.
    // or should we just stick with Floats?
    final GridSource<FloatType> gridSource = new GridSource<>(name, data, new FloatType(), null);
    final RealARGBColorConverter<FloatType> converter = RealARGBColorConverter.create(new FloatType(), 0, 512);
    converter.setColor(new ARGBType(0xffffffff));
    final SourceAndConverter<FloatType> soc = new SourceAndConverter<>(gridSource, converter, null);
    data.converterSetups.add(BigDataViewer.createConverterSetup(soc, GRID_SOURCE_ID));
    data.sources.add((SourceAndConverter) soc);
    return soc;
}
Also used : GridSource(bigwarp.source.GridSource) SourceAndConverter(bdv.viewer.SourceAndConverter) ARGBType(net.imglib2.type.numeric.ARGBType) FloatType(net.imglib2.type.numeric.real.FloatType)

Example 3 with SourceAndConverter

use of bdv.viewer.SourceAndConverter in project bigwarp by saalfeldlab.

the class BigWarpInit method add.

@SuppressWarnings({ "unchecked", "rawtypes" })
public static <T> BigWarpData<?> add(BigWarpData bwdata, AbstractSpimData<?> data, int baseId, int numTimepoints, boolean isMoving) {
    final List<SourceAndConverter<?>> tmpSources = new ArrayList<>();
    final List<ConverterSetup> tmpConverterSetups = new ArrayList<>();
    initSetups(data, tmpConverterSetups, tmpSources);
    int setupId = baseId;
    for (SourceAndConverter sac : tmpSources) add(bwdata, sac.getSpimSource(), setupId++, numTimepoints, isMoving);
    // 
    return bwdata;
}
Also used : SourceAndConverter(bdv.viewer.SourceAndConverter) ArrayList(java.util.ArrayList) RealARGBColorConverterSetup(bdv.tools.brightness.RealARGBColorConverterSetup) ConverterSetup(bdv.tools.brightness.ConverterSetup)

Example 4 with SourceAndConverter

use of bdv.viewer.SourceAndConverter in project bigwarp by saalfeldlab.

the class ApplyBigwarpPlugin method apply.

public static <T> List<ImagePlus> apply(final BigWarpData<T> bwData, final LandmarkTableModel landmarks, final String tranformTypeOption, final String fieldOfViewOption, final String fieldOfViewPointFilter, final String resolutionOption, final double[] resolutionSpec, final double[] fovSpec, final double[] offsetSpec, final Interpolation interp, final boolean isVirtual, final int nThreads, final boolean wait, final WriteDestinationOptions writeOpts) {
    int numChannels = bwData.movingSourceIndices.length;
    int[] movingSourceIndexList = bwData.movingSourceIndices;
    List<SourceAndConverter<T>> sourcesxfm = BigWarp.wrapSourcesAsTransformed(bwData.sources, landmarks.getNumdims(), bwData);
    InvertibleRealTransform invXfm = new BigWarpTransform(landmarks, tranformTypeOption).getTransformation();
    for (int i = 0; i < numChannels; i++) {
        ((WarpedSource<?>) (sourcesxfm.get(movingSourceIndexList[i]).getSpimSource())).updateTransform(invXfm);
        ((WarpedSource<?>) (sourcesxfm.get(movingSourceIndexList[i]).getSpimSource())).setIsTransformed(true);
    }
    ProgressWriter progressWriter = new ProgressWriterIJ();
    // Generate the properties needed to generate the transform from output pixel space
    // to physical space
    final double[] res = getResolution(bwData, resolutionOption, resolutionSpec);
    List<Interval> outputIntervalList = getPixelInterval(bwData, landmarks, invXfm, fieldOfViewOption, fieldOfViewPointFilter, fovSpec, offsetSpec, res);
    final List<String> matchedPtNames = new ArrayList<>();
    if (outputIntervalList.size() > 1)
        ApplyBigwarpPlugin.fillMatchedPointNames(matchedPtNames, landmarks, fieldOfViewPointFilter);
    double[] offset = getPixelOffset(fieldOfViewOption, offsetSpec, res, outputIntervalList.get(0));
    if (writeOpts != null && writeOpts.n5Dataset != null && !writeOpts.n5Dataset.isEmpty()) {
        final String unit = ApplyBigwarpPlugin.getUnit(bwData, resolutionOption);
        ApplyBigwarpPlugin.runN5Export(bwData, sourcesxfm, fieldOfViewOption, outputIntervalList.get(0), interp, offset, res, unit, progressWriter, writeOpts, Executors.newFixedThreadPool(nThreads));
        return null;
    } else {
        final boolean show = (writeOpts.pathOrN5Root == null || writeOpts.pathOrN5Root.isEmpty());
        return runExport(bwData, sourcesxfm, fieldOfViewOption, outputIntervalList, matchedPtNames, interp, offset, res, isVirtual, nThreads, progressWriter, show, wait, writeOpts);
    }
}
Also used : InvertibleRealTransform(net.imglib2.realtransform.InvertibleRealTransform) WarpedSource(bdv.img.WarpedSource) ProgressWriter(bdv.export.ProgressWriter) ArrayList(java.util.ArrayList) ProgressWriterIJ(bdv.ij.util.ProgressWriterIJ) BigWarpTransform(bigwarp.transforms.BigWarpTransform) SourceAndConverter(bdv.viewer.SourceAndConverter) FinalInterval(net.imglib2.FinalInterval) Interval(net.imglib2.Interval) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval)

Example 5 with SourceAndConverter

use of bdv.viewer.SourceAndConverter in project bigdataviewer-biop-tools by BIOP.

the class BdvViewToImagePlusExportCommand method run.

@Override
public void run() {
    // At least one source
    if ((sacs == null) || (sacs.length == 0)) {
        logger.info("No selected source. Abort command.");
        return;
    }
    SourceAndConverter<?> model = createModelSource();
    boolean cacheImage = false;
    boolean virtual = false;
    switch(export_mode) {
        case "Normal":
            virtual = false;
            break;
        case "Virtual":
            virtual = true;
            cacheImage = true;
            break;
        case "Virtual no-cache":
            virtual = true;
            cacheImage = false;
            break;
        default:
            throw new UnsupportedOperationException("Unrecognized export mode " + export_mode);
    }
    // New to split by type.
    boolean cacheImageFinal = cacheImage;
    boolean virtualFinal = virtual;
    images = new ArrayList<>();
    List<SourceAndConverter<?>> sourceList = new ArrayList<>();
    Arrays.asList(sacs).forEach(sac -> sourceList.add(sac));
    Map<Class<net.imglib2.type.Type>, List<SourceAndConverter<?>>> typeToSources = sourceList.stream().collect(Collectors.groupingBy(src -> (Class<net.imglib2.type.Type>) (src.getSpimSource().getType().getClass())));
    typeToSources.keySet().forEach(pixelType -> {
        try {
            if (pixelType.equals(ARGBType.class) || pixelType.equals(VolatileARGBType.class)) {
                typeToSources.get(pixelType).forEach(source -> {
                    Task task = null;
                    if (monitor)
                        task = taskService.createTask("Bdv View export:" + capturename);
                    try {
                        images.add(ImagePlusSampler.Builder().cache(cacheImageFinal).virtual(virtualFinal).unit(unit).monitor(task).title(capturename).setModel(model).interpolate(interpolate).rangeT(selected_timepoints_str).sources(new SourceAndConverter[] { source }).get());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                });
            } else {
                Task task = null;
                if (monitor)
                    task = taskService.createTask("Bdv View export:" + capturename);
                images.add(ImagePlusSampler.Builder().cache(cacheImageFinal).virtual(virtualFinal).unit(unit).monitor(task).title(capturename).setModel(model).interpolate(interpolate).rangeT(selected_timepoints_str).sources(typeToSources.get(pixelType).toArray(new SourceAndConverter[0])).get());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    });
}
Also used : EmptySourceAndConverterCreator(sc.fiji.bdvpg.sourceandconverter.importer.EmptySourceAndConverterCreator) SourceAndConverter(bdv.viewer.SourceAndConverter) Arrays(java.util.Arrays) ARGBType(net.imglib2.type.numeric.ARGBType) BdvPlaygroundActionCommand(sc.fiji.bdvpg.scijava.command.BdvPlaygroundActionCommand) LoggerFactory(org.slf4j.LoggerFactory) ItemVisibility(org.scijava.ItemVisibility) ArrayList(java.util.ArrayList) TaskService(org.scijava.task.TaskService) Map(java.util.Map) AffineTransform3D(net.imglib2.realtransform.AffineTransform3D) ScijavaBdvDefaults(sc.fiji.bdvpg.scijava.ScijavaBdvDefaults) RealPoint(net.imglib2.RealPoint) Logger(org.slf4j.Logger) ItemIO(org.scijava.ItemIO) Parameter(org.scijava.plugin.Parameter) Task(org.scijava.task.Task) Collectors(java.util.stream.Collectors) BdvHandle(bdv.util.BdvHandle) ImagePlus(ij.ImagePlus) Type(net.imglib2.type.Type) Plugin(org.scijava.plugin.Plugin) List(java.util.List) VolatileARGBType(net.imglib2.type.volatiles.VolatileARGBType) ImagePlusSampler(ch.epfl.biop.sourceandconverter.exporter.ImagePlusSampler) Task(org.scijava.task.Task) ArrayList(java.util.ArrayList) SourceAndConverter(bdv.viewer.SourceAndConverter) ArrayList(java.util.ArrayList) List(java.util.List) ARGBType(net.imglib2.type.numeric.ARGBType) VolatileARGBType(net.imglib2.type.volatiles.VolatileARGBType) VolatileARGBType(net.imglib2.type.volatiles.VolatileARGBType)

Aggregations

SourceAndConverter (bdv.viewer.SourceAndConverter)117 AffineTransform3D (net.imglib2.realtransform.AffineTransform3D)40 BdvHandle (bdv.util.BdvHandle)33 AbstractSpimData (mpicbg.spim.data.generic.AbstractSpimData)26 ArrayList (java.util.ArrayList)23 RealPoint (net.imglib2.RealPoint)22 Collectors (java.util.stream.Collectors)20 ImageJ (net.imagej.ImageJ)17 List (java.util.List)16 ViewerTransformAdjuster (sc.fiji.bdvpg.bdv.navigate.ViewerTransformAdjuster)16 SourceAndConverterServices (sc.fiji.bdvpg.services.SourceAndConverterServices)15 ARGBType (net.imglib2.type.numeric.ARGBType)13 Logger (org.slf4j.Logger)13 LoggerFactory (org.slf4j.LoggerFactory)13 ConverterSetup (bdv.tools.brightness.ConverterSetup)12 FloatType (net.imglib2.type.numeric.real.FloatType)12 SpimDataFromXmlImporter (sc.fiji.bdvpg.spimdata.importer.SpimDataFromXmlImporter)12 Source (bdv.viewer.Source)11 File (java.io.File)11 java.util (java.util)11