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
9ac17415
Commit
9ac17415
authored
Jul 29, 2010
by
Anatoly Baksheev
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
speckle filtering added
parent
63fed0f8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
166 additions
and
1 deletion
+166
-1
gpu.hpp
modules/gpu/include/opencv2/gpu/gpu.hpp
+6
-0
matrix_operations.cpp
modules/gpu/src/matrix_operations.cpp
+1
-1
speckle_filtering.cpp
modules/gpu/src/speckle_filtering.cpp
+159
-0
No files found.
modules/gpu/include/opencv2/gpu/gpu.hpp
View file @
9ac17415
...
@@ -413,6 +413,12 @@ namespace cv
...
@@ -413,6 +413,12 @@ namespace cv
GpuMat
out
;
GpuMat
out
;
};
};
}
}
//! Speckle filtering - filters small connected components on diparity image.
//! It sets pixel (x,y) to newVal if it coresponds to small CC with size < maxSpeckleSize.
//! Threshold for border between CC is diffThreshold;
void
filterSpeckles
(
Mat
&
img
,
uchar
newVal
,
int
maxSpeckleSize
,
uchar
diffThreshold
,
Mat
&
buf
);
}
}
#include "opencv2/gpu/matrix_operations.hpp"
#include "opencv2/gpu/matrix_operations.hpp"
...
...
modules/gpu/src/matrix_operations.cpp
View file @
9ac17415
...
@@ -164,7 +164,7 @@ GpuMat& GpuMat::setTo(const Scalar& s, const GpuMat& mask)
...
@@ -164,7 +164,7 @@ GpuMat& GpuMat::setTo(const Scalar& s, const GpuMat& mask)
else
else
impl
::
set_to_with_mask
(
*
this
,
depth
(),
s
.
val
,
mask
,
channels
());
impl
::
set_to_with_mask
(
*
this
,
depth
(),
s
.
val
,
mask
,
channels
());
return
*
this
;
return
*
this
;
}
}
...
...
modules/gpu/src/speckle_filtering.cpp
0 → 100644
View file @
9ac17415
/*M///////////////////////////////////////////////////////////////////////////////////////
//
// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
//
// By downloading, copying, installing or using the software you agree to this license.
// If you do not agree to this license, do not download, install,
// copy or use the software.
//
//
// License Agreement
// For Open Source Computer Vision Library
//
// Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
// Copyright (C) 2009, Willow Garage Inc., all rights reserved.
// Third party copyrights are property of their respective owners.
//
// 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.
//
//M*/
#include "precomp.hpp"
using
namespace
cv
;
typedef
Point_
<
short
>
Point2s
;
void
cv
::
filterSpeckles
(
Mat
&
img
,
uchar
newVal
,
int
maxSpeckleSize
,
uchar
maxDiff
,
Mat
&
_buf
)
{
int
MaxD
=
1024
;
int
WinSz
=
64
;
int
bufSize0
=
(
MaxD
+
2
)
*
sizeof
(
int
)
+
(
img
.
rows
+
WinSz
+
2
)
*
MaxD
*
sizeof
(
int
)
+
(
img
.
rows
+
WinSz
+
2
)
*
sizeof
(
int
)
+
(
img
.
rows
+
WinSz
+
2
)
*
MaxD
*
(
WinSz
+
1
)
*
sizeof
(
uchar
)
+
256
;
int
bufSize1
=
(
img
.
cols
+
9
+
2
)
*
sizeof
(
int
)
+
256
;
int
bufSz
=
max
(
bufSize0
*
1
,
bufSize1
*
2
);
_buf
.
create
(
1
,
bufSz
,
CV_8U
);
CV_Assert
(
img
.
type
()
==
CV_8U
);
int
width
=
img
.
cols
,
height
=
img
.
rows
,
npixels
=
width
*
height
;
size_t
bufSize
=
npixels
*
(
int
)(
sizeof
(
Point2s
)
+
sizeof
(
int
)
+
sizeof
(
uchar
));
if
(
!
_buf
.
isContinuous
()
||
!
_buf
.
data
||
_buf
.
cols
*
_buf
.
rows
*
_buf
.
elemSize
()
<
bufSize
)
_buf
.
create
(
1
,
bufSize
,
CV_8U
);
uchar
*
buf
=
_buf
.
data
;
int
i
,
j
,
dstep
=
img
.
step
/
sizeof
(
uchar
);
int
*
labels
=
(
int
*
)
buf
;
buf
+=
npixels
*
sizeof
(
labels
[
0
]);
Point2s
*
wbuf
=
(
Point2s
*
)
buf
;
buf
+=
npixels
*
sizeof
(
wbuf
[
0
]);
uchar
*
rtype
=
(
uchar
*
)
buf
;
int
curlabel
=
0
;
// clear out label assignments
memset
(
labels
,
0
,
npixels
*
sizeof
(
labels
[
0
]));
for
(
i
=
0
;
i
<
height
;
i
++
)
{
uchar
*
ds
=
img
.
ptr
<
uchar
>
(
i
);
int
*
ls
=
labels
+
width
*
i
;
for
(
j
=
0
;
j
<
width
;
j
++
)
{
if
(
ds
[
j
]
!=
newVal
)
// not a bad disparity
{
if
(
ls
[
j
]
)
// has a label, check for bad label
{
if
(
rtype
[
ls
[
j
]]
)
// small region, zero out disparity
ds
[
j
]
=
(
uchar
)
newVal
;
}
// no label, assign and propagate
else
{
Point2s
*
ws
=
wbuf
;
// initialize wavefront
Point2s
p
((
short
)
j
,
(
short
)
i
);
// current pixel
curlabel
++
;
// next label
int
count
=
0
;
// current region size
ls
[
j
]
=
curlabel
;
// wavefront propagation
while
(
ws
>=
wbuf
)
// wavefront not empty
{
count
++
;
// put neighbors onto wavefront
uchar
*
dpp
=
&
img
.
at
<
uchar
>
(
p
.
y
,
p
.
x
);
uchar
dp
=
*
dpp
;
int
*
lpp
=
labels
+
width
*
p
.
y
+
p
.
x
;
if
(
p
.
x
<
width
-
1
&&
!
lpp
[
+
1
]
&&
dpp
[
+
1
]
!=
newVal
&&
std
::
abs
(
dp
-
dpp
[
+
1
])
<=
maxDiff
)
{
lpp
[
+
1
]
=
curlabel
;
*
ws
++
=
Point2s
(
p
.
x
+
1
,
p
.
y
);
}
if
(
p
.
x
>
0
&&
!
lpp
[
-
1
]
&&
dpp
[
-
1
]
!=
newVal
&&
std
::
abs
(
dp
-
dpp
[
-
1
])
<=
maxDiff
)
{
lpp
[
-
1
]
=
curlabel
;
*
ws
++
=
Point2s
(
p
.
x
-
1
,
p
.
y
);
}
if
(
p
.
y
<
height
-
1
&&
!
lpp
[
+
width
]
&&
dpp
[
+
dstep
]
!=
newVal
&&
std
::
abs
(
dp
-
dpp
[
+
dstep
])
<=
maxDiff
)
{
lpp
[
+
width
]
=
curlabel
;
*
ws
++
=
Point2s
(
p
.
x
,
p
.
y
+
1
);
}
if
(
p
.
y
>
0
&&
!
lpp
[
-
width
]
&&
dpp
[
-
dstep
]
!=
newVal
&&
std
::
abs
(
dp
-
dpp
[
-
dstep
])
<=
maxDiff
)
{
lpp
[
-
width
]
=
curlabel
;
*
ws
++
=
Point2s
(
p
.
x
,
p
.
y
-
1
);
}
// pop most recent and propagate
// NB: could try least recent, maybe better convergence
p
=
*--
ws
;
}
// assign label type
if
(
count
<=
maxSpeckleSize
)
// speckle region
{
//printf("count = %d\n", count);
rtype
[
ls
[
j
]]
=
1
;
// small region label
ds
[
j
]
=
(
uchar
)
newVal
;
}
else
{
//printf("count = %d\n", count);
rtype
[
ls
[
j
]]
=
0
;
// large region label
}
}
}
}
}
}
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