use of mpicbg.spim.data.registration.ViewRegistration in project labkit-ui by juglab.
the class HDF5Saver method oneImageSpimData.
private static <T> SpimDataMinimal oneImageSpimData(List<RandomAccessibleInterval<T>> frames, File basePath) {
List<TimePoint> timePointList = IntStream.range(0, frames.size()).mapToObj(TimePoint::new).collect(Collectors.toList());
final TimePoints timePoints = new TimePoints(timePointList);
final BasicViewSetup setup = new BasicViewSetup(0, "image", (Dimensions) frames.get(0), new FinalVoxelDimensions("pixel", 1, 1, 1));
final Map<Integer, BasicViewSetup> setups = Collections.singletonMap(0, setup);
final MissingViews missingViews = null;
BasicImgLoader imgLoader = new BasicImgLoader() {
@Override
public BasicSetupImgLoader<T> getSetupImgLoader(int i) {
if (i != setup.getId())
throw new IllegalArgumentException();
return new BasicSetupImgLoader<T>() {
@Override
public RandomAccessibleInterval<T> getImage(int timeId, ImgLoaderHint... imgLoaderHints) {
return frames.get(timeId);
}
@Override
public T getImageType() {
return Util.getTypeFromInterval(frames.get(0));
}
};
}
};
final SequenceDescriptionMinimal sequence = new SequenceDescriptionMinimal(timePoints, setups, imgLoader, missingViews);
List<ViewRegistration> viewRegistrationList = timePointList.stream().map(x -> new ViewRegistration(x.getId(), setup.getId())).collect(Collectors.toList());
ViewRegistrations registrations = new ViewRegistrations(viewRegistrationList);
return new SpimDataMinimal(basePath, sequence, registrations);
}
use of mpicbg.spim.data.registration.ViewRegistration in project bigwarp by saalfeldlab.
the class BigWarpBatchTransform method createSpimData.
public static final SpimDataMinimal createSpimData(IFormatReader reader) {
Hashtable<String, Object> gmeta = reader.getGlobalMetadata();
// header stuff here TODO
System.out.println(gmeta);
// get relevant metadata
double pw = 1.0;
double ph = 1.0;
double pd = 1.0;
if (gmeta.keySet().contains("XResolution"))
pw = ((Double) gmeta.get("XResolution")).doubleValue();
if (gmeta.keySet().contains("YResolution"))
ph = ((Double) gmeta.get("YResolution")).doubleValue();
if (gmeta.keySet().contains("Spacing"))
pd = ((Double) gmeta.get("Spacing")).doubleValue();
int numSetups = 1;
int numTimepoints = 1;
int[] ids = new int[] { 349812342 };
final File basePath = new File(".");
String punit = "px";
if (gmeta.keySet().contains("Unit"))
punit = (String) gmeta.get("Unit");
final FinalVoxelDimensions voxelSize = new FinalVoxelDimensions(punit, pw, ph, pd);
final long w = ((Long) gmeta.get("ImageWidth")).longValue();
final long h = ((Long) gmeta.get("ImageLength")).longValue();
// Long.parseLong( (String)gmeta.get("images") );
final long d = reader.getSizeZ();
long[] dims = new long[] { w, h, d };
final FinalDimensions size = new FinalDimensions(new long[] { w, h, d });
// create setups from channels
final HashMap<Integer, BasicViewSetup> setups = new HashMap<Integer, BasicViewSetup>(numSetups);
for (int s = 0; s < numSetups; ++s) {
final BasicViewSetup setup = new BasicViewSetup(ids[s], String.format("channel %d", ids[s] + 1), size, voxelSize);
setup.setAttribute(new Channel(ids[s] + 1));
setups.put(ids[s], setup);
}
// create timepoints
final ArrayList<TimePoint> timepoints = new ArrayList<TimePoint>(numTimepoints);
for (int t = 0; t < numTimepoints; ++t) timepoints.add(new TimePoint(t));
// create ViewRegistrations from the images calibration
final AffineTransform3D sourceTransform = new AffineTransform3D();
sourceTransform.set(1.0 / pw, 0, 0, 0, 0, 1.0 / ph, 0, 0, 0, 0, pd, 0);
final ArrayList<ViewRegistration> registrations = new ArrayList<ViewRegistration>();
for (int t = 0; t < numTimepoints; ++t) for (int s = 0; s < numSetups; ++s) registrations.add(new ViewRegistration(t, ids[s], sourceTransform));
final SequenceDescriptionMinimal seq = new SequenceDescriptionMinimal(new TimePoints(timepoints), setups, new DummyImageLoader<FloatType>(new FloatType(), dims), null);
SpimDataMinimal spimData = new SpimDataMinimal(basePath, seq, new ViewRegistrations(registrations));
if (WrapBasicImgLoader.wrapImgLoaderIfNecessary(spimData))
System.err.println("WARNING:\nOpening <SpimData> dataset that is not suited for interactive browsing.\nConsider resaving as HDF5 for better performance.");
return spimData;
}
use of mpicbg.spim.data.registration.ViewRegistration in project bigwarp by saalfeldlab.
the class ImagePlusLoader method load.
public SpimDataMinimal load(final int setupIdOffset, ImagePlus imp) {
// get calibration and image size
final double pw;
final double ph;
final double pd;
pw = sanitizeCalibration(imp.getCalibration().pixelWidth, "x");
ph = sanitizeCalibration(imp.getCalibration().pixelHeight, "y");
pd = sanitizeCalibration(imp.getCalibration().pixelDepth, "z");
String punit = imp.getCalibration().getUnit();
if (punit == null || punit.isEmpty())
punit = "px";
final FinalVoxelDimensions voxelSize = new FinalVoxelDimensions(punit, pw, ph, pd);
final int w = imp.getWidth();
final int h = imp.getHeight();
final int d = imp.getNSlices();
final int numTimepoints = imp.getNFrames();
final int numSetups = imp.getNChannels();
final FinalDimensions size = new FinalDimensions(new int[] { w, h, d });
is3d = (d > 1);
isMultiChannel = (numSetups > 1);
// create ImgLoader wrapping the image
final BasicImgLoader imgLoader;
if (imp.getStack().isVirtual()) {
switch(imp.getType()) {
case ImagePlus.GRAY8:
imgLoader = VirtualStackImageLoader.createUnsignedByteInstance(imp, setupIdOffset);
break;
case ImagePlus.GRAY16:
imgLoader = VirtualStackImageLoader.createUnsignedShortInstance(imp, setupIdOffset);
break;
case ImagePlus.GRAY32:
imgLoader = VirtualStackImageLoader.createFloatInstance(imp, setupIdOffset);
break;
case ImagePlus.COLOR_RGB:
default:
imgLoader = VirtualStackImageLoader.createARGBInstance(imp, setupIdOffset);
break;
}
} else {
switch(imp.getType()) {
case ImagePlus.GRAY8:
imgLoader = ImageStackImageLoader.createUnsignedByteInstance(imp, setupIdOffset);
break;
case ImagePlus.GRAY16:
imgLoader = ImageStackImageLoader.createUnsignedShortInstance(imp, setupIdOffset);
break;
case ImagePlus.GRAY32:
imgLoader = ImageStackImageLoader.createFloatInstance(imp, setupIdOffset);
break;
case ImagePlus.COLOR_RGB:
default:
imgLoader = ImageStackImageLoader.createARGBInstance(imp, setupIdOffset);
break;
}
}
final File basePath = new File(".");
// create setups from channels
final HashMap<Integer, BasicViewSetup> setups = new HashMap<Integer, BasicViewSetup>(numSetups);
for (int s = 0; s < numSetups; ++s) {
final int id = setupIdOffset + s;
final BasicViewSetup setup = new BasicViewSetup(setupIdOffset + s, String.format("%s channel %d", imp.getTitle(), id + 1), size, voxelSize);
setup.setAttribute(new Channel(id + 1));
setups.put(id, setup);
settingsMap.put(id, ColorSettings.fromImagePlus(imp, id, s));
}
// create timepoints
final ArrayList<TimePoint> timepoints = new ArrayList<TimePoint>(numTimepoints);
for (int t = 0; t < numTimepoints; ++t) timepoints.add(new TimePoint(t));
// create ViewRegistrations from the images calibration
final AffineTransform3D sourceTransform = new AffineTransform3D();
sourceTransform.set(pw, 0, 0, 0, 0, ph, 0, 0, 0, 0, pd, 0);
final ArrayList<ViewRegistration> registrations = new ArrayList<ViewRegistration>();
for (int t = 0; t < numTimepoints; ++t) for (int s = 0; s < numSetups; ++s) registrations.add(new ViewRegistration(t, setupIdOffset + s, sourceTransform));
final SequenceDescriptionMinimal seq = new SequenceDescriptionMinimal(new TimePoints(timepoints), setups, imgLoader, null);
SpimDataMinimal spimData = new SpimDataMinimal(basePath, seq, new ViewRegistrations(registrations));
WrapBasicImgLoader.wrapImgLoaderIfNecessary(spimData);
return spimData;
}
use of mpicbg.spim.data.registration.ViewRegistration in project multiview-simulation by PreibischLab.
the class SimulatedBeadsImgLoader2 method createViewRegistrationsFromImgLoader.
public static ViewRegistrations createViewRegistrationsFromImgLoader(SimulatedBeadsImgLoader2 imgLoader, double relativeTileError, boolean centerAngles) {
SimulateBeads2 sb = imgLoader.getSimulateBeads();
final HashMap<ViewId, ViewRegistration> viewRegistrationList = new HashMap<ViewId, ViewRegistration>();
final RealInterval tilesExtent = sb.getTilesExtent();
double[] center = new double[tilesExtent.numDimensions()];
tilesExtent.realMax(center);
for (int d = 0; d < center.length; d++) center[d] /= -2.0;
for (int tp : new ArrayList<>(sb.tpTransforms.keySet()).stream().sorted().collect(Collectors.toList())) {
int vid = 0;
for (int a : new ArrayList<>(sb.angleTransforms.keySet()).stream().sorted().collect(Collectors.toList())) for (int channel : new ArrayList<>(sb.channelTransforms.keySet()).stream().sorted().collect(Collectors.toList())) for (int illum : new ArrayList<>(sb.illumTransforms.keySet()).stream().sorted().collect(Collectors.toList())) for (int tile : new ArrayList<>(sb.tileTransforms.keySet()).stream().sorted().collect(Collectors.toList())) {
final VoxelDimensions voxelSize = new FinalVoxelDimensions("pixels", 1, 1, 1);
final Dimensions dim = imgLoader.getSimulateBeads().getImg(0, a, channel, tile, illum);
final ViewRegistration viewRegistration = new ViewRegistration(tp, vid++);
final double calX = voxelSize.dimension(0);
final double calY = voxelSize.dimension(1);
final double calZ = voxelSize.dimension(2);
final AffineTransform3D m = new AffineTransform3D();
m.set(calX, 0.0f, 0.0f, 0.0f, 0.0f, calY, 0.0f, 0.0f, 0.0f, 0.0f, calZ, 0.0f);
final ViewTransform vt = new ViewTransformAffine("calibration", m);
viewRegistration.preconcatenateTransform(vt);
double[] translation = sb.tileTransforms.get(tile).inverse().getTranslation();
for (int i = 0; i < translation.length; i++) translation[i] *= relativeTileError;
AffineTransform3D atr = new AffineTransform3D();
atr.translate(translation);
final ViewTransform vtT = new ViewTransformAffine("translation", atr.copy());
viewRegistration.preconcatenateTransform(vtT);
if (centerAngles) {
AffineTransform3D centerTr = new AffineTransform3D();
centerTr.translate(center);
final ViewTransform centerVt = new ViewTransformAffine("center angle", centerTr.copy());
viewRegistration.preconcatenateTransform(centerVt);
}
final ViewTransform vtA = new ViewTransformAffine("rotation", sb.angleTransforms.get(a));
viewRegistration.preconcatenateTransform(vtA);
viewRegistrationList.put(viewRegistration, viewRegistration);
}
}
return new ViewRegistrations(viewRegistrationList);
}
use of mpicbg.spim.data.registration.ViewRegistration in project bigdataviewer-biop-tools by BIOP.
the class LifReOrdered method constructSpimData.
public AbstractSpimData constructSpimData() {
Map<Integer, ViewSetup> idToNewViewSetups = new HashMap<>();
// No Illumination
List<ViewSetup> newViewSetups = new ArrayList<>();
int maxTimePoint = spimdataOrigin.getViewRegistrations().getViewRegistrations().keySet().stream().map(this::originToReorderedLocation).mapToInt(viewId -> viewId.getTimePointId()).max().getAsInt() + 1;
logger.debug("Reordered spimdata max timepoint = " + maxTimePoint);
List<TimePoint> timePoints = new ArrayList<>();
IntStream.range(0, maxTimePoint).forEach(tp -> timePoints.add(new TimePoint(tp)));
final ArrayList<ViewRegistration> registrations = new ArrayList<>();
List<ViewId> missingViews = new ArrayList<>();
spimdataOrigin.getViewRegistrations().getViewRegistrations().keySet().stream().forEach(originViewId -> {
ViewId newViewId = originToReorderedLocation(originViewId);
// Create ViewSetup if it doesn't exist
if (!idToNewViewSetups.containsKey(newViewId.getViewSetupId())) {
BasicViewSetup bvs = (BasicViewSetup) spimdataOrigin.getSequenceDescription().getViewSetups().get(originViewId.getViewSetupId());
ViewSetup newViewSetup = new ViewSetup(newViewId.getViewSetupId(), bvs.getName(), bvs.getSize(), bvs.getVoxelSize(), bvs.getAttribute(Channel.class), bvs.getAttribute(Angle.class), bvs.getAttribute(Illumination.class));
bvs.getAttributes().forEach((name, entity) -> {
logger.debug("ViewSetupId : " + bvs.getId() + " " + name + ":" + entity);
newViewSetup.setAttribute(entity);
});
newViewSetups.add(newViewSetup);
idToNewViewSetups.put(newViewId.getViewSetupId(), newViewSetup);
}
// Create View Registration
registrations.add(new ViewRegistration(newViewId.getTimePointId(), newViewId.getViewSetupId(), spimdataOrigin.getViewRegistrations().getViewRegistration(originViewId).getModel()));
});
newViewSetups.forEach(vs -> logger.debug(vs.getName()));
logger.debug("Reordered spimdata number of setups = " + newViewSetups.size());
SequenceDescription sd = new SequenceDescription(new TimePoints(timePoints), newViewSetups, null, new MissingViews(missingViews));
sd.setImgLoader(new ReorderedImageLoader(this, sd, 4, 2));
final SpimData spimData = new SpimData(null, sd, new ViewRegistrations(registrations));
return spimData;
}
Aggregations