Package net.sourceforge.theba.core

Examples of net.sourceforge.theba.core.Stack


    /**
     * This is the code executed to track all currently selected seeds
     */
    @Override
    public void track() {
        Stack input = control.getStack();
        String min = JOptionPane.showInputDialog("Set minimum region size in voxels", "100");
        if (min == null) {
            return;
        }
        long totalSize = 0;
        int removeCount = 0;
        int count = 0;
        short id = 255;
        for (int z = 0; z < input.getDepth(); z++) {
            for (int y = 0; y < input.getHeight(); y++) {
                for (int x = 0; x < input.getWidth(); x++) {
                    short val = input.getVoxelUnchecked(x, y, z);
                    if (val == 0xff) {
                        id++;
                        long size = ImageFunctions.floodFill3D(input, x, y, z, id);
                        totalSize += size;
                        if (size < 100) {
View Full Code Here


     * This method generates fiber-chord measurements for the given volume. This
     * involves calculation of the mean distance between porous regions in x,y
     * and z-directions
     */
    public void fiberChordMeasurements() {
        final Stack stack = getStack();
        double length = 0;
        double count = 0;
        double total = 0;
        double nlength = 0;
        double ncount = 0;
        double ntotal = 0;

        for (int x = 0; x < stack.getWidth(); x++) {
            setProgressbar(x, stack.getWidth());

            if (isStopped())
                return;

            for (int y = 0; y < stack.getHeight(); y++) {
                for (int z = 0; z < stack.getDepth(); z++) {
                    short voxel = stack.getVoxel(x, y, z);
                    if (voxel == 0 && z < stack.getDepth())
                        length++;
                    else if (length > 0) {
                        count++;
                        total += length;
                        length = 0;
                    }
                    if (voxel != 0 && z < stack.getDepth())
                        nlength++;
                    else if (nlength > 0) {
                        ncount++;
                        ntotal += nlength;
                        nlength = 0;
                    }
                }
            }
        }

        double zaverageLength = total / count;
        double zaverageLength_inverse = ntotal / ncount;

        length = 0;
        total = 0;
        count = 0;
        nlength = 0;
        ntotal = 0;
        ncount = 0;

        for (int x = 0; x < stack.getWidth(); x++) {
            setProgressbar(x, stack.getWidth());
            if (isStopped())
                return;
            for (int z = 0; z < stack.getDepth(); z++) {
                for (int y = 0; y < stack.getHeight(); y++) {
                    short voxel = stack.getVoxel(x, y, z);

                    if (voxel == 0 && y < stack.getHeight())
                        length++;
                    else if (length > 0) {
                        count++;
                        total += length;
                        length = 0;
                    }
                    if (voxel != 0 && y < stack.getHeight())
                        nlength++;
                    else if (nlength > 0) {
                        ncount++;
                        ntotal += nlength;
                        nlength = 0;
                    }
                }
            }
        }

        double yaverage = total / count;
        double yaverage_inverse = ntotal / ncount;

        length = 0;
        total = 0;
        count = 0;
        nlength = 0;
        ntotal = 0;
        ncount = 0;

        for (int y = 0; y < stack.getHeight(); y++) {
            setProgressbar(y, stack.getHeight());
            if (isStopped())
                return;
            for (int z = 0; z < stack.getDepth(); z++) {
                for (int x = 0; x < stack.getWidth(); x++) {
                    short voxel = stack.getVoxel(x, y, z);
                    if (voxel == 0 && x < stack.getWidth())
                        length++;
                    else if (length > 0) {
                        count++;
                        total += length;
                        length = 0;
                    }
                    if (voxel != 0 && x < stack.getWidth()) {
                        nlength++;
                    } else if (nlength > 0) {
                        ncount++;
                        ntotal += nlength;
                        nlength = 0;
View Full Code Here

        filterMenu.addSeparator();
        JMenuItem removeMarkedVoxels = new JMenuItem("Remove marked");
        removeMarkedVoxels.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                final Stack activeVolume = getCurrentView().getVolume();
                disableMenus();
                Thread r = new Thread() {
                    public void run() {
                        byte ff = (byte) 0xff;
                        int count = 0;
                        for (int z = 0; z < activeVolume.getDepth(); z++) {
                            if (isStopped)
                                return;
                            setProgress(z);
                            short[] slice = activeVolume.getSlice(z);
                            for (int i = 0; i < slice.length; i++) {
                                if (slice[i] != 0 && slice[i] != ff) {
                                    count++;
                                    slice[i] = 0;
                                }
                            }
                        }
                        activeVolume.flush();
                        StringBuffer output = new StringBuffer();
                        output.append("Removed " + count + " voxels \n");
                        showResults(output, "Voxelcount");
                        enableMenus();
                        updateImage();
                    }
                };
                r.start();
            }
        });

        JMenuItem removeSmallRegions = new JMenuItem("Remove small labeled regions");
        removeSmallRegions.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Thread r = new Thread() {
                    public void run() {

                        String input = JOptionPane.showInputDialog(null, "Enter minmum regsize.", 100);
                        if (input == null) return;

                        int tval = Integer.parseInt(input);

                        setLabel("Creating histogram...");
                        long[] histo = new long[MAX_FIBERS + 256];
                        for (int z = 0; z < volume.getDepth(); z++) {
                            setProgress(z);
                            short[] slice = volume.getSlice(z);
                            for (short aSlice : slice) {
                                histo[aSlice]++;
                            }
                        }
                        setLabel("Removing regions");

                        for (int z = 0; z < volume.getDepth(); z++) {
                            setProgress(z);
                            short[] slice = volume.getSlice(z);
                            for (int i = 0; i < slice.length; i++) {
                                if (histo[slice[i]] < tval) slice[i] = 0;
                            }
                        }
                        enableMenus();
                        updateImage();
                    }

                };
                disableMenus();
                r.start();
            }
        });

        JMenuItem removeUnmarkedVoxels = new JMenuItem("Remove unlabeled");
        removeUnmarkedVoxels.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                final Stack activeVolume = getCurrentView().getVolume();
                disableMenus();
                Thread r = new Thread() {
                    public void run() {
                        int count = 0;
                        for (int z = 0; z < activeVolume.getDepth(); z++) {
                            if (isStopped)
                                return;
                            setProgress(z);
                            short[] slice = activeVolume.getSlice(z);
                            for (int i = 0; i < slice.length; i++) {
                                if (slice[i] == 255) {
                                    count++;
                                    slice[i] = 0;
                                }
                            }
                        }
                        activeVolume.flush();
                        StringBuffer output = new StringBuffer();
                        output.append("Removed " + count + " voxels \n");
                        showResults(output, "Voxelcount");
                        enableMenus();
                        updateImage();
                    }
                };
                r.start();
            }
        });

        JMenuItem resetMarkedVoxels = new JMenuItem("Remove colors");
        resetMarkedVoxels.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                final Stack activeVolume = getCurrentView().getVolume();
                disableMenus();
                Thread r = new Thread() {
                    public void run() {
                        byte ff = (byte) 0xff;
                        int count = 0;
                        for (int z = 0; z < activeVolume.getDepth(); z++) {
                            setProgress(z);
                            short[] slice = activeVolume.getSlice(z);
                            for (int i = 0; i < slice.length; i++) {
                                if (slice[i] != 0 && slice[i] != ff) {
                                    count++;
                                    slice[i] = 0;
                                }
                            }
                        }
                        activeVolume.flush();
                        StringBuffer output = new StringBuffer();
                        output.append("Reset " + count + " voxels \n");
                        showResults(output, "Voxelcount");
                        enableMenus();
                        updateImage();
                    }
                };
                r.start();
            }
        });

        JMenuItem resetLabels = new JMenuItem("Reset labels");
        resetMarkedVoxels.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                final Stack activeVolume = getCurrentView().getVolume();
                disableMenus();
                Thread r = new Thread() {
                    public void run() {
                        int count = 0;
                        for (int z = 0; z < activeVolume.getDepth(); z++) {
                            setProgress(z);
                            short[] slice = activeVolume.getSlice(z);
                            for (int i = 0; i < slice.length; i++) {
                                if (slice[i] != 0) {
                                    count++;
                                    slice[i] = 255;
                                }
                            }
                        }
                        activeVolume.flush();
                        StringBuffer output = new StringBuffer();
                        output.append("Reset " + count + " voxels \n");
                        showResults(output, "Voxelcount");
                        enableMenus();
                        updateImage();
                    }
                };
                r.start();
            }
        });

        filterMenu.add(removeMarkedVoxels);
        filterMenu.add(removeUnmarkedVoxels);
        filterMenu.add(resetMarkedVoxels);
        filterMenu.add(resetLabels);
        filterMenu.addSeparator();
        filterMenu.add(removeSmallRegions);

        filterMenu.addSeparator();

        flipItem.addActionListener(this);
        filterMenu.add(flipItem);
        helpMenu.setMnemonic('h');
        JMenuItem pluginItem = new JMenuItem("Installed Plugins");
        pluginItem.addActionListener(this);
        helpMenu.add(pluginItem);
        JMenuItem aboutItem = new JMenuItem("About");
        aboutItem.addActionListener(this);
        helpMenu.add(aboutItem);

        JMenu editMenu = new JMenu("Edit");
        editMenu.setMnemonic('e');
        JMenuItem undoItem = new JMenuItem("Undo");
        JMenuItem preferencesItem = new JMenuItem("Preferences...");
        preferencesItem.setMnemonic('p');
        undoItem.setEnabled(false);
        editMenu.add(undoItem);
        editMenu.add(preferencesItem);
        JMenuItem reloadItem = new JMenuItem("Reload stack");
        reloadItem.setMnemonic('r');
        reloadItem.setAccelerator(KeyStroke.getKeyStroke('r'));
        reloadItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Thread r = new Thread() {
                    public void run() {
                        loadStack();
                    }
                };
                r.start();
            }
        });
        editMenu.add(reloadItem);
        preferencesItem.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                preferences = new ThebaPrefs(mainWindow);
                preferences.setVisible(true);
            }
        });
        analyzeMenu = new JMenu("Analyze");
        analyzeMenu.setMnemonic('a');

        JMenuItem fiberMenu = new JMenu("Region measurements");

        JMenuItem measureAllItem = new JMenuItem("Perform all");

        if (descriptors != null) {
            for (final RegionDescriptor d : descriptors) {
                if (d.does3D()) {
                    JMenuItem item = new JMenuItem("Measure :" + d.getName());
                    ActionListener listener = new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                            final Stack volume = getCurrentView().getVolume();
                            disableMenus();
                            Thread r = new Thread() {
                                public void run() {
                                    setLabel("Counting regions...");
                                    StringBuffer buf = new StringBuffer("Bounding regions...");
View Full Code Here

        initIdList();
        disableMenus();
        SliceReader sr = new SliceReader(fileName, width, height, depth, 0);
        if (getPreferences().getInt("use_cached_access", 0) == 0) {
            datawriter = new HeapReader(width, height, depth);
            volume = new Stack(datawriter);
        } else {
            volume = new Stack(width, height, depth, getPreferences().getString("tempFileName", "temp.raw"));
            datawriter = volume.getWriter();
        }
        iw.setReader(datawriter);
        depthSlider.setMaximum(depth - 1);
        progressbar.setMaximum(depth - 1);
View Full Code Here

     *
     * @author jensbw
     */
    private final class HistogramAction implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            final Stack volume = getCurrentView().getVolume();
            disableMenus();
            Thread r = new Thread() {
                public void run() {
                    long total = 0;
                    long[] histo = new long[MAX_FIBERS + 256];

                    for (int z = 0; z < volume.getDepth(); z++) {
                        setProgress(z);
                        short[] slice = volume.getSlice(z);
                        int i = 0;
                        while (i < slice.length) {
                            histo[slice[i]]++;
                            total++;
                            i++;
View Full Code Here

     *
     * @author jensbw
     */
    private final class RegCountAction implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            final Stack volume = getCurrentView().getVolume();
            disableMenus();
            Thread r = new Thread() {
                public void run() {
                    long nonblackCount = 0;
                    long whiteCount = 0;

                    long total = 0;

                    for (int z = 0; z < volume.getDepth(); z++) {
                        setProgress(z);

                        short[] slice = volume.getSlice(z);
                        for (int i = 0; i < slice.length; i++) {

                            if (slice[i] == 255)
                                whiteCount++;

View Full Code Here

     * @author jensbw
     * @author perchrh
     */
    private final class RegionAnalysisAction implements ActionListener {
        public void actionPerformed(ActionEvent e) {
            final Stack volume = getCurrentView().getVolume();
            disableMenus();
            Thread r = new Thread() {
                public void run() {
                    StringBuffer buf = new StringBuffer("Counting regions...");
                    showResults(buf, "Region analysis");
                    Region[] regArray = new Region[4096];
                    regList = new LinkedList<Region>();
                    for (int z = 0; z < volume.getDepth(); z++) {
                        setProgress(z);
                        for (int x = 0; x < width; x++) {
                            for (int y = 0; y < height; y++) {
                                short val = volume.getVoxelUnchecked(x, y, z);
                                if (val != 255 && val != 0 && val != 7) {
                                    Region reg = regArray[val];
                                    if (reg == null) {
                                        BoxBounds bounds = new BoxBounds();
                                        reg = new Region(val, bounds);
View Full Code Here

    public VolumeReader getSliceReader() {
        return reader;
    }

    public Stack getVolume() {
        return new Stack(reader);
    }
View Full Code Here

TOP

Related Classes of net.sourceforge.theba.core.Stack

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.