Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
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
Commits
33239fca
Commit
33239fca
authored
Jun 10, 2014
by
Ilya Lavrenov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cv::equalizeHist
parent
c9528b39
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
13 deletions
+53
-13
histogram.cpp
modules/imgproc/src/histogram.cpp
+27
-11
histogram.cl
modules/imgproc/src/opencl/histogram.cl
+26
-2
No files found.
modules/imgproc/src/histogram.cpp
View file @
33239fca
...
...
@@ -3430,24 +3430,40 @@ namespace cv {
static
bool
ocl_equalizeHist
(
InputArray
_src
,
OutputArray
_dst
)
{
size_t
wgs
=
std
::
min
<
size_t
>
(
ocl
::
Device
::
getDefault
().
maxWorkGroupSize
(),
BINS
);
const
ocl
::
Device
&
dev
=
ocl
::
Device
::
getDefault
();
int
compunits
=
dev
.
maxComputeUnits
();
size_t
wgs
=
dev
.
maxWorkGroupSize
();
Size
size
=
_src
.
size
();
bool
use16
=
size
.
width
%
16
==
0
&&
_src
.
offset
()
%
16
==
0
&&
_src
.
step
()
%
16
==
0
;
int
kercn
=
dev
.
isAMD
()
&&
use16
?
16
:
std
::
min
(
4
,
ocl
::
predictOptimalVectorWidth
(
_src
));
// calculation of histogram
UMat
hist
;
if
(
!
ocl_calcHist1
(
_src
,
hist
))
ocl
::
Kernel
k1
(
"calculate_histogram"
,
ocl
::
imgproc
::
histogram_oclsrc
,
format
(
"-D BINS=%d -D HISTS_COUNT=%d -D WGS=%d -D kercn=%d -D T=%s%s"
,
BINS
,
compunits
,
wgs
,
kercn
,
kercn
==
4
?
"int"
:
ocl
::
typeToStr
(
CV_8UC
(
kercn
)),
_src
.
isContinuous
()
?
" -D HAVE_SRC_CONT"
:
""
));
if
(
k1
.
empty
())
return
false
;
UMat
lut
(
1
,
256
,
CV_8UC1
);
ocl
::
Kernel
k
(
"calcLUT"
,
ocl
::
imgproc
::
histogram_oclsrc
,
format
(
"-D BINS=%d -D HISTS_COUNT=1 -D WGS=%d"
,
BINS
,
(
int
)
wgs
));
if
(
k
.
empty
())
UMat
src
=
_src
.
getUMat
(),
ghist
(
1
,
BINS
*
compunits
,
CV_32SC1
);
k1
.
args
(
ocl
::
KernelArg
::
ReadOnly
(
src
),
ocl
::
KernelArg
::
PtrWriteOnly
(
ghist
),
(
int
)
src
.
total
());
size_t
globalsize
=
compunits
*
wgs
;
if
(
!
k1
.
run
(
1
,
&
globalsize
,
&
wgs
,
false
))
return
false
;
k
.
args
(
ocl
::
KernelArg
::
PtrWriteOnly
(
lut
),
ocl
::
KernelArg
::
PtrReadOnly
(
hist
),
(
int
)
_src
.
total
());
wgs
=
std
::
min
<
size_t
>
(
ocl
::
Device
::
getDefault
().
maxWorkGroupSize
(),
BINS
);
UMat
lut
(
1
,
256
,
CV_8UC1
);
ocl
::
Kernel
k2
(
"calcLUT"
,
ocl
::
imgproc
::
histogram_oclsrc
,
format
(
"-D BINS=%d -D HISTS_COUNT=%d -D WGS=%d"
,
BINS
,
compunits
,
(
int
)
wgs
));
k2
.
args
(
ocl
::
KernelArg
::
PtrWriteOnly
(
lut
),
ocl
::
KernelArg
::
PtrReadOnly
(
ghist
),
(
int
)
_src
.
total
());
// calculation of LUT
if
(
!
k
.
run
(
1
,
&
wgs
,
&
wgs
,
false
))
if
(
!
k
2
.
run
(
1
,
&
wgs
,
&
wgs
,
false
))
return
false
;
// execute LUT transparently
...
...
modules/imgproc/src/opencl/histogram.cl
View file @
33239fca
...
...
@@ -153,13 +153,37 @@ __kernel void merge_histogram(__global const int * ghist, __global uchar * histp
#
endif
}
__kernel
void
calcLUT
(
__global
uchar
*
dst,
__
constant
int
*
hist,
int
total
)
__kernel
void
calcLUT
(
__global
uchar
*
dst,
__
global
const
int
*
g
hist,
int
total
)
{
int
lid
=
get_local_id
(
0
)
;
__local
int
sumhist[BINS]
;
__local
float
scale
;
sumhist[lid]
=
hist[lid]
;
#
if
WGS
>=
BINS
int
res
=
0
;
#
else
#
pragma
unroll
for
(
int
i
=
lid
; i < BINS; i += WGS)
sumhist[i]
=
0
;
#
endif
#
pragma
unroll
for
(
int
i
=
0
; i < HISTS_COUNT; ++i)
{
#
pragma
unroll
for
(
int
j
=
lid
; j < BINS; j += WGS)
#
if
WGS
>=
BINS
res
+=
ghist[j]
;
#
else
sumhist[j]
+=
ghist[j]
;
#
endif
ghist
+=
BINS
;
}
#
if
WGS
>=
BINS
if
(
lid
<
BINS
)
sumhist[lid]
=
res
;
#
endif
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
if
(
lid
==
0
)
...
...
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