Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv_contrib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv_contrib
Commits
c1bfb00d
Commit
c1bfb00d
authored
Oct 08, 2015
by
Zhou Chao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add parallel processing for some steps of l0 smooth
parent
0c691ff0
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
42 deletions
+99
-42
l0_smooth.cpp
modules/ximgproc/src/l0_smooth.cpp
+99
-42
No files found.
modules/ximgproc/src/l0_smooth.cpp
View file @
c1bfb00d
...
...
@@ -44,6 +44,77 @@ using namespace std;
namespace
{
class
ParallelDft
:
public
ParallelLoopBody
{
private
:
vector
<
Mat
>
src_
;
public
:
ParallelDft
(
vector
<
Mat
>
&
s
)
{
src_
=
s
;
}
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
i
=
range
.
start
;
i
!=
range
.
end
;
i
++
)
{
dft
(
src_
[
i
],
src_
[
i
]);
}
}
};
class
ParallelIdft
:
public
ParallelLoopBody
{
private
:
vector
<
Mat
>
src_
;
public
:
ParallelIdft
(
vector
<
Mat
>
&
s
)
{
src_
=
s
;
}
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
i
=
range
.
start
;
i
!=
range
.
end
;
i
++
){
idft
(
src_
[
i
],
src_
[
i
],
DFT_SCALE
);
}
}
};
class
ParallelDivComplexByReal
:
public
ParallelLoopBody
{
private
:
vector
<
Mat
>
numer_
;
vector
<
Mat
>
denom_
;
vector
<
Mat
>
dst_
;
public
:
ParallelDivComplexByReal
(
vector
<
Mat
>
&
numer
,
vector
<
Mat
>
&
denom
,
vector
<
Mat
>
&
dst
)
{
numer_
=
numer
;
denom_
=
denom
;
dst_
=
dst
;
}
void
operator
()
(
const
Range
&
range
)
const
{
for
(
int
i
=
range
.
start
;
i
!=
range
.
end
;
i
++
)
{
Mat
aPanels
[
2
];
Mat
bPanels
[
2
];
split
(
numer_
[
i
],
aPanels
);
split
(
denom_
[
i
],
bPanels
);
Mat
realPart
;
Mat
imaginaryPart
;
divide
(
aPanels
[
0
],
denom_
[
i
],
realPart
);
divide
(
aPanels
[
1
],
denom_
[
i
],
imaginaryPart
);
aPanels
[
0
]
=
realPart
;
aPanels
[
1
]
=
imaginaryPart
;
merge
(
aPanels
,
2
,
dst_
[
i
]);
}
}
};
void
shift
(
InputArray
src
,
OutputArray
dst
,
int
shift_x
,
int
shift_y
)
{
Mat
S
=
src
.
getMat
();
Mat
D
=
dst
.
getMat
();
...
...
@@ -73,14 +144,15 @@ namespace
// dft after padding imaginary
void
fft
(
InputArray
src
,
OutputArray
dst
)
{
Mat
S
=
src
.
getMat
();
Mat
planes
[]
=
{
S
,
Mat
::
zeros
(
S
.
size
(),
S
.
type
())};
Mat
planes
[]
=
{
S
.
clone
(),
Mat
::
zeros
(
S
.
size
(),
S
.
type
())};
Mat
x
;
merge
(
planes
,
2
,
dst
);
// compute the result
dft
(
dst
,
dst
);
}
void
psf2otf
(
InputArray
src
,
OutputArray
dst
,
int
height
,
int
width
)
{
void
psf2otf
(
InputArray
src
,
OutputArray
dst
,
int
height
,
int
width
)
{
Mat
S
=
src
.
getMat
();
Mat
D
=
dst
.
getMat
();
...
...
@@ -100,31 +172,34 @@ namespace
fft
(
padded
,
dst
);
}
void
dftMultiChannel
(
InputArray
src
,
vector
<
Mat
>
&
dst
)
{
void
dftMultiChannel
(
InputArray
src
,
vector
<
Mat
>
&
dst
)
{
Mat
S
=
src
.
getMat
();
split
(
S
,
dst
);
for
(
int
i
=
0
;
i
<
S
.
channels
();
i
++
){
fft
(
dst
[
i
],
dst
[
i
]);
Mat
planes
[]
=
{
dst
[
i
].
clone
(),
Mat
::
zeros
(
dst
[
i
].
size
(),
dst
[
i
].
type
())};
merge
(
planes
,
2
,
dst
[
i
]);
}
parallel_for_
(
cv
::
Range
(
0
,
S
.
channels
()),
ParallelDft
(
dst
));
}
void
idftMultiChannel
(
const
vector
<
Mat
>
&
src
,
OutputArray
dst
){
Mat
*
channels
=
new
Mat
[
src
.
size
()]
;
vector
<
Mat
>
channels
(
src
)
;
for
(
int
i
=
0
;
unsigned
(
i
)
<
src
.
size
();
i
++
){
idft
(
src
[
i
],
channels
[
i
]);
Mat
realImg
[
2
];
split
(
channels
[
i
],
realImg
);
channels
[
i
]
=
realImg
[
0
]
/
src
[
i
].
cols
/
src
[
i
].
rows
;
parallel_for_
(
Range
(
0
,
src
.
size
()),
ParallelIdft
(
channels
));
for
(
int
i
=
0
;
unsigned
(
i
)
<
src
.
size
();
i
++
){
Mat
panels
[
2
];
split
(
channels
[
i
],
panels
);
channels
[
i
]
=
panels
[
0
];
}
Mat
D
;
merge
(
channels
,
src
.
size
()
,
D
);
merge
(
channels
,
D
);
D
.
copyTo
(
dst
);
delete
[]
channels
;
}
void
addComplex
(
InputArray
aSrc
,
int
bSrc
,
OutputArray
dst
){
...
...
@@ -134,32 +209,15 @@ namespace
merge
(
panels
,
2
,
dst
);
}
void
divComplexByReal
(
InputArray
aSrc
,
InputArray
bSrc
,
OutputArray
dst
){
Mat
aPanels
[
2
];
Mat
bPanels
[
2
];
split
(
aSrc
.
getMat
(),
aPanels
);
split
(
bSrc
.
getMat
(),
bPanels
);
Mat
realPart
;
Mat
imaginaryPart
;
divide
(
aPanels
[
0
],
bSrc
.
getMat
(),
realPart
);
divide
(
aPanels
[
1
],
bSrc
.
getMat
(),
imaginaryPart
);
aPanels
[
0
]
=
realPart
;
aPanels
[
1
]
=
imaginaryPart
;
Mat
rst
;
merge
(
aPanels
,
2
,
dst
);
}
void
divComplexByRealMultiChannel
(
vector
<
Mat
>
&
numer
,
vector
<
Mat
>
&
denom
,
vector
<
Mat
>
&
dst
){
void
divComplexByRealMultiChannel
(
const
vector
<
Mat
>
&
numer
,
const
vector
<
Mat
>
&
denom
,
vector
<
Mat
>
&
dst
)
{
for
(
int
i
=
0
;
unsigned
(
i
)
<
numer
.
size
();
i
++
)
{
divComplexByReal
(
numer
[
i
],
denom
[
i
],
dst
[
i
]
);
dst
[
i
].
create
(
numer
[
i
].
size
(),
numer
[
i
].
type
()
);
}
parallel_for_
(
Range
(
0
,
numer
.
size
()),
ParallelDivComplexByReal
(
numer
,
denom
,
dst
));
}
// power of 2 of the absolute value of the complex
...
...
@@ -175,11 +233,11 @@ namespace
namespace
cv
{
namespace
ximgproc
{
namespace
ximgproc
{
void
l0Smooth
(
InputArray
src
,
OutputArray
dst
,
double
lambda
,
double
kappa
)
{
void
l0Smooth
(
InputArray
src
,
OutputArray
dst
,
double
lambda
,
double
kappa
)
{
Mat
S
=
src
.
getMat
();
CV_Assert
(
!
S
.
empty
());
...
...
@@ -222,7 +280,6 @@ void l0Smooth(InputArray src, OutputArray dst, double lambda, double kappa)
// input image in frequency domain
vector
<
Mat
>
numerConst
;
dftMultiChannel
(
S
,
numerConst
);
/*********************************
* solver
*********************************/
...
...
@@ -303,6 +360,6 @@ void l0Smooth(InputArray src, OutputArray dst, double lambda, double kappa)
}
else
{
S
.
copyTo
(
D
);
}
}
}
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment