forked from JzHuai0108/ImageSegmentor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathChangeDetector.h
93 lines (88 loc) · 3.53 KB
/
ChangeDetector.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* This file is part of ImageSegmentor.
*
* Copyright (C) 2012 Jianzhu Huai <huai dot 3 at osu dot edu> (The Ohio State University)
*
* ImageSegmentor is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ImageSegmentor is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with ImageSegmentor. If not, see <http://www.gnu.org/licenses/>.
*/
#include<vector>
//when using the bestp, the coverage limit becomes of not much use.
//the parameter gap and gThresh has some effect on outcome, the parameters for segmentation
//have not yet been studied.
typedef struct Parcel{
static int dim;
int pIndex;//the index of the first pixel belong to this parcel in tagarray,
int size;//area
CRect boundBox;
float *sum1;//sum of spectral intensity
float *sum2;//sum of squares of spectral intensity
Parcel():pIndex(-1),size(0),sum1(0),sum2(0){}
Parcel(const Parcel&pass):pIndex(pass.pIndex),size(pass.size),sum1(pass.sum1),sum2(pass.sum2){}
Parcel&operator=(const Parcel&pass){
if(this==&pass)
return*this;
pIndex=pass.pIndex;
size=pass.size;
sum1=pass.sum1;
sum2=pass.sum2;
return*this;
}
}Parcel;
typedef struct RefPair{
int bestp;//parcel label of the biggest intersection parcel in the other segmentation
//if bestp==-1, it means the parcel cannot be used, especially to avoid duplicated checking of region pairs
int section;//parcel intersection area
float sDist;//spectral difference
float gDist;//geometric difference
RefPair():bestp(-1),section(0),sDist(-0.f),gDist(-0.f) {}
RefPair(const RefPair&pass):bestp(pass.bestp),section(pass.section),
sDist(pass.sDist),gDist(pass.gDist) {}
RefPair& operator=(const RefPair&right){
if(this==&right)
return *this;
bestp=right.bestp;
section=right.section;
sDist=right.sDist;
gDist=right.gDist;
return *this;
}
}RefPair;//each refence pair corresponds to one parcel
class ChangeDetector{
std::vector<RefPair> refList1;//each refpair is associated with the parcel in segmentation 1 of the same index in vector
std::vector<RefPair> refList2;
ChangeDetector(const ChangeDetector&);
ChangeDetector& operator=(const ChangeDetector&);
public:
void PrepLabel(const CString&tagf1,const CString &tagf2);
void PrepRegList(const CString&seg1,const CString&seg2);
int *tag1;//label matrix for segmentation 1
int *tag2;
BYTE *buf;//result with 0 indicating unchanged area
float *sMean1;//spectral mean,
float *sMean2;//spectral mean
float *sVar1;//spectral variance,
float *sVar2;
int dim;//dimension of mean and variance, i.e., band number
int width;
int height;
std::vector<Parcel> regList1;//segmentation 1, tag[regList1[i].pIndex]==i holds
std::vector<Parcel> regList2;
ChangeDetector();
~ChangeDetector();
void InitPairs();//for each pixel in segmentation 1, floodfill with matching pixel in segmentation 2
void RadioDiff();//spectral difference
void MorphDiff(float,float);//geometric difference
void Detect(float,float);//for each region pair in pairList, decide the no changed one
void SaveChange(const CString&,const CString&)const;//save the change detection array
};