Skip to content

Commit

Permalink
docs: convert to test for ImageBufAlgo Partial Image Arithmetic (#4460)
Browse files Browse the repository at this point in the history
cumentation to testsuite conversion for cpp and python for the
ImageBufAlgo Chapter, Section: Image Arithmetic up to the div function.

The PR also fixes a python testing image file reference in
..docs-examples-python/ref/out.txt, where reference images "simple.tif"
and "scanlines.tif" should have the docs-examples-cpp prefix (see
..docs-examples-python/run.py line 11 for details).

---------

Signed-off-by: Lydia Zheng <[email protected]>
  • Loading branch information
lydia-zheng authored Sep 28, 2024
1 parent 6e62fb4 commit 0391796
Show file tree
Hide file tree
Showing 9 changed files with 409 additions and 153 deletions.
297 changes: 148 additions & 149 deletions src/doc/imagebufalgo.rst

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions testsuite/docs-examples-cpp/ref/out-arm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ example_resize
example_resample
example_fit
example_warp
example_add
example_sub
example_absdiff
example_abs
example_mul
example_div
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -106,6 +112,20 @@ cshift.exr : 256 x 256, 4 channel, half openexr
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
texture.exr : 256 x 256, 3 channel, half openexr (+mipmap)
SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC
add.exr : 256 x 256, 4 channel, half openexr
SHA-1: EA465A4FEA171DDF7D382931AE1FF1E37C4977F8
add-cspan.exr : 256 x 256, 4 channel, half openexr
SHA-1: 3E8E6F104951D3D156891708478193AAE6C5859F
sub.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
absdiff.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
abs.exr : 256 x 256, 4 channel, half openexr
SHA-1: A670546F9AB515ABEC009BFE4C4FF6AF4D628FBA
mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
Comparing "simple.tif" and "ref/simple.tif"
PASS
Comparing "scanlines.tif" and "ref/scanlines.tif"
Expand Down
20 changes: 20 additions & 0 deletions testsuite/docs-examples-cpp/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ example_resize
example_resample
example_fit
example_warp
example_add
example_sub
example_absdiff
example_abs
example_mul
example_div
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -106,6 +112,20 @@ cshift.exr : 256 x 256, 4 channel, half openexr
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
texture.exr : 256 x 256, 3 channel, half openexr (+mipmap)
SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC
add.exr : 256 x 256, 4 channel, half openexr
SHA-1: EA465A4FEA171DDF7D382931AE1FF1E37C4977F8
add-cspan.exr : 256 x 256, 4 channel, half openexr
SHA-1: 3E8E6F104951D3D156891708478193AAE6C5859F
sub.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
absdiff.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
abs.exr : 256 x 256, 4 channel, half openexr
SHA-1: A670546F9AB515ABEC009BFE4C4FF6AF4D628FBA
mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
Comparing "simple.tif" and "ref/simple.tif"
PASS
Comparing "scanlines.tif" and "ref/scanlines.tif"
Expand Down
12 changes: 11 additions & 1 deletion testsuite/docs-examples-cpp/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
# Prep:
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr grid.exr")
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")


# 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 @@ -73,7 +76,14 @@
"transpose.exr",
"reorient.exr",
"cshift.exr",
"texture.exr"
"texture.exr",
"add.exr",
"add-cspan.exr",
"sub.exr",
"absdiff.exr",
"abs.exr",
"mul.exr",
"div.exr"
]
for file in hashes :
command += info_command(file, verbose=False)
Expand Down
85 changes: 85 additions & 0 deletions testsuite/docs-examples-cpp/src/docs-examples-imagebufalgo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,86 @@ void example_warp()


// Section: Image Arithmetic
void example_add()
{
print("example_add\n");
// BEGIN-imagebufalgo-add
// Add images A and B
ImageBuf A ("A.exr");
ImageBuf B ("B.exr");
ImageBuf Sum = ImageBufAlgo::add(A, B);

// Add 0.2 to channels 0-2, but not to channel 3
ImageBuf SumCspan = ImageBufAlgo::add(A, { 0.2f, 0.2f, 0.2f, 0.0f });
// END-imagebufalgo-add
Sum.write("add.exr");
SumCspan.write("add-cspan.exr");
}

void example_sub()
{
print("example_sub\n");
// BEGIN-imagebufalgo-sub
ImageBuf A ("A.exr");
ImageBuf B ("B.exr");
ImageBuf Diff = ImageBufAlgo::sub(A, B);
// END-imagebufalgo-sub
Diff.write("sub.exr");
}

void example_absdiff()
{
print("example_absdiff\n");
// BEGIN-imagebufalgo-absdiff
ImageBuf A ("A.exr");
ImageBuf B ("B.exr");
ImageBuf Diff = ImageBufAlgo::absdiff (A, B);
// END-imagebufalgo-absdiff
Diff.write("absdiff.exr");
}

void example_abs()
{
print("example_abs\n");
// BEGIN-imagebufalgo-absolute
ImageBuf A("grid.exr");
ImageBuf Abs = ImageBufAlgo::abs(A);
// END-imagebufalgo-absolute
Abs.write("abs.exr");
}

void example_mul()
{
print("example_mul\n");
// BEGIN-imagebufalgo-mul
// Pixel-by-pixel, channel-by-channel multiplication of A and B
ImageBuf A ("A.exr");
ImageBuf B ("B.exr");
ImageBuf Product = ImageBufAlgo::mul (A, B);

// In-place reduce intensity of A's channels 0-2 by 50%
ImageBufAlgo::mul (A, A, { 0.5f, 0.5f, 0.5f, 1.0f });
// END-imagebufalgo-mul
Product.write("mul.exr");
}


void example_div()
{
print("example_div\n");
// BEGIN-imagebufalgo-div
// Pixel-by-pixel, channel-by-channel division of A by B
ImageBuf A ("A.exr");
ImageBuf B ("B.exr");
ImageBuf Ratio = ImageBufAlgo::div (A, B);

// In-place reduce intensity of A's channels 0-2 by 50%
ImageBufAlgo::div (A, A, { 2.0f, 2.0f, 2.0f, 1.0f });
// END-imagebufalgo-div
Ratio.write("div.exr");
}

//TODO: mad and onwards

// Section: Image comparison and statistics

Expand Down Expand Up @@ -572,6 +651,12 @@ int main(int /*argc*/, char** /*argv*/)
example_warp();

// Section: Image Arithmetic
example_add();
example_sub();
example_absdiff();
example_abs();
example_mul();
example_div();

// Section: Image comparison and statistics

Expand Down
20 changes: 20 additions & 0 deletions testsuite/docs-examples-python/ref/out-arm.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ example_resize
example_resample
example_fit
example_warp
example_add
example_sub
example_absdiff
example_abs
example_mul
example_div
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -107,6 +113,20 @@ cshift.exr : 256 x 256, 4 channel, half openexr
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
texture.exr : 256 x 256, 3 channel, half openexr (+mipmap)
SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC
add.exr : 256 x 256, 4 channel, half openexr
SHA-1: EA465A4FEA171DDF7D382931AE1FF1E37C4977F8
add_cspan.exr : 256 x 256, 4 channel, half openexr
SHA-1: 3E8E6F104951D3D156891708478193AAE6C5859F
sub.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
absdiff.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
abs.exr : 256 x 256, 4 channel, half openexr
SHA-1: A670546F9AB515ABEC009BFE4C4FF6AF4D628FBA
mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
Comparing "simple.tif" and "../docs-examples-cpp/ref/simple.tif"
PASS
Comparing "scanlines.tif" and "../docs-examples-cpp/ref/scanlines.tif"
Expand Down
20 changes: 20 additions & 0 deletions testsuite/docs-examples-python/ref/out.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ example_resize
example_resample
example_fit
example_warp
example_add
example_sub
example_absdiff
example_abs
example_mul
example_div
example_make_texture
zero1.exr : 512 x 512, 3 channel, half openexr
SHA-1: 95823C334FCE55968E8D2827CCD1CF77CEE19ABD
Expand Down Expand Up @@ -107,6 +113,20 @@ cshift.exr : 256 x 256, 4 channel, half openexr
SHA-1: 000F95FDC44D4DBDA8B4041C2506149C7AE28ACA
texture.exr : 256 x 256, 3 channel, half openexr (+mipmap)
SHA-1: 4074B050432CE7C664CEC4546A46E74F9A310CDC
add.exr : 256 x 256, 4 channel, half openexr
SHA-1: EA465A4FEA171DDF7D382931AE1FF1E37C4977F8
add_cspan.exr : 256 x 256, 4 channel, half openexr
SHA-1: 3E8E6F104951D3D156891708478193AAE6C5859F
sub.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
absdiff.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A521E1D2A632C26E53B83D2CC4B0EDECFC1E68C
abs.exr : 256 x 256, 4 channel, half openexr
SHA-1: A670546F9AB515ABEC009BFE4C4FF6AF4D628FBA
mul.exr : 256 x 256, 4 channel, half openexr
SHA-1: ECCDBBBF088912F0B77B887D6B8B480C3F93615E
div.exr : 256 x 256, 4 channel, half openexr
SHA-1: 6A85C923DB82C893C0D88028386F1C58604A4757
Comparing "simple.tif" and "../docs-examples-cpp/ref/simple.tif"
PASS
Comparing "scanlines.tif" and "../docs-examples-cpp/ref/scanlines.tif"
Expand Down
14 changes: 12 additions & 2 deletions testsuite/docs-examples-python/run.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python

# Copyright Contributors to the OpenImageIO project.
# SPDX-License-Identifier: Apache-2.0
Expand All @@ -13,6 +13,8 @@
# Prep:
command += run_app("cmake -E copy " + test_source_dir + "/../common/grid-small.exr grid.exr")
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")

# 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 @@ -68,7 +70,15 @@
"transpose.exr",
"reorient.exr",
"cshift.exr",
"texture.exr"
"texture.exr",
"add.exr",
"add_cspan.exr",
"sub.exr",
"absdiff.exr",
"abs.exr",
"mul.exr",
"div.exr"

]
for file in hashes :
command += info_command(file, verbose=False)
Expand Down
74 changes: 73 additions & 1 deletion testsuite/docs-examples-python/src/docs-examples-imagebufalgo.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,73 @@ def example_warp():


# Section: Image Arithmetic

def example_add():
print("example_add")
# BEGIN-imagebufalgo-add
# Add images A and B
A = ImageBuf("A.exr")
B = ImageBuf("B.exr")
Sum = ImageBufAlgo.add (A, B)

# Add 0.2 to channels 0-2, but not to channel 3
Sum_cspan = ImageBufAlgo.add (A, (0.2, 0.2, 0.2, 0.0))
# END-imagebufalgo-add
Sum.write("add.exr", "half")
Sum_cspan.write("add_cspan.exr", "half")

def example_sub():
print("example_sub")
# BEGIN-imagebufalgo-sub
A = ImageBuf("A.exr")
B = ImageBuf("B.exr")
Diff = ImageBufAlgo.sub (A, B)
# END-imagebufalgo-sub
Diff.write("sub.exr", "half")

def example_absdiff():
print("example_absdiff")
# BEGIN-imagebufalgo-absdiff
A = ImageBuf("A.exr")
B = ImageBuf("B.exr")
Diff = ImageBufAlgo.absdiff (A, B)
# END-imagebufalgo-absdiff
Diff.write("absdiff.exr", "half")

def example_abs():
print("example_abs")
# BEGIN-imagebufalgo-absolute
A = ImageBuf("grid.exr")
Abs = ImageBufAlgo.abs (A)
# END-imagebufalgo-absolute
Abs.write("abs.exr", "half")

def example_mul():
print("example_mul")
# BEGIN-imagebufalgo-mul
# Pixel-by-pixel, channel-by-channel multiplication of A and B
A = ImageBuf("A.exr")
B = ImageBuf("B.exr")
Product = ImageBufAlgo.mul (A, B)

# In-place reduce intensity of A's channels 0-2 by 50%
ImageBufAlgo.mul (A, A, (0.5, 0.5, 0.5, 1.0))
# END-imagebufalgo-mul
Product.write("mul.exr", "half")

def example_div():
print("example_div")
# BEGIN-imagebufalgo-div
# Pixel-by-pixel, channel-by-channel division of A by B
A = ImageBuf("A.exr")
B = ImageBuf("B.exr")
Ratio = ImageBufAlgo.div (A, B)

# In-place reduce intensity of A's channels 0-2 by 50%
ImageBufAlgo.div (A, A, (2.0, 2.0, 2.0, 1.0))
# END-imagebufalgo-div
Ratio.write("div.exr", "half")

#TODO: mad and onwards

# Section: Image comparison and statistics

Expand Down Expand Up @@ -511,6 +577,12 @@ def example_make_texture():
example_warp()

# Section: Image Arithmetic
example_add()
example_sub()
example_absdiff()
example_abs()
example_mul()
example_div()

# Section: Image comparison and statistics

Expand Down

0 comments on commit 0391796

Please sign in to comment.