This repository has been archived by the owner on Jan 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathRegion.h
187 lines (172 loc) · 6.3 KB
/
Region.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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/**
* 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/>.
*/
// Region.h: interface for the Region class.
//
//////////////////////////////////////////////////////////////////////
#if !defined(AFX_REGION_H__5C2B5D5D_02AB_4004_99C1_3F7AE3C28297__INCLUDED_)
#define AFX_REGION_H__5C2B5D5D_02AB_4004_99C1_3F7AE3C28297__INCLUDED_
//#pragma warning (disable:4786)
#include "NP.h"
#include<vector>
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
typedef std::vector<NP> NPL;
typedef struct tPair
{
int r[2];
float t;
unsigned int bl;//boundary length between the pair region
// float es;//edge strength, note that when a pixel belong to P abuts two neighbors which merge to Q later,
//then the edge strength of this pixel is added twice in the edge strength between region P and Q.
//since intuitively, the chance the pixel is an edge point is bigger.
tPair():t(0.f),bl(0){}
tPair(const tPair&pass):t(pass.t),bl(pass.bl){
r[0]=pass.r[0];
r[1]=pass.r[1];
}
tPair& operator=(const tPair&agn){
if(&agn==this)
return*this;
r[0]=agn.r[0];
r[1]=agn.r[1];
t=agn.t;
bl=agn.bl;
return *this;
}
} tPair;
typedef struct exRegion
{
public:
int label;//indicate the father pixel index of this region in tagMatrix
float* attList;//attribute list according to prop
bool isVisited;
exRegion():label(-1),attList(NULL),isVisited(false){}
exRegion(const exRegion&cpy):label(cpy.label),attList(cpy.attList),isVisited(cpy.isVisited){}
exRegion&operator=(const exRegion&agn){
if(&agn==this)
return*this;
label=agn.label;
attList=agn.attList;
isVisited=agn.isVisited;
return *this;
}
bool operator<(const exRegion&b) const
{
return label<b.label;
}
bool operator==(const exRegion&b) const
{
return label==b.label;
}
}exRegion;
enum PROP
{
centerX=0,//x coordinate of bounding box center
centerY,//y coord
minRectWid,//bounding box width
minRectHeg,//bounding box height
boxAngle,//bounding box angle
eigRatio,//the major eigenvalue of the point coordinate covariance matrix to the minor one
meanThick,//the average width of a region computed from erosion
changeRatio,//the rate of changed pixels in one region
shadeRatio,//the ratio of shade pixels in one region
neiShadeRatio,//the maximum ratio of shade pixels in one regions' neighboring regions
};
//texture intensity color
enum TIC//terms as defined in Vincent Tao's integrating intensity texture color
{
PC1=0,//for diff in image 1
PC2,//for diff in image 2
ROUC,//for color hue and saturation
GMEAN1,//MEAN INTENSITY FOR IMAGE 1 IN REGION
GMEAN2,//FOR image 2
ROUI,//for intensity rou
PT1,//for var threshold in image 1
PT2,//in image 2
ROUT//for LBP AND VAR (texture)
};
class Region
{
public:
//void DeleteNeighbor(const int tag);
unsigned int size;
float *addition; // each entry is the sum of intensity values in one
// channel of all pixels in the region normalized by the intensity
// range limit, e.g., 256
float *sSum; // each entry is the sum of squares of intensity values in
// one channel of all pixels in the region normalized by the squared
// intensity range limit, e.g., 256^2
NPL NPList;
int perim;
int bestp;// best merge candidate pair index
int p;//parent region index
/* The heterogeneity of the region defined following equations (2-6) of
Benz, U. C., Hofmann, P., Willhauck, G., Lingenfelder, I., & Heynen, M. (2004).
Multi-resolution, object-oriented fuzzy analysis of remote sensing data for
GIS-ready information. ISPRS Journal of photogrammetry and remote sensing,
58(3-4), 239-258."
For clarity, the exact equation is given below.
$ heterogeneity = w_{color} h_{color} + (1 - w_{color}) h_{shape} \\
h_{color} = \sum_{c=1}^{d} w_c \sqrt{\frac{1}{n-1}\left( \sum^n I_{c,j}^2 -
\frac{(\sum^n I_{c,j})^2}{n} \right )} \\
h_{shape} = w_{compt} h_{compt} + (1 - w_{compt}) h_{smooth} \\
h_{smooth} = n l/b \\
h_{compt} = l\sqrt{n} $
where d is the number of channels of the image,
n the number of pixels in the region, l the perimeter of the region,
b the perimeter of the region's bounding box
*/
float interdif;
bool isChecked;
CRect *norbox;//regular box bounding the region
public:
/** compute the heterogeneity of the region
* param: d number of channels
* param: wcolor weight of color heterogeneity, $w_{color}$ in equation (2)
* of Benz 04, note it is not $w_c$
* param: wp weight of compactness heterogeneity, implying that
* smoothness heterogeneity weight == 1 - wp
* param: range is the right range limit of the intensity values, a power
* of 2. For a intensity range [0, 255], it ought to be 256
* return the computed heterogeneity combining color and shape info
*/
float InterDiff(int d=1,float wcolor=0.9,float wp=0.5,float range=256.f);
Region(unsigned int sz=0):size(sz),addition(NULL),sSum(NULL),perim(0),
bestp(-1),p(-1),interdif(0),isChecked(false),norbox(NULL){}
Region(const Region&cpy):size(cpy.size),addition(cpy.addition),sSum(cpy.sSum),perim(cpy.perim),
bestp(cpy.bestp),p(cpy.p),interdif(cpy.interdif),isChecked(cpy.isChecked),norbox(cpy.norbox){}
Region&operator=(const Region&cpy){
if(&cpy==this)
return *this;
size=cpy.size;
addition=cpy.addition;
sSum=cpy.sSum;
perim=cpy.perim;
bestp=cpy.bestp;
p=cpy.p;
interdif=cpy.interdif;
isChecked=cpy.isChecked;
norbox=cpy.norbox;
return *this;
}
~Region();
};
//Actually,the result of compute dist is the internaldif(a&b)
#endif // !defined(AFX_REGION_H__5C2B5D5D_02AB_4004_99C1_3F7AE3C28297__INCLUDED_)