Skip to content

Commit c1031da

Browse files
committed
Add OpenCV NlMeans denoise example
1 parent 9d1344e commit c1031da

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
========================================
2+
Fast Non-Local Means Denoise with OpenCV
3+
========================================
4+
5+
In this example we will use a denoise algorithm defined in an `external libray`_: OpenCV.
6+
7+
This method progressively scans neighborhoods of an image looking for repeated search template. These
8+
repeated areas can then be averaged to eliminate gaussian noise, without the requirement of additional
9+
images for comparison.
10+
11+
Sample data can be found in the `images folder`_.
12+
13+
SciJava Ops via Fiji's sripting engine with `script parameters`_:
14+
15+
.. tabs::
16+
17+
.. code-tab:: groovy
18+
#@ ImgPlus img
19+
#@ Integer (label="strength:", value=4.0) strength
20+
#@ Integer (label="template size:", value=7) template
21+
#@ Integer (label="search size:", value=21) search
22+
#@output ImgPlus result
23+
24+
import org.scijava.ops.api.OpEnvironment;
25+
import net.imglib2.type.numeric.integer.UnsignedByteType;
26+
27+
// build the Ops environment
28+
ops = OpEnvironment.build();
29+
30+
// Get the min and max values of our input image
31+
oldMin = ops.unary("stats.min").input(img).apply();
32+
oldMax = ops.unary("stats.max").input(img).apply();
33+
34+
// We need to convert to 8-bit since not all data types are currently supported in OpenCV
35+
var type = new UnsignedByteType(100);
36+
var img8bit = ops.binary("create.img").input(img, type).apply();
37+
38+
// Normalize our input data to the 8-bit min/max
39+
newMin = new UnsignedByteType((int)type.getMinValue());
40+
newMax = new UnsignedByteType((int)type.getMaxValue());
41+
42+
ops.op("image.normalize").arity5().input(img, oldMin, oldMax, newMin, newMax).output(img8bit).compute()
43+
44+
// Create a container for the denoise output
45+
result = img8bit.copy()
46+
47+
// Run the denoise op
48+
ops.quaternary("filter.denoise").input(img8bit, strength, template, search).output(result).compute();
49+
.. _`script parameters`: https://imagej.net/scripting/parameters
50+
.. _`external libray`: https://docs.opencv.org/4.x/d5/d69/tutorial_py_non_local_means.html
51+
.. _`images folder`: https://github.com/scijava/incubator/tree/main/docs/ops/images/sample_16bit_T24.png

docs/ops/doc/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ The combination of these libraries allows declarative image analysis workflows,
3030
:caption: ⚙️ Examples
3131

3232
examples/example_gaussian_subtraction
33+
examples/opencv_denoise
3334

3435
.. toctree::
3536
:maxdepth: 2

0 commit comments

Comments
 (0)