[301] | 1 | // ----------------------------------------------------------------------- |
---|
| 2 | // spectrumDetect.cc: Search a 1D Image for objects. |
---|
| 3 | // ----------------------------------------------------------------------- |
---|
| 4 | // Copyright (C) 2006, Matthew Whiting, ATNF |
---|
| 5 | // |
---|
| 6 | // This program is free software; you can redistribute it and/or modify it |
---|
| 7 | // under the terms of the GNU General Public License as published by the |
---|
| 8 | // Free Software Foundation; either version 2 of the License, or (at your |
---|
| 9 | // option) any later version. |
---|
| 10 | // |
---|
| 11 | // Duchamp is distributed in the hope that it will be useful, but WITHOUT |
---|
| 12 | // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
---|
| 13 | // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
---|
| 14 | // for more details. |
---|
| 15 | // |
---|
| 16 | // You should have received a copy of the GNU General Public License |
---|
| 17 | // along with Duchamp; if not, write to the Free Software Foundation, |
---|
| 18 | // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA |
---|
| 19 | // |
---|
| 20 | // Correspondence concerning Duchamp may be directed to: |
---|
| 21 | // Internet email: Matthew.Whiting [at] atnf.csiro.au |
---|
| 22 | // Postal address: Dr. Matthew Whiting |
---|
| 23 | // Australia Telescope National Facility, CSIRO |
---|
| 24 | // PO Box 76 |
---|
| 25 | // Epping NSW 1710 |
---|
| 26 | // AUSTRALIA |
---|
| 27 | // ----------------------------------------------------------------------- |
---|
[582] | 28 | #include <duchamp/Detection/finders.hh> |
---|
[393] | 29 | #include <duchamp/PixelMap/Scan.hh> |
---|
[50] | 30 | |
---|
[258] | 31 | using namespace PixelInfo; |
---|
| 32 | |
---|
[50] | 33 | enum STATUS { NONOBJECT, OBJECT }; |
---|
| 34 | |
---|
[378] | 35 | namespace duchamp |
---|
[50] | 36 | { |
---|
[222] | 37 | |
---|
[1008] | 38 | std::vector<Scan> spectrumDetect(std::vector<bool> &array, size_t dim, unsigned int minSize) |
---|
[378] | 39 | { |
---|
[528] | 40 | /// @details |
---|
| 41 | /// A detection algorithm that searches in a single 1-D spectrum. It |
---|
| 42 | /// simply scans along the spectrum, storing connected sets of |
---|
| 43 | /// detected pixels as Scans, where "detected" means according to the |
---|
| 44 | /// Image::isDetection(long,long) function. |
---|
| 45 | /// |
---|
| 46 | /// When finished a vector of the detected scans is returned. |
---|
[50] | 47 | |
---|
[378] | 48 | STATUS status; |
---|
| 49 | Scan obj; |
---|
| 50 | std::vector<Scan> outputlist; |
---|
| 51 | bool isObject; |
---|
[50] | 52 | |
---|
[378] | 53 | status = NONOBJECT; |
---|
[1008] | 54 | for(size_t pos=0;pos<(dim+1);pos++){ |
---|
[50] | 55 | |
---|
[582] | 56 | if(pos<dim){ |
---|
| 57 | isObject = array[pos]; |
---|
[258] | 58 | } |
---|
[378] | 59 | else isObject=false; |
---|
| 60 | |
---|
| 61 | if(isObject){ |
---|
| 62 | if(status != OBJECT){ |
---|
| 63 | status = OBJECT; |
---|
| 64 | obj.define(0, pos, 1); |
---|
[136] | 65 | } |
---|
[378] | 66 | else obj.growRight(); |
---|
[50] | 67 | } |
---|
[378] | 68 | else{ |
---|
| 69 | if(status == OBJECT){ // if we were on an object and have left |
---|
[582] | 70 | if(obj.getXlen() >= int(minSize)){ // if it's big enough |
---|
[378] | 71 | outputlist.push_back(obj); // add to list. |
---|
| 72 | } |
---|
| 73 | obj.clear(); |
---|
| 74 | } |
---|
| 75 | status = NONOBJECT; |
---|
| 76 | } |
---|
| 77 | |
---|
[50] | 78 | } |
---|
| 79 | |
---|
[378] | 80 | return outputlist; |
---|
| 81 | |
---|
[50] | 82 | } |
---|
| 83 | |
---|
| 84 | } |
---|