use of bdv.spimdata.SpimDataMinimal in project labkit-ui by juglab.
the class HDF5Saver method writeXml.
private void writeXml() {
try {
BasicImgLoader imgLoader = new Hdf5ImageLoader(hdf5, partitions, data.getSequenceDescription());
SpimDataMinimal spimData = new SpimDataMinimal(data, imgLoader);
new XmlIoSpimDataMinimal().save(spimData, xml.getAbsolutePath());
} catch (SpimDataException e) {
throw new RuntimeException(e);
}
}
use of bdv.spimdata.SpimDataMinimal 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 bdv.spimdata.SpimDataMinimal 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 bdv.spimdata.SpimDataMinimal in project bigwarp by saalfeldlab.
the class ImagePlusLoader method loadAll.
public SpimDataMinimal[] loadAll(int startid) {
SpimDataMinimal[] out = new SpimDataMinimal[impList.length];
index = startid;
for (int i = 0; i < impList.length; i++) {
out[i] = load(index, impList[i]);
index += impList[i].getNChannels();
}
return out;
}
use of bdv.spimdata.SpimDataMinimal 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;
}
Aggregations