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
e178294b
Commit
e178294b
authored
Feb 12, 2015
by
Erik Karlsson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactoring in preparation for 16-bit implementation of fastNlMeansDenoising
parent
5466e321
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
113 additions
and
79 deletions
+113
-79
denoising.cpp
modules/photo/src/denoising.cpp
+6
-6
fast_nlmeans_denoising_invoker.hpp
modules/photo/src/fast_nlmeans_denoising_invoker.hpp
+0
-0
fast_nlmeans_denoising_invoker_commons.hpp
modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp
+107
-73
fast_nlmeans_multi_denoising_invoker.hpp
modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp
+0
-0
No files found.
modules/photo/src/denoising.cpp
View file @
e178294b
...
...
@@ -65,17 +65,17 @@ void cv::fastNlMeansDenoising( InputArray _src, OutputArray _dst, float h,
switch
(
src
.
type
())
{
case
CV_8U
:
parallel_for_
(
cv
::
Range
(
0
,
src
.
rows
),
FastNlMeansDenoisingInvoker
<
uchar
>
(
FastNlMeansDenoisingInvoker
<
uchar
,
int
,
unsigned
int
>
(
src
,
dst
,
templateWindowSize
,
searchWindowSize
,
h
));
break
;
case
CV_8UC2
:
parallel_for_
(
cv
::
Range
(
0
,
src
.
rows
),
FastNlMeansDenoisingInvoker
<
cv
::
Vec2b
>
(
FastNlMeansDenoisingInvoker
<
cv
::
Vec2b
,
int
,
unsigned
int
>
(
src
,
dst
,
templateWindowSize
,
searchWindowSize
,
h
));
break
;
case
CV_8UC3
:
parallel_for_
(
cv
::
Range
(
0
,
src
.
rows
),
FastNlMeansDenoisingInvoker
<
cv
::
Vec3b
>
(
FastNlMeansDenoisingInvoker
<
cv
::
Vec3b
,
int
,
unsigned
int
>
(
src
,
dst
,
templateWindowSize
,
searchWindowSize
,
h
));
break
;
default
:
...
...
@@ -175,19 +175,19 @@ void cv::fastNlMeansDenoisingMulti( InputArrayOfArrays _srcImgs, OutputArray _ds
{
case
CV_8U
:
parallel_for_
(
cv
::
Range
(
0
,
srcImgs
[
0
].
rows
),
FastNlMeansMultiDenoisingInvoker
<
uchar
>
(
FastNlMeansMultiDenoisingInvoker
<
uchar
,
int
,
unsigned
int
>
(
srcImgs
,
imgToDenoiseIndex
,
temporalWindowSize
,
dst
,
templateWindowSize
,
searchWindowSize
,
h
));
break
;
case
CV_8UC2
:
parallel_for_
(
cv
::
Range
(
0
,
srcImgs
[
0
].
rows
),
FastNlMeansMultiDenoisingInvoker
<
cv
::
Vec2b
>
(
FastNlMeansMultiDenoisingInvoker
<
cv
::
Vec2b
,
int
,
unsigned
int
>
(
srcImgs
,
imgToDenoiseIndex
,
temporalWindowSize
,
dst
,
templateWindowSize
,
searchWindowSize
,
h
));
break
;
case
CV_8UC3
:
parallel_for_
(
cv
::
Range
(
0
,
srcImgs
[
0
].
rows
),
FastNlMeansMultiDenoisingInvoker
<
cv
::
Vec3b
>
(
FastNlMeansMultiDenoisingInvoker
<
cv
::
Vec3b
,
int
,
unsigned
int
>
(
srcImgs
,
imgToDenoiseIndex
,
temporalWindowSize
,
dst
,
templateWindowSize
,
searchWindowSize
,
h
));
break
;
...
...
modules/photo/src/fast_nlmeans_denoising_invoker.hpp
View file @
e178294b
This diff is collapsed.
Click to expand it.
modules/photo/src/fast_nlmeans_denoising_invoker_commons.hpp
View file @
e178294b
...
...
@@ -44,118 +44,152 @@
using
namespace
cv
;
template
<
typename
T
>
static
inline
int
calcDist
(
const
T
a
,
const
T
b
);
template
<>
inline
int
calcDist
(
const
uchar
a
,
const
uchar
b
)
template
<
typename
T
,
typename
IT
>
struct
calcDist_
{
return
(
a
-
b
)
*
(
a
-
b
);
}
static
inline
IT
f
(
const
T
a
,
const
T
b
);
}
;
template
<
>
inline
int
calcDist
(
const
Vec2b
a
,
const
Vec2b
b
)
template
<
typename
IT
>
struct
calcDist_
<
uchar
,
IT
>
{
return
(
a
[
0
]
-
b
[
0
])
*
(
a
[
0
]
-
b
[
0
])
+
(
a
[
1
]
-
b
[
1
])
*
(
a
[
1
]
-
b
[
1
]);
}
static
inline
IT
f
(
uchar
a
,
uchar
b
)
{
return
(
IT
)(
a
-
b
)
*
(
IT
)(
a
-
b
);
}
};
template
<
>
inline
int
calcDist
(
const
Vec3b
a
,
const
Vec3b
b
)
template
<
typename
IT
>
struct
calcDist_
<
Vec2b
,
IT
>
{
return
(
a
[
0
]
-
b
[
0
])
*
(
a
[
0
]
-
b
[
0
])
+
(
a
[
1
]
-
b
[
1
])
*
(
a
[
1
]
-
b
[
1
])
+
(
a
[
2
]
-
b
[
2
])
*
(
a
[
2
]
-
b
[
2
]);
}
static
inline
IT
f
(
const
Vec2b
a
,
const
Vec2b
b
)
{
return
(
IT
)(
a
[
0
]
-
b
[
0
])
*
(
IT
)(
a
[
0
]
-
b
[
0
])
+
(
IT
)(
a
[
1
]
-
b
[
1
])
*
(
IT
)(
a
[
1
]
-
b
[
1
]);
}
};
template
<
typename
T
>
static
inline
int
calcDist
(
const
Mat
&
m
,
int
i1
,
int
j1
,
int
i2
,
int
j2
)
template
<
typename
IT
>
struct
calcDist_
<
Vec3b
,
IT
>
{
const
T
a
=
m
.
at
<
T
>
(
i1
,
j1
);
const
T
b
=
m
.
at
<
T
>
(
i2
,
j2
);
return
calcDist
<
T
>
(
a
,
b
);
}
static
inline
IT
f
(
const
Vec3b
a
,
const
Vec3b
b
)
{
return
(
IT
)(
a
[
0
]
-
b
[
0
])
*
(
IT
)(
a
[
0
]
-
b
[
0
])
+
(
IT
)(
a
[
1
]
-
b
[
1
])
*
(
IT
)(
a
[
1
]
-
b
[
1
])
+
(
IT
)(
a
[
2
]
-
b
[
2
])
*
(
IT
)(
a
[
2
]
-
b
[
2
]);
}
};
template
<
typename
T
>
static
inline
int
calcUpDownDist
(
T
a_up
,
T
a_down
,
T
b_up
,
T
b_down
)
template
<
typename
T
,
typename
IT
>
static
inline
IT
calcDist
(
const
T
a
,
const
T
b
)
{
return
calcDist
(
a_down
,
b_down
)
-
calcDist
(
a_up
,
b_up
);
return
calcDist
_
<
T
,
IT
>::
f
(
a
,
b
);
}
template
<>
inline
int
calcUpDownDist
(
uchar
a_up
,
uchar
a_down
,
uchar
b_up
,
uchar
b_down
)
template
<
typename
T
,
typename
IT
>
static
inline
IT
calcDist
(
const
Mat
&
m
,
int
i1
,
int
j1
,
int
i2
,
int
j2
)
{
int
A
=
a_down
-
b_down
;
int
B
=
a_up
-
b_up
;
return
(
A
-
B
)
*
(
A
+
B
);
const
T
a
=
m
.
at
<
T
>
(
i1
,
j1
)
;
const
T
b
=
m
.
at
<
T
>
(
i2
,
j2
)
;
return
calcDist
<
T
,
IT
>
(
a
,
b
);
}
template
<
typename
T
>
static
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
T
p
);
template
<>
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
uchar
p
)
template
<
typename
T
,
typename
IT
>
struct
calcUpDownDist_
{
estimation
[
0
]
+=
weight
*
p
;
}
static
inline
IT
f
(
T
a_up
,
T
a_down
,
T
b_up
,
T
b_down
)
{
return
calcDist
<
T
,
IT
>
(
a_down
,
b_down
)
-
calcDist
<
T
,
IT
>
(
a_up
,
b_up
);
}
};
template
<
>
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
Vec2b
p
)
template
<
typename
IT
>
struct
calcUpDownDist_
<
uchar
,
IT
>
{
estimation
[
0
]
+=
weight
*
p
[
0
];
estimation
[
1
]
+=
weight
*
p
[
1
];
}
static
inline
IT
f
(
uchar
a_up
,
uchar
a_down
,
uchar
b_up
,
uchar
b_down
)
{
IT
A
=
a_down
-
b_down
;
IT
B
=
a_up
-
b_up
;
return
(
A
-
B
)
*
(
A
+
B
);
}
};
template
<>
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
Vec3b
p
)
template
<
typename
T
,
typename
IT
>
static
inline
IT
calcUpDownDist
(
T
a_up
,
T
a_down
,
T
b_up
,
T
b_down
)
{
estimation
[
0
]
+=
weight
*
p
[
0
];
estimation
[
1
]
+=
weight
*
p
[
1
];
estimation
[
2
]
+=
weight
*
p
[
2
];
}
return
calcUpDownDist_
<
T
,
IT
>::
f
(
a_up
,
a_down
,
b_up
,
b_down
);
};
template
<
>
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
int
p
)
template
<
typename
T
,
typename
IT
>
struct
incWithWeight_
{
estimation
[
0
]
+=
weight
*
p
;
}
static
inline
void
f
(
IT
*
estimation
,
IT
weight
,
T
p
)
;
}
;
template
<
>
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
Vec2i
p
)
template
<
typename
IT
>
struct
incWithWeight_
<
uchar
,
IT
>
{
estimation
[
0
]
+=
weight
*
p
[
0
];
estimation
[
1
]
+=
weight
*
p
[
1
];
}
static
inline
void
f
(
IT
*
estimation
,
IT
weight
,
uchar
p
)
{
estimation
[
0
]
+=
weight
*
p
;
}
};
template
<
>
inline
void
incWithWeight
(
int
*
estimation
,
int
weight
,
Vec3i
p
)
template
<
typename
IT
>
struct
incWithWeight_
<
Vec2b
,
IT
>
{
estimation
[
0
]
+=
weight
*
p
[
0
];
estimation
[
1
]
+=
weight
*
p
[
1
];
estimation
[
2
]
+=
weight
*
p
[
2
];
}
static
inline
void
f
(
IT
*
estimation
,
IT
weight
,
Vec2b
p
)
{
estimation
[
0
]
+=
weight
*
p
[
0
];
estimation
[
1
]
+=
weight
*
p
[
1
];
}
};
template
<
typename
T
>
static
inline
T
saturateCastFromArray
(
int
*
estimation
);
template
<
typename
IT
>
struct
incWithWeight_
<
Vec3b
,
IT
>
{
static
inline
void
f
(
IT
*
estimation
,
IT
weight
,
Vec3b
p
)
{
estimation
[
0
]
+=
weight
*
p
[
0
];
estimation
[
1
]
+=
weight
*
p
[
1
];
estimation
[
2
]
+=
weight
*
p
[
2
];
}
};
template
<>
inline
uchar
saturateCastFromArray
(
int
*
estimation
)
template
<
typename
T
,
typename
IT
>
static
inline
void
incWithWeight
(
IT
*
estimation
,
IT
weight
,
T
p
)
{
return
saturate_cast
<
uchar
>
(
estimation
[
0
]
);
return
incWithWeight_
<
T
,
IT
>::
f
(
estimation
,
weight
,
p
);
}
template
<
>
inline
Vec2b
saturateCastFromArray
(
int
*
estimation
)
template
<
typename
T
,
typename
IT
>
struct
saturateCastFromArray_
{
Vec2b
res
;
res
[
0
]
=
saturate_cast
<
uchar
>
(
estimation
[
0
]);
res
[
1
]
=
saturate_cast
<
uchar
>
(
estimation
[
1
]);
return
res
;
}
static
inline
T
f
(
IT
*
estimation
);
};
template
<
>
inline
Vec3b
saturateCastFromArray
(
int
*
estimation
)
template
<
typename
IT
>
struct
saturateCastFromArray_
<
uchar
,
IT
>
{
Vec3b
res
;
res
[
0
]
=
saturate_cast
<
uchar
>
(
estimation
[
0
]);
res
[
1
]
=
saturate_cast
<
uchar
>
(
estimation
[
1
]);
res
[
2
]
=
saturate_cast
<
uchar
>
(
estimation
[
2
]);
return
res
;
}
static
inline
uchar
f
(
IT
*
estimation
)
{
return
saturate_cast
<
uchar
>
(
estimation
[
0
]);
}
};
template
<
>
inline
int
saturateCastFromArray
(
int
*
estimation
)
template
<
typename
IT
>
struct
saturateCastFromArray_
<
Vec2b
,
IT
>
{
return
estimation
[
0
];
}
static
inline
Vec2b
f
(
IT
*
estimation
)
{
Vec2b
res
;
res
[
0
]
=
saturate_cast
<
uchar
>
(
estimation
[
0
]);
res
[
1
]
=
saturate_cast
<
uchar
>
(
estimation
[
1
]);
return
res
;
}
};
template
<
>
inline
Vec2i
saturateCastFromArray
(
int
*
estimation
)
template
<
typename
IT
>
struct
saturateCastFromArray_
<
Vec3b
,
IT
>
{
estimation
[
1
]
=
0
;
return
Vec2i
(
estimation
);
}
static
inline
Vec3b
f
(
IT
*
estimation
)
{
Vec3b
res
;
res
[
0
]
=
saturate_cast
<
uchar
>
(
estimation
[
0
]);
res
[
1
]
=
saturate_cast
<
uchar
>
(
estimation
[
1
]);
res
[
2
]
=
saturate_cast
<
uchar
>
(
estimation
[
2
]);
return
res
;
}
};
template
<
>
inline
Vec3i
saturateCastFromArray
(
int
*
estimation
)
template
<
typename
T
,
typename
IT
>
static
inline
T
saturateCastFromArray
(
IT
*
estimation
)
{
return
Vec3i
(
estimation
);
return
saturateCastFromArray_
<
T
,
IT
>::
f
(
estimation
);
}
#endif
modules/photo/src/fast_nlmeans_multi_denoising_invoker.hpp
View file @
e178294b
This diff is collapsed.
Click to expand it.
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