use of net.imglib2.type.numeric.integer.UnsignedByteType in project vcell by virtualcell.
the class ProjectService method load.
public Task<Project, String> load(File root) {
final Task<Project, String> task = new Task<Project, String>() {
@Override
protected Project doInBackground() throws Exception {
Project project = new Project(root.getName());
String rootPath = root.getAbsolutePath();
File[] dataFiles = Paths.get(rootPath, "data").toFile().listFiles();
File[] geometryFiles = Paths.get(rootPath, "geometry").toFile().listFiles();
File[] modelDirectories = Paths.get(rootPath, "models").toFile().listFiles();
File[] resultsFiles = Paths.get(rootPath, "results").toFile().listFiles();
int numFiles = dataFiles.length + geometryFiles.length + modelDirectories.length + resultsFiles.length;
int numLoaded = 0;
if (dataFiles != null) {
for (File dataFile : dataFiles) {
try {
setSubtask(dataFile.getName());
Dataset data = datasetIOService.open(dataFile.getAbsolutePath());
project.getData().add(data);
numLoaded++;
setProgress(numLoaded * 100 / numFiles);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (geometryFiles != null) {
for (File geometryFile : geometryFiles) {
try {
setSubtask(geometryFile.getName());
Dataset geometry = datasetIOService.open(geometryFile.getAbsolutePath());
// Geometry datasets are saved as 8-bit images so we must convert back to 1-bit
if (geometry.firstElement() instanceof UnsignedByteType) {
@SuppressWarnings("unchecked") Img<UnsignedByteType> img = (Img<UnsignedByteType>) geometry.getImgPlus().getImg();
Img<BitType> converted = opService.convert().bit(img);
ImgPlus<BitType> convertedImgPlus = new ImgPlus<>(converted, geometry.getName());
geometry.setImgPlus(convertedImgPlus);
}
project.getGeometry().add(geometry);
numLoaded++;
setProgress(numLoaded * 100 / numFiles);
} catch (IOException e) {
e.printStackTrace();
}
}
}
if (modelDirectories != null) {
for (File modelDirectory : modelDirectories) {
setSubtask(modelDirectory.getName());
SBMLDocument sbmlDocument = null;
BufferedImage image = null;
File[] modelFiles = modelDirectory.listFiles();
System.out.println(modelFiles.length);
// Invalid model directory
if (modelFiles.length > 2)
continue;
for (File modelFile : modelFiles) {
System.out.println(modelFile.getName());
if (FilenameUtils.getExtension(modelFile.getName()).equals("xml")) {
sbmlDocument = new SBMLReader().readSBML(modelFile);
System.out.println("Loaded sbml");
} else if (FilenameUtils.getExtension(modelFile.getName()).equals("png")) {
image = ImageIO.read(modelFile);
System.out.println("Loaded image");
}
}
if (sbmlDocument != null) {
VCellModel vCellModel = new VCellModel(modelDirectory.getName(), null, sbmlDocument);
vCellModel.setImage(image);
project.getModels().add(vCellModel);
System.out.println("Added model");
}
numLoaded++;
setProgress(numLoaded * 100 / numFiles);
}
}
if (resultsFiles != null) {
for (File resultsFile : resultsFiles) {
try {
setSubtask(resultsFile.getName());
Dataset results = datasetIOService.open(resultsFile.getAbsolutePath());
// Loading 1-dimensional tif images adds a dimension
// so must crop out empty dimensions
@SuppressWarnings("unchecked") ImgPlus<T> imgPlus = (ImgPlus<T>) results.getImgPlus();
int numDimensions = imgPlus.numDimensions();
long[] dimensions = new long[2 * imgPlus.numDimensions()];
for (int i = 0; i < numDimensions; i++) {
dimensions[i] = 0;
dimensions[i + numDimensions] = imgPlus.dimension(i) - 1;
}
FinalInterval interval = Intervals.createMinMax(dimensions);
ImgPlus<T> cropped = opService.transform().crop(imgPlus, interval, true);
results.setImgPlus(cropped);
project.getResults().add(results);
numLoaded++;
setProgress(numLoaded * 100 / numFiles);
} catch (IOException e) {
e.printStackTrace();
}
}
}
currentProjectRoot = root;
return project;
}
};
return task;
}
use of net.imglib2.type.numeric.integer.UnsignedByteType in project vcell by virtualcell.
the class TestJettyService method exerciseService.
public static void exerciseService() {
try {
// HttpClient httpClient = new HttpClient();
// HostConfiguration hostConfiguration = new HostConfiguration();
// hostConfiguration.setHost("localhost",8080);
// HttpMethod method = new GetMethod("/list?type=biom");
// int var = httpClient.executeMethod(hostConfiguration, method);
// System.out.println("result="+var);
//
// method = new GetMethod("/");
// var = httpClient.executeMethod(hostConfiguration, method);
// System.out.println("result="+var);
// search for port that vcell is providing IJ related services on
int lastVCellApiPort = VCellHelper.findVCellApiServerPort();
// get rest api
System.out.println(VCellHelper.getApiInfo() + "\n");
URL[] testUrls = new URL[] { new URL("http://localhost:" + lastVCellApiPort + "/" + "getinfo" + "?" + "open=true" + "&" + "type" + "=" + "quick") // new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=true"+"&"+"type"+"="+"bm"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=true"+"&"+"type"+"="+"mm"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=false"+"&"+"type"+"="+"quick"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=false"+"&"+"type"+"="+"bm"),
// new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=false"+"&"+"type"+"="+"mm")
};
for (int i = 0; i < testUrls.length; i++) {
System.out.println("----------Test " + i + ": " + testUrls[i].toString());
// System.out.println(VCellHelper.getRawContent(testUrls[i]));
Document doc = VCellHelper.getDocument(testUrls[i]);
printDocument(doc, System.out);
Node simNode = doc.getElementsByTagName("simInfo").item(0);
String cachekey = simNode.getAttributes().getNamedItem("cacheKey").getNodeValue();
URL varInfoUrl = new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + "cachekey" + "=" + cachekey);
System.out.println(" --varInfo=" + varInfoUrl.toString());
System.out.println(VCellHelper.getRawContent(varInfoUrl));
doc = VCellHelper.getDocument(varInfoUrl);
ArrayList<Double> times = new ArrayList<>();
Node timeNode = doc.getElementsByTagName("times").item(0);
StringTokenizer st = new StringTokenizer(timeNode.getTextContent(), ",");
while (st.hasMoreTokens()) {
StringTokenizer timepointT = new StringTokenizer(st.nextToken(), "='");
timepointT.nextToken();
times.add(Double.parseDouble(timepointT.nextToken()));
}
String varName = null;
NodeList varNodes = doc.getElementsByTagName("ijVarInfo");
for (int j = 0; j < varNodes.getLength(); j++) {
if (varNodes.item(j).getAttributes().getNamedItem("variableType").getNodeValue().equals("Volume")) {
varName = varNodes.item(j).getAttributes().getNamedItem("name").getNodeValue();
break;
}
}
URL dataUrl = new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + "cachekey" + "=" + cachekey + "&" + "varname" + "=" + varName + "&" + "timepoint" + "=" + times.get(times.size() / 2) + "&" + "jobid=0");
System.out.println(" --data=" + dataUrl.toString());
doc = VCellHelper.getDocument(dataUrl);
BasicStackDimensions basicStackDimensions = VCellHelper.getVCStackDims(doc);
double[] data = VCellHelper.getData(doc);
System.out.println(basicStackDimensions.getTotalSize());
System.out.println(data.length);
}
if (true) {
return;
}
int cachekey = 4;
// get rest api
System.out.println(VCellHelper.getApiInfo());
// System.out.println(VCellHelper.getRawContent(new URL("http://localhost:"+lastVCellApiPort+"/"+"getinfo"+"?"+"open=true"+"&"+"type"+"="+"bm")));//generate cachekeys user can reference to get data
// get variable names
System.out.println(VCellHelper.getRawContent(new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + /*+"open=true"+"&"*/
"cachekey" + "=" + cachekey)));
// get data
Document doc = VCellHelper.getDocument(new URL("http://localhost:" + lastVCellApiPort + "/" + "getdata" + "?" + "cachekey" + "=" + cachekey + "&" + "varname" + "=" + "C_cyt" + "&" + "timepoint" + "=5.55394648006857" + "&" + "jobid=0"));
BasicStackDimensions basicStackDimensions = VCellHelper.getVCStackDims(doc);
double[] data = VCellHelper.getData(doc);
System.out.println(basicStackDimensions.getTotalSize());
System.out.println(data.length);
long[] dims = new long[basicStackDimensions.numDimensions()];
basicStackDimensions.dimensions(dims);
ArrayImg<DoubleType, DoubleArray> img = ArrayImgs.doubles(data, dims);
// ArrayImg<DoubleType, DoubleArray> img = (ArrayImg<DoubleType, DoubleArray>)new ArrayImgFactory< DoubleType >().create( basicStackDimensions, new DoubleType() );
// ArrayCursor<DoubleType> cursor = img.cursor();
// while(cursor.hasNext()) {
// cursor.next().set
// }
// Img< UnsignedByteType > img = new ArrayImgFactory< UnsignedByteType >().create( new long[] { 400, 320 }, new UnsignedByteType() );
ImageJFunctions.show(img);
DialogUtils.showInfoDialog(JOptionPane.getRootFrame(), "blah");
// JAXBContext jaxbContext = JAXBContext.newInstance(IJData.class);
// Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
// IJData ijData = (IJData) jaxbUnmarshaller.unmarshal(new URL("http://localhost:8080/"+ApiEnum.getdata.name()+"?"/*+"open=true"+"&"*/+IJGetDataParams.cachekey.name()+"=0"));
// System.out.println(ijData);
// URLConnection con = url.openConnection();
// InputStream in = con.getInputStream();
// String encoding = con.getContentEncoding();
// encoding = encoding == null ? "UTF-8" : encoding;
// String body = IOUtils.toString(in, encoding);
// System.out.println(body);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of net.imglib2.type.numeric.integer.UnsignedByteType in project vcell by virtualcell.
the class SmallCR method openExample.
public static ExampleDatasets openExample(ImageJ ij, File exampleDataDir) throws Exception {
final String[] exampleFiles = new String[] { "Experimental.zip", "Seg Geom_3d.zip", "PreBleach.zip", "Analysis ROI.zip" };
// final String[] exampleFiles = new String[] {"testDiff_1_2.zip","Seg Geom_3d.zip","testPreBleach.zip","Analysis ROI.zip"};// for test
// List<Display<?>> displays0 = ij.display().getDisplays();
// for (Display<?> display : displays0) {
// System.out.println("----------disp "+display.getName()+" "+display.getIdentifier());
// }
List<ImageDisplay> knownImageDisplays = ij.imageDisplay().getImageDisplays();
// for (ImageDisplay imageDisplay : imageDisplays0) {
// System.out.println("----------imgdisp "+imageDisplay.getName()+" "+imageDisplay.getIdentifier());
// }
// 2D
ImgPlus<? extends RealType<?>> experimentalData = null;
// 2D or 3D (if 3D will be z-project for analysis withg 2D experimental data)
ImgPlus<UnsignedByteType> segmentedGeom = null;
// 2D
ImgPlus<? extends RealType<?>> preBleachImage = null;
// 2D
ImgPlus<UnsignedByteType> analysisROI = null;
// Open example images if they are not already open
for (int exampleFilesIndex = 0; exampleFilesIndex < exampleFiles.length; exampleFilesIndex++) {
DefaultDataset exampleFileDataset = null;
for (ImageDisplay imageDisplay : knownImageDisplays) {
if (imageDisplay.getName().equals(exampleFiles[exampleFilesIndex])) {
exampleFileDataset = (DefaultDataset) imageDisplay.getActiveView().getData();
break;
}
}
if (exampleFileDataset == null) {
exampleFileDataset = (DefaultDataset) ij.io().open(new File(exampleDataDir, exampleFiles[exampleFilesIndex]).getAbsolutePath());
// ij.ui().show(exampleFileDataset);
showAndZoom(ij, exampleFiles[exampleFilesIndex], exampleFileDataset, 4);
}
// Print names of axes (x,y,z,time,channel,unknown,...)
System.out.print(exampleFileDataset.getName() + ": ");
for (int dimensionIndex = 0; dimensionIndex < exampleFileDataset.numDimensions(); dimensionIndex++) {
System.out.print((exampleFileDataset.axis(dimensionIndex) != null ? exampleFileDataset.axis(dimensionIndex).type().toString() + " " : "null "));
}
System.out.println();
// Assign variables (defaultDataset corresponds to open 'exampleFiles' element
switch(exampleFilesIndex) {
case 0:
experimentalData = exampleFileDataset.getImgPlus();
break;
case 1:
segmentedGeom = (ImgPlus<UnsignedByteType>) exampleFileDataset.getImgPlus();
break;
case 2:
preBleachImage = exampleFileDataset.getImgPlus();
break;
case 3:
analysisROI = (ImgPlus<UnsignedByteType>) exampleFileDataset.getImgPlus();
break;
}
}
return new ExampleDatasets(experimentalData, preBleachImage, segmentedGeom, analysisROI);
}
use of net.imglib2.type.numeric.integer.UnsignedByteType in project vcell by virtualcell.
the class SmallCR method createGeometry.
public static IJGeom createGeometry(ImgPlus<UnsignedByteType> nonZProjectedSegmentedGeom, int xIndex, int yIndex, int assumedZIndex, int xsize, int ysize, int zsize, HashMap<Integer, String> segmentedGeomValuesMapSubvolumeName) throws Exception {
// Create byte array that defines vcell subvolumes ids (handles)
byte[] vcellSubvolumeHandles = new byte[(int) Intervals.numElements(nonZProjectedSegmentedGeom)];
Cursor<UnsignedByteType> nonZProjectedSegmentedGeomCursor = nonZProjectedSegmentedGeom.localizingCursor();
while (nonZProjectedSegmentedGeomCursor.hasNext()) {
UnsignedByteType segmentedGeomValue = (UnsignedByteType) nonZProjectedSegmentedGeomCursor.next();
int currentZ = (assumedZIndex == -1 ? 0 : nonZProjectedSegmentedGeomCursor.getIntPosition(assumedZIndex));
int currXYPixelIndex = nonZProjectedSegmentedGeomCursor.getIntPosition(yIndex) * xsize + nonZProjectedSegmentedGeomCursor.getIntPosition(xIndex);
int currXYZPixelIndex = currXYPixelIndex + (assumedZIndex == -1 ? 0 : currentZ * (xsize * ysize));
vcellSubvolumeHandles[currXYZPixelIndex] = (byte) segmentedGeomValue.get();
}
// Define new Geometry with domain equal to xyz pixel size for ease of use
String[] subvolumeNames = segmentedGeomValuesMapSubvolumeName.values().toArray(new String[0]);
Integer[] subvolumePixelValues = segmentedGeomValuesMapSubvolumeName.keySet().toArray(new Integer[0]);
double[] origin = new double[] { 0, 0, 0 };
double[] extent = new double[] { xsize, ysize, zsize };
IJGeom ijGeom = new IJGeom(subvolumeNames, subvolumePixelValues, xsize, ysize, zsize, origin, extent, vcellSubvolumeHandles);
return ijGeom;
}
use of net.imglib2.type.numeric.integer.UnsignedByteType in project imagej-ops by imagej.
the class TubenessTest method testTubeness.
@Test
public void testTubeness() {
Img<UnsignedByteType> input = openUnsignedByteType(Ops.class, "TubesInput.png");
Img<DoubleType> expected = openDoubleImg("tube.tif");
final double scale = 5;
final double sigma = scale / Math.sqrt(2);
Img<DoubleType> actual = ops.create().img(input, new DoubleType());
ops.filter().tubeness(actual, input, sigma);
assertIterationsEqual(expected, actual);
}
Aggregations