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;
}
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;
}
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;
}
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);
}
}
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();
}
});
}
Aggregations