use of net.imglib2.img.array.ArrayImgFactory in project vcell by virtualcell.
the class VCellResultService method importCsv.
public Dataset importCsv(File directory) throws FileNotFoundException {
File[] files = directory.listFiles();
// TODO: Better handling
if (files == null)
return null;
ArrayList<ArrayList<Float>> timeSeries = new ArrayList<>(files.length);
Scanner scanner;
int dataSize = 0;
for (File file : files) {
scanner = new Scanner(file);
scanner.useDelimiter("[,\n]");
while (scanner.hasNext() && !scanner.hasNextDouble()) {
scanner.next();
}
if (!scanner.hasNextDouble()) {
scanner.close();
return null;
}
ArrayList<Float> data = new ArrayList<>();
while (scanner.hasNextDouble()) {
data.add(scanner.nextFloat());
}
scanner.close();
timeSeries.add(data);
dataSize = data.size();
}
int[] dimensions = { dataSize, timeSeries.size() };
Img<FloatType> img = new ArrayImgFactory<FloatType>().create(dimensions, new FloatType());
Cursor<FloatType> cursor = img.localizingCursor();
while (cursor.hasNext()) {
cursor.next();
int xPos = cursor.getIntPosition(0);
int tPos = cursor.getIntPosition(1);
Float val = timeSeries.get(tPos).get(xPos);
cursor.get().set(val);
}
Dataset dataset = datasetService.create(img);
// Drop single dimensions
@SuppressWarnings("unchecked") ImgPlus<FloatType> imgPlus = (ImgPlus<FloatType>) dataset.getImgPlus();
FinalInterval interval = Intervals.createMinMax(0, 0, imgPlus.dimension(0) - 1, imgPlus.dimension(1) - 1);
ImgPlus<FloatType> cropped = ops.transform().crop(imgPlus, interval, true);
dataset.setImgPlus(cropped);
System.out.println(dataset.numDimensions());
dataset.setName(directory.getName());
return dataset;
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class FlatIterableViewTest method defaultFlatIterableTest.
@Test
public void defaultFlatIterableTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
Cursor<DoubleType> il2 = Views.flatIterable(img).cursor();
Cursor<DoubleType> opr = ops.transform().flatIterableView(img).cursor();
while (il2.hasNext()) {
il2.next();
opr.next();
assertEquals(il2.getDoublePosition(0), opr.getDoublePosition(0), 1e-10);
assertEquals(il2.getDoublePosition(1), opr.getDoublePosition(1), 1e-10);
}
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class HyperSliceViewTest method defaultHyperSliceTest.
@Test
public void defaultHyperSliceTest() {
final Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10, 10 }, new DoubleType());
final MixedTransformView<DoubleType> il2 = Views.hyperSlice((RandomAccessible<DoubleType>) img, 1, 8);
final MixedTransformView<DoubleType> opr = ops.transform().hyperSliceView(deinterval(img), 1, 8);
for (int i = 0; i < il2.getTransformToSource().getMatrix().length; i++) {
for (int j = 0; j < il2.getTransformToSource().getMatrix()[i].length; j++) {
assertEquals(il2.getTransformToSource().getMatrix()[i][j], opr.getTransformToSource().getMatrix()[i][j], 1e-10);
}
}
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class IntervalViewTest method intervalMinMaxTest.
@Test
public void intervalMinMaxTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
Random r = new Random();
for (DoubleType d : img) {
d.set(r.nextDouble());
}
Cursor<DoubleType> il2 = Views.interval(img, new long[] { 1, 1 }, new long[] { 8, 9 }).localizingCursor();
RandomAccess<DoubleType> opr = ops.transform().intervalView(img, new long[] { 1, 1 }, new long[] { 8, 9 }).randomAccess();
while (il2.hasNext()) {
DoubleType e = il2.next();
opr.setPosition(il2);
assertEquals(e.get(), opr.get().get(), 1e-10);
}
}
use of net.imglib2.img.array.ArrayImgFactory in project imagej-ops by imagej.
the class IntervalViewTest method defaultIntervalTest.
@Test
public void defaultIntervalTest() {
Img<DoubleType> img = new ArrayImgFactory<DoubleType>().create(new int[] { 10, 10 }, new DoubleType());
Random r = new Random();
for (DoubleType d : img) {
d.set(r.nextDouble());
}
Cursor<DoubleType> il2 = Views.interval(img, img).localizingCursor();
RandomAccess<DoubleType> opr = ops.transform().intervalView(img, img).randomAccess();
while (il2.hasNext()) {
DoubleType e = il2.next();
opr.setPosition(il2);
assertEquals(e.get(), opr.get().get(), 1e-10);
}
}
Aggregations