[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 | // ----------------------------------------------------------------------- |
---|
[393] | 28 | #include <duchamp/Cubes/cubes.hh> |
---|
| 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 | |
---|
[378] | 38 | std::vector<Scan> Image::spectrumDetect() |
---|
| 39 | { |
---|
| 40 | /** |
---|
| 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. |
---|
| 47 | * |
---|
| 48 | */ |
---|
[50] | 49 | |
---|
[378] | 50 | STATUS status; |
---|
| 51 | Scan obj; |
---|
| 52 | std::vector<Scan> outputlist; |
---|
| 53 | bool isObject; |
---|
[50] | 54 | |
---|
[378] | 55 | status = NONOBJECT; |
---|
| 56 | for(int pos=0;pos<(this->axisDim[0]+1);pos++){ |
---|
[50] | 57 | |
---|
[378] | 58 | if(pos<this->axisDim[0]){ |
---|
| 59 | isObject = this->isDetection(pos,0); |
---|
[258] | 60 | } |
---|
[378] | 61 | else isObject=false; |
---|
| 62 | |
---|
| 63 | if(isObject){ |
---|
| 64 | if(status != OBJECT){ |
---|
| 65 | status = OBJECT; |
---|
| 66 | obj.define(0, pos, 1); |
---|
[136] | 67 | } |
---|
[378] | 68 | else obj.growRight(); |
---|
[50] | 69 | } |
---|
[378] | 70 | else{ |
---|
| 71 | if(status == OBJECT){ // if we were on an object and have left |
---|
| 72 | if(obj.getXlen() >= this->minSize){ // if it's big enough |
---|
| 73 | outputlist.push_back(obj); // add to list. |
---|
| 74 | } |
---|
| 75 | obj.clear(); |
---|
| 76 | } |
---|
| 77 | status = NONOBJECT; |
---|
| 78 | } |
---|
| 79 | |
---|
[50] | 80 | } |
---|
| 81 | |
---|
[378] | 82 | return outputlist; |
---|
| 83 | |
---|
[50] | 84 | } |
---|
| 85 | |
---|
| 86 | } |
---|