Search in sources :

Example 1 with ImgPlus

use of net.imagej.ImgPlus in project imagej-ops by imagej.

the class CropTest method testCropTypes.

/**
 * Verifies that the types of the objects returned are correct.
 */
@Test
public void testCropTypes() {
    // Set-up interval
    final Interval defInterval = new FinalInterval(new long[] { 0, 0, 0 }, new long[] { 19, 19, 19 });
    final Interval smallerInterval = new FinalInterval(new long[] { 0, 0, 0 }, new long[] { 19, 19, 18 });
    // check if result is ImgView
    assertTrue(ops.run(CropRAI.class, in, defInterval) instanceof Img);
    // check if result is ImgPlus
    final Object imgPlus = ops.run(CropImgPlus.class, new ImgPlus<>(in), defInterval);
    assertTrue(imgPlus instanceof ImgPlus);
    // check if result is RandomAccessibleInterval
    final Object run = ops.run(CropRAI.class, Views.interval(in, smallerInterval), smallerInterval);
    assertTrue(run instanceof RandomAccessibleInterval && !(run instanceof Img));
}
Also used : Img(net.imglib2.img.Img) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) ImgPlus(net.imagej.ImgPlus) FinalInterval(net.imglib2.FinalInterval) RandomAccessibleInterval(net.imglib2.RandomAccessibleInterval) Interval(net.imglib2.Interval) FinalInterval(net.imglib2.FinalInterval) AbstractOpTest(net.imagej.ops.AbstractOpTest) Test(org.junit.Test)

Example 2 with ImgPlus

use of net.imagej.ImgPlus in project vcell by virtualcell.

the class VCellPlugin_Minimal method run.

// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
// public void showAndZoom(String displayName,Object thingToDisplay,double zoomFactor) throws Exception{
// final ImageDisplayService ids = getContext().getService(ImageDisplayService.class);
// final DisplayService ds = getContext().getService(DisplayService.class);
// new Thread(new Runnable() {
// 
// @Override
// public void run() {
// // TODO Auto-generated method stub
// uiService.show(displayName,thingToDisplay);
// //Find display and set zoom, resize window
// List<ImageDisplay> knownImageDisplays = ids.getImageDisplays();
// boolean bvisible = false;
// while (!bvisible) {
// for (ImageDisplay imageDisplay : knownImageDisplays) {
// if (imageDisplay.getName().equals(displayName)) {
// if (imageDisplay.isVisible(imageDisplay.getActiveView())) {
// bvisible = true;
// break;
// }
// }
// }
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// //		    	int vw = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportWidth();
// //		    	int vh = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportHeight();
// //		    	System.out.println(" -----byname="+ij.display().getDisplay(displayName));
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// try {
// ids.getActiveImageDisplay().getCanvas().setZoom(zoomFactor);
// if(ds.getDisplay(displayName) != null && uiService.getDisplayViewer(ds.getDisplay(displayName)) instanceof JFrame) {
// double vw = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.X))*zoomFactor;
// double vh = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.Y))*zoomFactor;
// ((JFrame)uiService.getDisplayViewer(ds.getDisplay(displayName)).getWindow()).setSize(new Dimension((int)vw+50, (int)vh+150));
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// 
// //		    	ij.ui().getDisplayViewer(ij.display().getDisplay(displayName)).getPanel().redoLayout();
// //		    	List<Display<?>> displays = ij.display().getDisplays();
// //		    	for (Display<?> display : displays) {
// //					System.out.println(display+" -----byname="+ij.display().getDisplay(displayName));
// //				}
// 
// }
// }).start();
// 
// }
@Override
public void run() {
    try {
        if (vcellSelection != null && vcellSelection.exception != null) {
            if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
                uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
            }
            return;
        }
        if (vcellSelection == null || vcellSelection.theCacheKey == null) {
            return;
        }
        // Create ImageJ datasets and display separate hyperstack for each variable
        for (int varIndex = 0; varIndex < vcellSelection.varName.length; varIndex++) {
            int[] time = vcellSelection.timePointIndexes;
            displayProgressBar(true, "loading Image...", "VCell Model Loader", (varIndex + 1) * 100 / vcellSelection.varName.length, uiService);
            final IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, vcellSelection.varName[varIndex], VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
            BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
            double[] data = new double[bsd.getTotalSize() * tpd.ijData.length];
            double min = Double.MAX_VALUE;
            double max = Double.MIN_VALUE;
            ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize, tpd.ijData.length);
            for (int i = 0; i < tpd.ijData.length; i++) {
                System.arraycopy(tpd.ijData[i].getDoubleData(), 0, data, i * bsd.getTotalSize(), bsd.getTotalSize());
                // calc minmax only for pixel values that are in domain of this variable
                for (int j = 0; j < tpd.ijData[i].getDoubleData().length; j++) {
                    if (tpd.ijData[i].getDoubleData()[j] != tpd.ijData[i].notInDomainValue) {
                        min = Math.min(min, tpd.ijData[i].getDoubleData()[j]);
                        max = Math.max(max, tpd.ijData[i].getDoubleData()[j]);
                    }
                }
            }
            ImgPlus<DoubleType> imgPlus = new ImgPlus<DoubleType>(testimg);
            imgPlus.setChannelMinimum(0, min);
            imgPlus.setChannelMaximum(0, max);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.Z), 2);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.TIME), 3);
            uiService.show(vcellSelection.varName[varIndex], imgPlus);
            DefaultImageDisplay createDisplayQuietly = (DefaultImageDisplay) displayService.getDisplay(vcellSelection.varName[varIndex]);
            while (displayService.getActiveDisplay() == null) {
                Thread.sleep(100);
            }
            WindowManager.getActiveWindow().setSize(400, 400);
            IJ.run("Scale to Fit", "");
            // refresh the sliders
            WindowManager.getActiveWindow().setSize(400, 400);
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // eventService.publish(new PanZoomEvent(createDisplayQuietly.getCanvas()));
            // IJ.run("Set... ", "zoom=300 x="+(bsd.xsize/2)+" y="+(bsd.ysize/2));
            // IJ.run("Set... ", "zoom=300");
            // IJ.run("In");
            // IJ.run("In");
            // IJ.run("In");
            // RunService runService = getContext().getService(RunService.class);
            // runService.run("In", (Map)null);
            // final Iterator<PluginInfo<Op>> iterator = opService.getPlugins().iterator();
            // while(iterator.hasNext()) {
            // System.out.println(iterator.next());
            // }
            // opService.run("In", "");
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // createDisplayQuietly.update();
            // final Display<?> createDisplayQuietly = getContext().getService(DisplayService.class).createDisplayQuietly(testimg);
            final DefaultDatasetView defaultDatasetView = (DefaultDatasetView) ((DefaultImageDisplay) createDisplayQuietly).getActiveView();
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(2), 2);
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(3), 3);
            // defaultDatasetView.update();
            System.out.println(min + " " + max);
        // displayService.setActiveDisplay(createDisplayQuietly);
        // IJ.setMinAndMax(min, max);
        // defaultDatasetView.getData().setChannelMinimum(0, min);
        // defaultDatasetView.getData().setChannelMaximum(0, max);
        // defaultDatasetView.setChannelRanges(min,max);
        // IJ.getImage().updateAndDraw();
        // while(displayService.getActiveDisplay() == null) {
        // Thread.sleep(100);
        // }
        // IJ.setMinAndMax(min, max);
        // WindowManager.getCurrentImage().setDisplayRange(min, max)
        // WindowManager.getCurrentImage().setDisplayRange(min,max);
        // ImageStack.create(varIndex, varIndex, varIndex, varIndex)
        // ImagePlus ip = new ImagePlus();
        // uiService.showUI();
        // EventService es = null;
        // getContext().getService(EventService.class).publish(new DisplayUpdatedEvent(createDisplayQuietly,DisplayUpdatedEvent.DisplayUpdateLevel.UPDATE));
        // uiService.get
        // uiService.show(createDisplayQuietly);
        // getContext().getService(DisplayService.class).
        // showAndZoom(vcellSelection.varName[varIndex],createDisplayQuietly, 3);
        }
    } catch (Exception e) {
        displayProgressBar(false, "Error", "VCell Model Loader", 100, uiService);
        uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
    } finally {
        displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
    }
}
Also used : ImgPlus(net.imagej.ImgPlus) DefaultLinearAxis(net.imagej.axis.DefaultLinearAxis) DoubleType(net.imglib2.type.numeric.real.DoubleType) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DefaultImageDisplay(net.imagej.display.DefaultImageDisplay) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray) DefaultDatasetView(net.imagej.display.DefaultDatasetView)

Example 3 with ImgPlus

use of net.imagej.ImgPlus in project vcell by virtualcell.

the class VCellPlugin method run.

// private Hashtable<String,Thread> threadHash = new Hashtable<String,Thread>();
// private void startJProgressThread0(String lastName,String newName) {
// if(lastName != null && threadHash.get(lastName) != null) {
// threadHash.get(lastName).interrupt();
// while(threadHash.get(lastName) != null) {
// try {
// Thread.sleep(50);
// } catch (InterruptedException e) {
// e.printStackTrace();
// break;
// }
// }
// }
// if(newName == null) {
// return;
// }
// final Thread progressThread = new Thread(new Runnable(){
// @Override
// public void run() {
// final int[] progress = new int[] {1};
// while(progressDialog.isVisible()) {
// if(Thread.currentThread().isInterrupted()) {
// break;
// }
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// jProgressBar.setValue(progress[0]);
// }});
// progress[0]++;
// try {
// Thread.sleep(500);
// } catch (InterruptedException e) {
// break;
// }
// }
// threadHash.remove(Thread.currentThread().getName());
// }});
// threadHash.put(newName, progressThread);
// progressThread.setName(newName);
// progressThread.setDaemon(true);//So not block JVM exit
// progressThread.start();
// }
// public void showAndZoom(String displayName,Object thingToDisplay,double zoomFactor) throws Exception{
// final ImageDisplayService ids = getContext().getService(ImageDisplayService.class);
// final DisplayService ds = getContext().getService(DisplayService.class);
// new Thread(new Runnable() {
// 
// @Override
// public void run() {
// // TODO Auto-generated method stub
// uiService.show(displayName,thingToDisplay);
// //Find display and set zoom, resize window
// List<ImageDisplay> knownImageDisplays = ids.getImageDisplays();
// boolean bvisible = false;
// while (!bvisible) {
// for (ImageDisplay imageDisplay : knownImageDisplays) {
// if (imageDisplay.getName().equals(displayName)) {
// if (imageDisplay.isVisible(imageDisplay.getActiveView())) {
// bvisible = true;
// break;
// }
// }
// }
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
// }
// //		    	int vw = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportWidth();
// //		    	int vh = ij.imageDisplay().getActiveImageDisplay().getCanvas().getViewportHeight();
// //		    	System.out.println(" -----byname="+ij.display().getDisplay(displayName));
// SwingUtilities.invokeLater(new Runnable() {
// @Override
// public void run() {
// try {
// ids.getActiveImageDisplay().getCanvas().setZoom(zoomFactor);
// if(ds.getDisplay(displayName) != null && uiService.getDisplayViewer(ds.getDisplay(displayName)) instanceof JFrame) {
// double vw = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.X))*zoomFactor;
// double vh = ids.getActiveImageDisplay().dimension(ids.getActiveImageDisplay().dimensionIndex(Axes.Y))*zoomFactor;
// ((JFrame)uiService.getDisplayViewer(ds.getDisplay(displayName)).getWindow()).setSize(new Dimension((int)vw+50, (int)vh+150));
// }
// } catch (Exception e) {
// e.printStackTrace();
// }
// }
// });
// 
// //		    	ij.ui().getDisplayViewer(ij.display().getDisplay(displayName)).getPanel().redoLayout();
// //		    	List<Display<?>> displays = ij.display().getDisplays();
// //		    	for (Display<?> display : displays) {
// //					System.out.println(display+" -----byname="+ij.display().getDisplay(displayName));
// //				}
// 
// }
// }).start();
// 
// }
@Override
public void run() {
    try {
        if (vcellSelection != null && vcellSelection.exception != null) {
            if (!vcellSelection.exception.getMessage().equals(MyPreProcessor.CANCELLED)) {
                uiService.showDialog("Model search failed\n" + vcellSelection.exception.getClass().getName() + "\n" + vcellSelection.exception.getMessage(), MessageType.ERROR_MESSAGE);
            }
            return;
        }
        if (vcellSelection == null || vcellSelection.theCacheKey == null) {
            return;
        }
        // Create ImageJ datasets and display separate hyperstack for each variable
        for (int varIndex = 0; varIndex < vcellSelection.varName.length; varIndex++) {
            int[] time = vcellSelection.timePointIndexes;
            displayProgressBar(true, "loading Image...", "VCell Model Loader", (varIndex + 1) * 100 / vcellSelection.varName.length, uiService);
            final IJDataList tpd = vcellHelper.getTimePointData(vcellSelection.theCacheKey, vcellSelection.varName[varIndex], VCellHelper.VARTYPE_POSTPROC.NotPostProcess, time, 0);
            BasicStackDimensions bsd = tpd.ijData[0].stackInfo;
            double[] data = new double[bsd.getTotalSize() * tpd.ijData.length];
            double min = Double.MAX_VALUE;
            double max = Double.MIN_VALUE;
            ArrayImg<DoubleType, DoubleArray> testimg = ArrayImgs.doubles(data, bsd.xsize, bsd.ysize, bsd.zsize, tpd.ijData.length);
            for (int i = 0; i < tpd.ijData.length; i++) {
                System.arraycopy(tpd.ijData[i].getDoubleData(), 0, data, i * bsd.getTotalSize(), bsd.getTotalSize());
                // calc minmax only for pixel values that are in domain of this variable
                for (int j = 0; j < tpd.ijData[i].getDoubleData().length; j++) {
                    if (tpd.ijData[i].getDoubleData()[j] != tpd.ijData[i].notInDomainValue) {
                        min = Math.min(min, tpd.ijData[i].getDoubleData()[j]);
                        max = Math.max(max, tpd.ijData[i].getDoubleData()[j]);
                    }
                }
            }
            ImgPlus<DoubleType> imgPlus = new ImgPlus<DoubleType>(testimg);
            imgPlus.setChannelMinimum(0, min);
            imgPlus.setChannelMaximum(0, max);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.Z), 2);
            imgPlus.setAxis(new DefaultLinearAxis(Axes.TIME), 3);
            uiService.show(vcellSelection.varName[varIndex], imgPlus);
            DefaultImageDisplay createDisplayQuietly = (DefaultImageDisplay) displayService.getDisplay(vcellSelection.varName[varIndex]);
            while (displayService.getActiveDisplay() == null) {
                Thread.sleep(100);
            }
            WindowManager.getActiveWindow().setSize(400, 400);
            IJ.run("Scale to Fit", "");
            // refresh the sliders
            WindowManager.getActiveWindow().setSize(400, 400);
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // eventService.publish(new PanZoomEvent(createDisplayQuietly.getCanvas()));
            // IJ.run("Set... ", "zoom=300 x="+(bsd.xsize/2)+" y="+(bsd.ysize/2));
            // IJ.run("Set... ", "zoom=300");
            // IJ.run("In");
            // IJ.run("In");
            // IJ.run("In");
            // RunService runService = getContext().getService(RunService.class);
            // runService.run("In", (Map)null);
            // final Iterator<PluginInfo<Op>> iterator = opService.getPlugins().iterator();
            // while(iterator.hasNext()) {
            // System.out.println(iterator.next());
            // }
            // opService.run("In", "");
            // final ZoomService zoomService = getContext().getService(ZoomService.class);
            // zoomService.zoomSet(createDisplayQuietly, 300, 0, 0);
            // createDisplayQuietly.update();
            // final Display<?> createDisplayQuietly = getContext().getService(DisplayService.class).createDisplayQuietly(testimg);
            final DefaultDatasetView defaultDatasetView = (DefaultDatasetView) ((DefaultImageDisplay) createDisplayQuietly).getActiveView();
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(2), 2);
            // defaultDatasetView.getData().setAxis(createDisplayQuietly.axis(3), 3);
            // defaultDatasetView.update();
            System.out.println(min + " " + max);
        // displayService.setActiveDisplay(createDisplayQuietly);
        // IJ.setMinAndMax(min, max);
        // defaultDatasetView.getData().setChannelMinimum(0, min);
        // defaultDatasetView.getData().setChannelMaximum(0, max);
        // defaultDatasetView.setChannelRanges(min,max);
        // IJ.getImage().updateAndDraw();
        // while(displayService.getActiveDisplay() == null) {
        // Thread.sleep(100);
        // }
        // IJ.setMinAndMax(min, max);
        // WindowManager.getCurrentImage().setDisplayRange(min, max)
        // WindowManager.getCurrentImage().setDisplayRange(min,max);
        // ImageStack.create(varIndex, varIndex, varIndex, varIndex)
        // ImagePlus ip = new ImagePlus();
        // uiService.showUI();
        // EventService es = null;
        // getContext().getService(EventService.class).publish(new DisplayUpdatedEvent(createDisplayQuietly,DisplayUpdatedEvent.DisplayUpdateLevel.UPDATE));
        // uiService.get
        // uiService.show(createDisplayQuietly);
        // getContext().getService(DisplayService.class).
        // showAndZoom(vcellSelection.varName[varIndex],createDisplayQuietly, 3);
        }
    } catch (Exception e) {
        displayProgressBar(false, "Error", "VCell Model Loader", 100, uiService);
        uiService.showDialog("theCacheKey,var,VCellHelper.VARTYPE_POSTPROC.NotPostProcess,time,0\n" + e.getMessage(), "getTimePoint(...) failed", MessageType.ERROR_MESSAGE);
    } finally {
        displayProgressBar(false, "displaying Image...", "VCell Model Loader", 100, uiService);
    }
}
Also used : ImgPlus(net.imagej.ImgPlus) DefaultLinearAxis(net.imagej.axis.DefaultLinearAxis) DoubleType(net.imglib2.type.numeric.real.DoubleType) IJDataList(org.vcell.imagej.helper.VCellHelper.IJDataList) BasicStackDimensions(org.vcell.imagej.helper.VCellHelper.BasicStackDimensions) DefaultImageDisplay(net.imagej.display.DefaultImageDisplay) DoubleArray(net.imglib2.img.basictypeaccess.array.DoubleArray) DefaultDatasetView(net.imagej.display.DefaultDatasetView)

Example 4 with ImgPlus

use of net.imagej.ImgPlus 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;
}
Also used : Scanner(java.util.Scanner) ImgPlus(net.imagej.ImgPlus) Dataset(net.imagej.Dataset) ArrayList(java.util.ArrayList) FloatType(net.imglib2.type.numeric.real.FloatType) FinalInterval(net.imglib2.FinalInterval) File(java.io.File)

Example 5 with ImgPlus

use of net.imagej.ImgPlus in project vcell by virtualcell.

the class ProjectService method saveDataset.

private void saveDataset(Dataset dataset, Path path) throws IOException {
    Dataset datasetToSave = dataset.duplicate();
    // SCIFIO cannot save 1-bit images so we must convert to 8-bit
    if (datasetToSave.firstElement() instanceof BitType) {
        @SuppressWarnings("unchecked") Img<BitType> img = (Img<BitType>) dataset.getImgPlus().getImg();
        Img<UnsignedByteType> converted = opService.convert().uint8(img);
        ImgPlus<UnsignedByteType> convertedImgPlus = new ImgPlus<>(converted, dataset.getName());
        datasetToSave.setImgPlus(convertedImgPlus);
    }
    String name = dataset.getName();
    if (FilenameUtils.getExtension(name).isEmpty()) {
        // Default save extension
        name += ".tif";
    }
    Path filePath = Paths.get(path.toString(), name);
    datasetIOService.save(datasetToSave, filePath.toString());
}
Also used : Path(java.nio.file.Path) Img(net.imglib2.img.Img) BitType(net.imglib2.type.logic.BitType) ImgPlus(net.imagej.ImgPlus) Dataset(net.imagej.Dataset) UnsignedByteType(net.imglib2.type.numeric.integer.UnsignedByteType)

Aggregations

ImgPlus (net.imagej.ImgPlus)6 Dataset (net.imagej.Dataset)3 FinalInterval (net.imglib2.FinalInterval)3 Img (net.imglib2.img.Img)3 File (java.io.File)2 DefaultLinearAxis (net.imagej.axis.DefaultLinearAxis)2 DefaultDatasetView (net.imagej.display.DefaultDatasetView)2 DefaultImageDisplay (net.imagej.display.DefaultImageDisplay)2 DoubleArray (net.imglib2.img.basictypeaccess.array.DoubleArray)2 BitType (net.imglib2.type.logic.BitType)2 UnsignedByteType (net.imglib2.type.numeric.integer.UnsignedByteType)2 DoubleType (net.imglib2.type.numeric.real.DoubleType)2 BasicStackDimensions (org.vcell.imagej.helper.VCellHelper.BasicStackDimensions)2 IJDataList (org.vcell.imagej.helper.VCellHelper.IJDataList)2 BufferedImage (java.awt.image.BufferedImage)1 IOException (java.io.IOException)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Scanner (java.util.Scanner)1 AbstractOpTest (net.imagej.ops.AbstractOpTest)1