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
f55c85fe
Commit
f55c85fe
authored
Dec 18, 2013
by
Konstantin Matskevich
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
morphology
parent
65b020f0
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
219 additions
and
0 deletions
+219
-0
morph.cpp
modules/imgproc/src/morph.cpp
+0
-0
morph.cl
modules/imgproc/src/opencl/morph.cl
+125
-0
test_filters.cpp
modules/imgproc/test/ocl/test_filters.cpp
+94
-0
No files found.
modules/imgproc/src/morph.cpp
View file @
f55c85fe
This diff is collapsed.
Click to expand it.
modules/imgproc/src/opencl/morph.cl
0 → 100644
View file @
f55c85fe
//
License
Agreement
//
For
Open
Source
Computer
Vision
Library
//
//
Copyright
(
C
)
2010-2012,
Institute
Of
Software
Chinese
Academy
Of
Science,
all
rights
reserved.
//
Copyright
(
C
)
2010-2012,
Advanced
Micro
Devices,
Inc.,
all
rights
reserved.
//
Third
party
copyrights
are
property
of
their
respective
owners.
//
//
@Authors
//
Niko
Li,
newlife20080214@gmail.com
//
Zero
Lin,
zero.lin@amd.com
//
Yao
Wang,
bitwangyaoyao@gmail.com
//
Redistribution
and
use
in
source
and
binary
forms,
with
or
without
modification,
//
are
permitted
provided
that
the
following
conditions
are
met:
//
//
*
Redistribution
's
of
source
code
must
retain
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer.
//
//
*
Redistribution
's
in
binary
form
must
reproduce
the
above
copyright
notice,
//
this
list
of
conditions
and
the
following
disclaimer
in
the
documentation
//
and/or
other
materials
provided
with
the
distribution.
//
//
*
The
name
of
the
copyright
holders
may
not
be
used
to
endorse
or
promote
products
//
derived
from
this
software
without
specific
prior
written
permission.
//
//
This
software
is
provided
by
the
copyright
holders
and
contributors
as
is
and
//
any
express
or
implied
warranties,
including,
but
not
limited
to,
the
implied
//
warranties
of
merchantability
and
fitness
for
a
particular
purpose
are
disclaimed.
//
In
no
event
shall
the
Intel
Corporation
or
contributors
be
liable
for
any
direct,
//
indirect,
incidental,
special,
exemplary,
or
consequential
damages
//
(
including,
but
not
limited
to,
procurement
of
substitute
goods
or
services
;
//
loss
of
use,
data,
or
profits
; or business interruption) however caused
//
and
on
any
theory
of
liability,
whether
in
contract,
strict
liability,
//
or
tort
(
including
negligence
or
otherwise
)
arising
in
any
way
out
of
//
the
use
of
this
software,
even
if
advised
of
the
possibility
of
such
damage.
//
//
#
ifdef
DOUBLE_SUPPORT
#
ifdef
cl_amd_fp64
#
pragma
OPENCL
EXTENSION
cl_amd_fp64:enable
#
elif
defined
(
cl_khr_fp64
)
#
pragma
OPENCL
EXTENSION
cl_khr_fp64:enable
#
endif
#
endif
#
ifdef
ERODE
#
define
MORPH_OP
(
A,B
)
min
((
A
)
,
(
B
))
#
endif
#
ifdef
DILATE
#
define
MORPH_OP
(
A,B
)
max
((
A
)
,
(
B
))
#
endif
//BORDER_CONSTANT:
iiiiii|abcdefgh|iiiiiii
#
define
ELEM
(
i,l_edge,r_edge,elem1,elem2
)
(
i
)
<
(
l_edge
)
|
(
i
)
>=
(
r_edge
)
?
(
elem1
)
:
(
elem2
)
__kernel
void
morph
(
__global
const
GENTYPE
*
restrict
src,
__global
GENTYPE
*dst,
int
src_offset_x,
int
src_offset_y,
int
cols,
int
rows,
int
src_step_in_pixel,
int
dst_step_in_pixel,
__constant
uchar
*
mat_kernel,
int
src_whole_cols,
int
src_whole_rows,
int
dst_offset_in_pixel
)
{
int
l_x
=
get_local_id
(
0
)
;
int
l_y
=
get_local_id
(
1
)
;
int
x
=
get_group_id
(
0
)
*LSIZE0
;
int
y
=
get_group_id
(
1
)
*LSIZE1
;
int
start_x
=
x+src_offset_x-RADIUSX
;
int
end_x
=
x
+
src_offset_x+LSIZE0+RADIUSX
;
int
width
=
end_x
-
(
x+src_offset_x-RADIUSX
)
+1
;
int
start_y
=
y+src_offset_y-RADIUSY
;
int
point1
=
mad24
(
l_y,LSIZE0,l_x
)
;
int
point2
=
point1
+
LSIZE0*LSIZE1
;
int
tl_x
=
point1
%
width
;
int
tl_y
=
point1
/
width
;
int
tl_x2
=
point2
%
width
;
int
tl_y2
=
point2
/
width
;
int
cur_x
=
start_x
+
tl_x
;
int
cur_y
=
start_y
+
tl_y
;
int
cur_x2
=
start_x
+
tl_x2
;
int
cur_y2
=
start_y
+
tl_y2
;
int
start_addr
=
mad24
(
cur_y,src_step_in_pixel,cur_x
)
;
int
start_addr2
=
mad24
(
cur_y2,src_step_in_pixel,cur_x2
)
;
GENTYPE
temp0,temp1
;
__local
GENTYPE
LDS_DAT[2*LSIZE1*LSIZE0]
;
int
end_addr
=
mad24
(
src_whole_rows
-
1
,
src_step_in_pixel,src_whole_cols
)
;
//read
pixels
from
src
start_addr
=
((
start_addr
<
end_addr
)
&&
(
start_addr
>
0
))
?
start_addr
:
0
;
start_addr2
=
((
start_addr2
<
end_addr
)
&&
(
start_addr2
>
0
))
?
start_addr2
:
0
;
temp0
=
src[start_addr]
;
temp1
=
src[start_addr2]
;
//judge
if
read
out
of
boundary
temp0=
ELEM
(
cur_x,0,src_whole_cols,
(
GENTYPE
)
VAL,temp0
)
;
temp0=
ELEM
(
cur_y,0,src_whole_rows,
(
GENTYPE
)
VAL,temp0
)
;
temp1=
ELEM
(
cur_x2,0,src_whole_cols,
(
GENTYPE
)
VAL,temp1
)
;
temp1=
ELEM
(
cur_y2,0,src_whole_rows,
(
GENTYPE
)
VAL,temp1
)
;
LDS_DAT[point1]
=
temp0
;
LDS_DAT[point2]
=
temp1
;
barrier
(
CLK_LOCAL_MEM_FENCE
)
;
GENTYPE
res
=
(
GENTYPE
)
VAL
;
for
(
int
i=0
; i<2*RADIUSY+1; i++)
for
(
int
j=0
; j<2*RADIUSX+1; j++)
{
res
=
#
ifndef
RECTKERNEL
mat_kernel[i*
(
2*RADIUSX+1
)
+j]
?
#
endif
MORPH_OP
(
res,LDS_DAT[mad24
(
l_y+i,width,l_x+j
)
]
)
#
ifndef
RECTKERNEL
:res
#
endif
;
}
int
gidx
=
get_global_id
(
0
)
;
int
gidy
=
get_global_id
(
1
)
;
int
out_addr
=
mad24
(
gidy,dst_step_in_pixel,gidx+dst_offset_in_pixel
)
;
if
(
gidx<cols
&&
gidy<rows
)
{
dst[out_addr]
=
res
;
}
}
modules/imgproc/test/ocl/test_filters.cpp
View file @
f55c85fe
...
...
@@ -229,6 +229,75 @@ OCL_TEST_P(GaussianBlurTest, Mat)
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// Erode
typedef
FilterTestBase
Erode
;
OCL_TEST_P
(
Erode
,
Mat
)
{
Size
kernelSize
(
ksize
,
ksize
);
int
iterations
=
(
int
)
param
;
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
random_roi
();
Mat
kernel
=
randomMat
(
kernelSize
,
CV_8UC1
,
0
,
3
);
OCL_OFF
(
cv
::
erode
(
src_roi
,
dst_roi
,
kernel
,
Point
(
-
1
,
-
1
),
iterations
)
);
OCL_ON
(
cv
::
erode
(
usrc_roi
,
udst_roi
,
kernel
,
Point
(
-
1
,
-
1
),
iterations
)
);
Near
();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// Dilate
typedef
FilterTestBase
Dilate
;
OCL_TEST_P
(
Dilate
,
Mat
)
{
Size
kernelSize
(
ksize
,
ksize
);
int
iterations
=
(
int
)
param
;
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
random_roi
();
Mat
kernel
=
randomMat
(
kernelSize
,
CV_8UC1
,
0
,
3
);
OCL_OFF
(
cv
::
dilate
(
src_roi
,
dst_roi
,
kernel
,
Point
(
-
1
,
-
1
),
iterations
)
);
OCL_ON
(
cv
::
dilate
(
usrc_roi
,
udst_roi
,
kernel
,
Point
(
-
1
,
-
1
),
iterations
)
);
Near
();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////
// MorphologyEx
typedef
FilterTestBase
MorphologyEx
;
OCL_TEST_P
(
MorphologyEx
,
Mat
)
{
Size
kernelSize
(
ksize
,
ksize
);
int
iterations
=
(
int
)
param
;
int
op
=
size
.
height
;
for
(
int
j
=
0
;
j
<
test_loop_times
;
j
++
)
{
random_roi
();
Mat
kernel
=
randomMat
(
kernelSize
,
CV_8UC1
,
0
,
3
);
OCL_OFF
(
cv
::
morphologyEx
(
src_roi
,
dst_roi
,
op
,
kernel
,
Point
(
-
1
,
-
1
),
iterations
)
);
OCL_ON
(
cv
::
morphologyEx
(
usrc_roi
,
udst_roi
,
op
,
kernel
,
Point
(
-
1
,
-
1
),
iterations
)
);
Near
();
}
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////
#define FILTER_BORDER_SET_NO_ISOLATED \
...
...
@@ -285,6 +354,31 @@ OCL_INSTANTIATE_TEST_CASE_P(Filter, GaussianBlurTest, Combine(
Values
(
0.0
),
// not used
Bool
()));
OCL_INSTANTIATE_TEST_CASE_P
(
Filter
,
Erode
,
Combine
(
Values
(
CV_8UC1
,
CV_8UC4
,
CV_32FC1
,
CV_32FC4
,
CV_64FC1
,
CV_64FC4
),
Values
(
3
,
5
,
7
),
Values
(
Size
(
0
,
0
)),
//not used
Values
((
BorderType
)
BORDER_CONSTANT
),
//not used
Values
(
1.0
,
2.0
,
3.0
),
Bool
()
)
);
OCL_INSTANTIATE_TEST_CASE_P
(
Filter
,
Dilate
,
Combine
(
Values
(
CV_8UC1
,
CV_8UC4
,
CV_32FC1
,
CV_32FC4
,
CV_64FC1
,
CV_64FC4
),
Values
(
3
,
5
,
7
),
Values
(
Size
(
0
,
0
)),
//not used
Values
((
BorderType
)
BORDER_CONSTANT
),
//not used
Values
(
1.0
,
2.0
,
3.0
),
Bool
()
)
);
OCL_INSTANTIATE_TEST_CASE_P
(
Filter
,
MorphologyEx
,
Combine
(
Values
(
CV_8UC1
,
CV_8UC4
,
CV_32FC1
,
CV_32FC4
,
CV_64FC1
,
CV_64FC4
),
Values
(
3
,
5
,
7
),
Values
(
Size
(
0
,
0
),
Size
(
0
,
1
),
Size
(
0
,
2
),
Size
(
0
,
3
),
Size
(
0
,
4
),
Size
(
0
,
5
),
Size
(
0
,
6
)),
//uses as generator of operations
Values
((
BorderType
)
BORDER_CONSTANT
),
//not used
Values
(
1.0
,
2.0
,
3.0
),
Bool
()
)
);
}
}
// namespace cvtest::ocl
#endif // HAVE_OPENCL
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