Skip to content

Commit

Permalink
docs: convert docs -> examples for image enhancement and restoration …
Browse files Browse the repository at this point in the history
…section (#4458)

Further work towards #3992

Signed-off-by: Daniel Greenstein <[email protected]>
  • Loading branch information
grdanny authored Oct 2, 2024
1 parent 765c8ed commit 1be693b
Show file tree
Hide file tree
Showing 12 changed files with 217 additions and 49 deletions.
108 changes: 64 additions & 44 deletions src/doc/imagebufalgo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2535,24 +2535,27 @@ Image Enhancement / Restoration

Examples:

.. tabs::

.. code-tab:: c++
.. tabs::

ImageBuf Src ("tahoe.exr");
int pixelsFixed = 0;
ImageBufAlgo::fixNonFinite (Src, Src, ImageBufAlgo::NONFINITE_BOX3,
&pixelsFixed);
std::cout << "Repaired " << pixelsFixed << " non-finite pixels\n";
.. tab:: C++
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
:language: c++
:start-after: BEGIN-imagebufalgo-fixNonFinite
:end-before: END-imagebufalgo-fixNonFinite
:dedent: 4

.. code-tab:: py
.. tab:: Python
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
:language: py
:start-after: BEGIN-imagebufalgo-fixNonFinite
:end-before: END-imagebufalgo-fixNonFinite
:dedent: 4

Src = ImageBuf("tahoe.exr")
ImageBufAlgo.fixNonFinite (Src, Src, "box3", oiio.NONFINITE_BOX3)
.. tab:: oiiotool
.. sourcecode:: bash

.. code-tab:: bash oiiotool
oiiotool with_nans.tif --fixnan box3 -o with_nans_fixed.tif

oiiotool tahoe.exr --fixnan box3 -o fixed.exr

|
Expand All @@ -2564,21 +2567,27 @@ Image Enhancement / Restoration

Examples:

.. tabs::

.. code-tab:: c++

ImageBuf Src ("holes.exr");
ImageBuf Filled = ImageBufAlgo::fillholes_pushpull (Src);
.. tabs::

.. code-tab:: py
.. tab:: C++
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
:language: c++
:start-after: BEGIN-imagebufalgo-fillholes_pushpull
:end-before: END-imagebufalgo-fillholes_pushpull
:dedent: 4

Src = ImageBuf("holes.exr")
Filled = ImageBufAlgo.fillholes_pushpull (Src)
.. tab:: Python
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
:language: py
:start-after: BEGIN-imagebufalgo-fillholes_pushpull
:end-before: END-imagebufalgo-fillholes_pushpull
:dedent: 4

.. code-tab:: bash oiiotool
.. tab:: oiiotool
.. sourcecode:: bash

oiiotool holes.exr --fillholes -o filled.exr
oiiotool checker_with_alpha.exr --fillholes -o checker_with_alpha_filled.exr

|
Expand All @@ -2590,21 +2599,27 @@ Image Enhancement / Restoration

Examples:

.. tabs::

.. code-tab:: c++

ImageBuf Noisy ("tahoe.exr");
ImageBuf Clean = ImageBufAlgo::median_filter (Noisy, 3, 3);
.. tabs::

.. code-tab:: py
.. tab:: C++
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
:language: c++
:start-after: BEGIN-imagebufalgo-median_filter
:end-before: END-imagebufalgo-median_filter
:dedent: 4

Noisy = ImageBuf("tahoe.exr")
Clean = ImageBufAlgo.median_filter (Noisy, 3, 3)
.. tab:: Python
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
:language: py
:start-after: BEGIN-imagebufalgo-median_filter
:end-before: END-imagebufalgo-median_filter
:dedent: 4

.. code-tab:: bash oiiotool
.. tab:: oiiotool
.. sourcecode:: bash

oiiotool tahoe.exr --median 3x3 -o clean.exr
oiiotool tahoe.tif --median 3x3 -o tahoe_median_filter.tif

..
Expand Down Expand Up @@ -2633,21 +2648,26 @@ Image Enhancement / Restoration

Examples:

.. tabs::

.. code-tab:: c++

ImageBuf Blurry ("tahoe.exr");
ImageBuf Sharp = ImageBufAlgo::unsharp_mask (Blurry, "gaussian", 5.0f);
.. tabs::

.. code-tab:: py
.. tab:: C++
.. literalinclude:: ../../testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
:language: c++
:start-after: BEGIN-imagebufalgo-unsharp_mask
:end-before: END-imagebufalgo-unsharp_mask
:dedent: 4

Blurry ImageBuf("tahoe.exr")
Sharp = ImageBufAlgo.unsharp_mask (Blurry, "gaussian", 5.0)
.. tab:: Python
.. literalinclude:: ../../testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
:language: py
:start-after: BEGIN-imagebufalgo-unsharp_mask
:end-before: END-imagebufalgo-unsharp_mask
:dedent: 4

.. code-tab:: bash oiiotool
.. tab:: oiiotool
.. sourcecode:: bash

oiiotool tahoe.exr --unsharp:kernel=gaussian:width=5 -o sharp.exr
oiiotool tahoe.tif --unsharp:kernel=gaussian:width=5 -o tahoe_unsharp_mask.tif

|
Expand Down
2 changes: 1 addition & 1 deletion src/include/OpenImageIO/imagebufalgo.h
Original file line number Diff line number Diff line change
Expand Up @@ -1693,7 +1693,7 @@ enum NonFiniteFixMode
///< values, if any nonfinite values are found.
};

/// `fixNonFinite()` returns in image containing the values of `src` (within
/// `fixNonFinite()` returns an image containing the values of `src` (within
/// the ROI), while repairing any non-finite (NaN/Inf) pixels. If
/// `pixelsFixed` is not nullptr, store in it the number of pixels that
/// contained non-finite value. It is permissible to operate in-place (with
Expand Down
Binary file added testsuite/common/checker_with_alpha.exr
Binary file not shown.
Binary file added testsuite/common/with_nans.tif
Binary file not shown.
11 changes: 11 additions & 0 deletions testsuite/docs-examples-cpp/ref/out-arm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ example_absdiff
example_abs
example_mul
example_div
example_fixNonFinite
Repaired 48 non-finite pixels
example_fillholes_pushpull
example_median_filter
example_unsharp_mask
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -126,6 +131,12 @@ mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
checker_with_alpha_filled.exr : 256 x 256, 4 channel, half openexr
SHA-1: B245E027638D5C1BA2608FEDDB3BB9B5E9FA3A44
tahoe_median_filter.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: A0B2E3A10A16EA8CC905F144C5F91B6A0964A177
tahoe_unsharp_mask.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: CDE3FAC8053381C59B7BEB3B47991F357E14D9D2
Comparing "simple.tif" and "ref/simple.tif"
PASS
Comparing "scanlines.tif" and "ref/scanlines.tif"
Expand Down
11 changes: 11 additions & 0 deletions testsuite/docs-examples-cpp/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ example_absdiff
example_abs
example_mul
example_div
example_fixNonFinite
Repaired 48 non-finite pixels
example_fillholes_pushpull
example_median_filter
example_unsharp_mask
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -126,6 +131,12 @@ mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
checker_with_alpha_filled.exr : 256 x 256, 4 channel, half openexr
SHA-1: B245E027638D5C1BA2608FEDDB3BB9B5E9FA3A44
tahoe_median_filter.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: A0B2E3A10A16EA8CC905F144C5F91B6A0964A177
tahoe_unsharp_mask.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: D3B56074F48EC5D3ADDA4BDE1F487192ABE9BA76
Comparing "simple.tif" and "ref/simple.tif"
PASS
Comparing "scanlines.tif" and "ref/scanlines.tif"
Expand Down
8 changes: 6 additions & 2 deletions testsuite/docs-examples-cpp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
command += run_app("cmake -E copy " + test_source_dir + "/../common/tahoe-small.tif tahoe.tif")
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr A.exr")
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr B.exr")

command += run_app("cmake -E copy " + test_source_dir + "/../common/with_nans.tif with_nans.tif")
command += run_app("cmake -E copy " + test_source_dir + "/../common/checker_with_alpha.exr checker_with_alpha.exr")

# Copy the grid to both a tiled and scanline version
command += oiio_app("iconvert") + "../common/grid.tif --scanline scanline.tif > out.txt ;"
Expand Down Expand Up @@ -83,7 +84,10 @@
"absdiff.exr",
"abs.exr",
"mul.exr",
"div.exr"
"div.exr",
"checker_with_alpha_filled.exr",
"tahoe_median_filter.tif",
"tahoe_unsharp_mask.tif"
]
for file in hashes :
command += info_command(file, verbose=False)
Expand Down
59 changes: 59 additions & 0 deletions testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,60 @@ void example_div()

// Section: Image enhancement / restoration

void example_fixNonFinite()
{
print("example_fixNonFinite\n");
// BEGIN-imagebufalgo-fixNonFinite
ImageBuf Src ("with_nans.tif");
int pixelsFixed = 0;
ImageBufAlgo::fixNonFinite (Src, Src, ImageBufAlgo::NONFINITE_BOX3,
&pixelsFixed);
std::cout << "Repaired " << pixelsFixed << " non-finite pixels\n";
// END-imagebufalgo-fixNonFinite

// fixing the nans seems nondeterministic - so not writing out the image
// Src.write("with_nans_fixed.tif");

}


void example_fillholes_pushpull()
{
print("example_fillholes_pushpull\n");
// BEGIN-imagebufalgo-fillholes_pushpull

ImageBuf Src ("checker_with_alpha.exr");
ImageBuf Filled = ImageBufAlgo::fillholes_pushpull (Src);

// END-imagebufalgo-fillholes_pushpull
Filled.write("checker_with_alpha_filled.exr");

}


void example_median_filter()
{
print("example_median_filter\n");
// BEGIN-imagebufalgo-median_filter
ImageBuf Noisy ("tahoe.tif");
ImageBuf Clean = ImageBufAlgo::median_filter (Noisy, 3, 3);
// END-imagebufalgo-median_filter
Clean.write("tahoe_median_filter.tif");

}


void example_unsharp_mask()
{
print("example_unsharp_mask\n");
// BEGIN-imagebufalgo-unsharp_mask
ImageBuf Blurry ("tahoe.tif");
ImageBuf Sharp = ImageBufAlgo::unsharp_mask (Blurry, "gaussian", 5.0f);
// END-imagebufalgo-unsharp_mask
Sharp.write("tahoe_unsharp_mask.tif");

}


// Section: Morphological filters

Expand Down Expand Up @@ -664,6 +718,11 @@ int main(int /*argc*/, char** /*argv*/)

// Section: Image enhancement / restoration

example_fixNonFinite();
example_fillholes_pushpull();
example_median_filter();
example_unsharp_mask();

// Section: Morphological filters

// Section: Color space conversion
Expand Down
10 changes: 10 additions & 0 deletions testsuite/docs-examples-python/ref/out-arm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ example_absdiff
example_abs
example_mul
example_div
example_fixNonFinite
example_fillholes_pushpull
example_median_filter
example_unsharp_mask
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -127,6 +131,12 @@ mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
checker_with_alpha_filled.exr : 256 x 256, 4 channel, half openexr
SHA-1: B245E027638D5C1BA2608FEDDB3BB9B5E9FA3A44
tahoe_median_filter.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: A0B2E3A10A16EA8CC905F144C5F91B6A0964A177
tahoe_unsharp_mask.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: CDE3FAC8053381C59B7BEB3B47991F357E14D9D2
Comparing "simple.tif" and "../docs-examples-cpp/ref/simple.tif"
PASS
Comparing "scanlines.tif" and "../docs-examples-cpp/ref/scanlines.tif"
Expand Down
10 changes: 10 additions & 0 deletions testsuite/docs-examples-python/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ example_absdiff
example_abs
example_mul
example_div
example_fixNonFinite
example_fillholes_pushpull
example_median_filter
example_unsharp_mask
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -127,6 +131,12 @@ mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
checker_with_alpha_filled.exr : 256 x 256, 4 channel, half openexr
SHA-1: B245E027638D5C1BA2608FEDDB3BB9B5E9FA3A44
tahoe_median_filter.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: A0B2E3A10A16EA8CC905F144C5F91B6A0964A177
tahoe_unsharp_mask.tif : 512 x 384, 3 channel, uint8 tiff
SHA-1: D3B56074F48EC5D3ADDA4BDE1F487192ABE9BA76
Comparing "simple.tif" and "../docs-examples-cpp/ref/simple.tif"
PASS
Comparing "scanlines.tif" and "../docs-examples-cpp/ref/scanlines.tif"
Expand Down
8 changes: 6 additions & 2 deletions testsuite/docs-examples-python/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
command += run_app("cmake -E copy " + test_source_dir + "/../common/tahoe-small.tif tahoe.tif")
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr A.exr")
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr B.exr")
command += run_app("cmake -E copy " + test_source_dir + "/../common/with_nans.tif with_nans.tif")
command += run_app("cmake -E copy " + test_source_dir + "/../common/checker_with_alpha.exr checker_with_alpha.exr")

# Copy the grid to both a tiled and scanline version
command += oiio_app("iconvert") + "../common/grid.tif --scanline scanline.tif > out.txt ;"
Expand Down Expand Up @@ -77,8 +79,10 @@
"absdiff.exr",
"abs.exr",
"mul.exr",
"div.exr"

"div.exr",
"checker_with_alpha_filled.exr",
"tahoe_median_filter.tif",
"tahoe_unsharp_mask.tif"
]
for file in hashes :
command += info_command(file, verbose=False)
Expand Down
Loading

0 comments on commit 1be693b

Please sign in to comment.