src/main/java/org/stowers/microscopy/ij1plugins/findpeaks/FindPeaks3D.java
protected List<FindPeaks3DLocalMax> findpeaks() {

        List<FindPeaks3DThread> threadList = Collections.synchronizedList(new ArrayList<>());
        for (int k = 1; k < d -1; k++) {
            for (int j = 1; j < h - 1; j++) {
                FindPeaks3DThread thread = new FindPeaks3DThread(stack, stats, 1, j, k, w - 1, 1, 1,
                        tolerance, threshold, minsep, zscale, maxSize);
                thread.setName(name);
                threadList.add(thread);
            }
        }

        peaksFoundList = threadList.parallelStream()
                .map(e -> e.process())
                .flatMap(List::stream)
                .sorted((e1, e2) -> Long.compare(e1.getVoxelIndex(), //sort on pixel array index
                        e2.getVoxelIndex()))
                .collect(Collectors.toList());
        System.out.println(peaksFoundList.size());

        peaksFoundList = peaksFoundList.stream()
                .filter(e -> e.checkY())
                .sorted(
                        comparing(FindPeaks3DLocalMax::getValue).reversed())  //sort bright to dim
                .collect(Collectors.toList());

        System.out.println(peaksFoundList.size());

        int j = 0;

        removeList = new ArrayList<>();
        peaksKeptList = new ArrayList<>();

        for (FindPeaks3DLocalMax p : peaksFoundList) {
            /*
            keep the peak if it is not on the remove list
            if it is not close to a peek already on the keep list
            if its region is larger than 1 pixel
             */
            if (p.getVoxelIndex() == 359989) {
                int f = 5;
            }

            if (removeList.contains(p.getVoxelIndex())) {
                continue;
            }
            if (isClose(p)) {
                removeList.add(p.getVoxelIndex());
                continue;
            }
            // region is the same list as getNeighborsList
            List<Long> region = p.findRegion(hotVoxels);
            hotVoxels.addAll(region);
            if (p.getNeighborsList().size() >= 1) {
                peaksKeptList.add(p);
                removeClose(region);
            } else {
                removeList.add(p.getVoxelIndex());
            }

            if (peaksKeptList.size() >= npeaks) {
                break;
            }
        }

        peaksKeptList = peaksKeptList.stream()
                .sorted(
                        comparing(FindPeaks3DLocalMax::getSumIntensity).reversed())  //sort bright to dim
//                        comparing(FindPeaks3DLocalMax::getZ)
                .collect(Collectors.toList());
        return peaksKeptList;

    }
/**
     *
     * @return List<FindPeaks3DLocalMax> Returns a List of FindPeaks3DLocalMax objects
     */
@return List Returns a List of FindPeaks3DLocalMax objects
@return List Returns a List of FindPeaks3DLocalMax objects
protected List<FindPeaks3DLocalMax> findpeaks() {
        List<FindPeaks3DThread> threadList = Collections.synchronizedList(new ArrayList<>());
        for (int k = 1; k < d -1; k++) {
            for (int j = 1; j < h - 1; j++) {
                FindPeaks3DThread thread = new FindPeaks3DThread(stack, stats, 1, j, k, w - 1, 1, 1,
                        tolerance, threshold, minsep, zscale, maxSize);
                thread.setName(name);
                threadList.add(thread);
            }
        }
        peaksFoundList = threadList.parallelStream()
                .map(e -> e.process())
                .flatMap(List::stream)
                .sorted((e1, e2) -> Long.compare(e1.getVoxelIndex(), 
                        e2.getVoxelIndex()))
                .collect(Collectors.toList());
        System.out.println(peaksFoundList.size());
        peaksFoundList = peaksFoundList.stream()
                .filter(e -> e.checkY())
                .sorted(
                        comparing(FindPeaks3DLocalMax::getValue).reversed())  
                .collect(Collectors.toList());
        System.out.println(peaksFoundList.size());
        int j = 0;
        removeList = new ArrayList<>();
        peaksKeptList = new ArrayList<>();
        for (FindPeaks3DLocalMax p : peaksFoundList) {
            /*
            keep the peak if it is not on the remove list
            if it is not close to a peek already on the keep list
            if its region is larger than 1 pixel
             */
            if (p.getVoxelIndex() == 359989) {
                int f = 5;
            }
            if (removeList.contains(p.getVoxelIndex())) {
                continue;
            }
            if (isClose(p)) {
                removeList.add(p.getVoxelIndex());
                continue;
            }
            List<Long> region = p.findRegion(hotVoxels);
            hotVoxels.addAll(region);
            if (p.getNeighborsList().size() >= 1) {
                peaksKeptList.add(p);
                removeClose(region);
            } else {
                removeList.add(p.getVoxelIndex());
            }
            if (peaksKeptList.size() >= npeaks) {
                break;
            }
        }
        peaksKeptList = peaksKeptList.stream()
                .sorted(
                        comparing(FindPeaks3DLocalMax::getSumIntensity).reversed())  
                .collect(Collectors.toList());
        return peaksKeptList;
    }
protected List < FindPeaks3DLocalMax > findpeaks ( ) { List < FindPeaks3DThread > threadList = Collections . synchronizedList ( new ArrayList < > ( ) ) ; for ( int k = 1 ; k < d - 1 ; k ++ ) { for ( int j = 1 ; j < h - 1 ; j ++ ) { FindPeaks3DThread thread = new FindPeaks3DThread ( stack , stats , 1 , j , k , w - 1 , 1 , 1 , tolerance , threshold , minsep , zscale , maxSize ) ; thread . setName ( name ) ; threadList . add ( thread ) ; } } peaksFoundList = threadList . parallelStream ( ) . map ( e -> e . process ( ) ) . flatMap ( List :: stream ) . sorted ( ( e1 , e2 ) -> Long . compare ( e1 . getVoxelIndex ( ) , e2 . getVoxelIndex ( ) ) ) . collect ( Collectors . toList ( ) ) ; System . out . println ( peaksFoundList . size ( ) ) ; peaksFoundList = peaksFoundList . stream ( ) . filter ( e -> e . checkY ( ) ) . sorted ( comparing ( FindPeaks3DLocalMax :: getValue ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ; System . out . println ( peaksFoundList . size ( ) ) ; int j = 0 ; removeList = new ArrayList < > ( ) ; peaksKeptList = new ArrayList < > ( ) ; for ( FindPeaks3DLocalMax p : peaksFoundList ) { /*
            keep the peak if it is not on the remove list
            if it is not close to a peek already on the keep list
            if its region is larger than 1 pixel
             */ if ( p . getVoxelIndex ( ) == 359989 ) { int f = 5 ; } if ( removeList . contains ( p . getVoxelIndex ( ) ) ) { continue ; } if ( isClose ( p ) ) { removeList . add ( p . getVoxelIndex ( ) ) ; continue ; } List < Long > region = p . findRegion ( hotVoxels ) ; hotVoxels . addAll ( region ) ; if ( p . getNeighborsList ( ) . size ( ) >= 1 ) { peaksKeptList . add ( p ) ; removeClose ( region ) ; } else { removeList . add ( p . getVoxelIndex ( ) ) ; } if ( peaksKeptList . size ( ) >= npeaks ) { break ; } } peaksKeptList = peaksKeptList . stream ( ) . sorted ( comparing ( FindPeaks3DLocalMax :: getSumIntensity ) . reversed ( ) ) . collect ( Collectors . toList ( ) ) ; return peaksKeptList ; }
@return List<FindPeaks3DLocalMax> Returns a List of FindPeaks3DLocalMax objects
@return List<FindPeaks3DLocalMax > Returns a List of FindPeaks3DLocalMax objects
//sort on pixel array index //sort bright to dim // region is the same list as getNeighborsList //sort bright to dim //                        comparing(FindPeaks3DLocalMax::getZ)