diff --git a/src/doc/imagebufalgo.rst b/src/doc/imagebufalgo.rst index cad312fdc8..1e5ed39313 100644 --- a/src/doc/imagebufalgo.rst +++ b/src/doc/imagebufalgo.rst @@ -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 | @@ -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 | @@ -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 .. @@ -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 | diff --git a/src/include/OpenImageIO/imagebufalgo.h b/src/include/OpenImageIO/imagebufalgo.h index ed23b0c683..41b24b2570 100644 --- a/src/include/OpenImageIO/imagebufalgo.h +++ b/src/include/OpenImageIO/imagebufalgo.h @@ -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 diff --git a/testsuite/common/checker_with_alpha.exr b/testsuite/common/checker_with_alpha.exr new file mode 100644 index 0000000000..040f4a872e Binary files /dev/null and b/testsuite/common/checker_with_alpha.exr differ diff --git a/testsuite/common/with_nans.tif b/testsuite/common/with_nans.tif new file mode 100644 index 0000000000..fa0e94a4a2 Binary files /dev/null and b/testsuite/common/with_nans.tif differ diff --git a/testsuite/docs-examples-cpp/ref/out-arm.txt b/testsuite/docs-examples-cpp/ref/out-arm.txt index 151cfff56f..a62547a696 100644 --- a/testsuite/docs-examples-cpp/ref/out-arm.txt +++ b/testsuite/docs-examples-cpp/ref/out-arm.txt @@ -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 @@ -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" diff --git a/testsuite/docs-examples-cpp/ref/out.txt b/testsuite/docs-examples-cpp/ref/out.txt index d6580ec0f4..f220b66aa0 100644 --- a/testsuite/docs-examples-cpp/ref/out.txt +++ b/testsuite/docs-examples-cpp/ref/out.txt @@ -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 @@ -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" diff --git a/testsuite/docs-examples-cpp/run.py b/testsuite/docs-examples-cpp/run.py index c7232d0a36..61badf528b 100755 --- a/testsuite/docs-examples-cpp/run.py +++ b/testsuite/docs-examples-cpp/run.py @@ -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 ;" @@ -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) diff --git a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp index d06bf00ab8..37bc5009e5 100644 --- a/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp +++ b/testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp @@ -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 @@ -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 diff --git a/testsuite/docs-examples-python/ref/out-arm.txt b/testsuite/docs-examples-python/ref/out-arm.txt index e5131d998d..f4bc5eee5d 100644 --- a/testsuite/docs-examples-python/ref/out-arm.txt +++ b/testsuite/docs-examples-python/ref/out-arm.txt @@ -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 @@ -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" diff --git a/testsuite/docs-examples-python/ref/out.txt b/testsuite/docs-examples-python/ref/out.txt index 91f66228a6..ee900dcd5b 100644 --- a/testsuite/docs-examples-python/ref/out.txt +++ b/testsuite/docs-examples-python/ref/out.txt @@ -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 @@ -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" diff --git a/testsuite/docs-examples-python/run.py b/testsuite/docs-examples-python/run.py index 97cd71f6b1..ff2bf18184 100755 --- a/testsuite/docs-examples-python/run.py +++ b/testsuite/docs-examples-python/run.py @@ -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 ;" @@ -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) diff --git a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py index 99d8ea8331..68b48bdbae 100644 --- a/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py +++ b/testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py @@ -512,6 +512,41 @@ def example_div(): # Section: Image enhancement / restoration +def example_fixNonFinite(): + print("example_fixNonFinite") + # BEGIN-imagebufalgo-fixNonFinite + Src = ImageBuf("with_nans.tif") + ImageBufAlgo.fixNonFinite (Src, Src, oiio.NONFINITE_BOX3) + # END-imagebufalgo-fixNonFinite + + # fixing the nans seems nondeterministic - so not writing out the image + # Src.write("with_nans_fixed.tif") + +def example_fillholes_pushpull(): + print("example_fillholes_pushpull") + # BEGIN-imagebufalgo-fillholes_pushpull + Src = ImageBuf("checker_with_alpha.exr") + Filled = ImageBufAlgo.fillholes_pushpull(Src) + # END-imagebufalgo-fillholes_pushpull + Filled.write("checker_with_alpha_filled.exr") + + +def example_median_filter(): + print("example_median_filter") + # BEGIN-imagebufalgo-median_filter + Noisy = ImageBuf("tahoe.tif") + Clean = ImageBufAlgo.median_filter (Noisy, 3, 3) + # END-imagebufalgo-median_filter + Clean.write("tahoe_median_filter.tif") + + +def example_unsharp_mask(): + print("example_unsharp_mask") + # BEGIN-imagebufalgo-unsharp_mask + Blurry = ImageBuf("tahoe.tif") + Sharp = ImageBufAlgo.unsharp_mask (Blurry, "gaussian", 5.0) + # END-imagebufalgo-unsharp_mask + Sharp.write("tahoe_unsharp_mask.tif") # Section: Morphological filters @@ -589,6 +624,10 @@ def example_make_texture(): # Section: Convolution and frequency-space algorithms # Section: Image enhancement / restoration + example_fixNonFinite() + example_fillholes_pushpull() + example_median_filter() + example_unsharp_mask() # Section: Morphological filters