예제 #1
0
def test_pnmimage_quantize():
    img = PNMImage(32, 32, 3)

    for x in range(32):
        for y in range(32):
            img.set_xel_val(x, y, randint(0, 100), randint(50, 100), randint(0, 1))

    hist = PNMImage.Histogram()
    img.make_histogram(hist)
    num_colors = hist.get_num_pixels()
    assert num_colors > 100

    img2 = PNMImage(img)
    img2.quantize(100)
    hist = PNMImage.Histogram()
    img2.make_histogram(hist)
    assert hist.get_num_pixels() <= 100

    # Make sure that this is reasonably close
    max_dist = 0
    for x in range(32):
        for y in range(32):
            diff = img.get_xel(x, y) - img2.get_xel(x, y)
            max_dist = max(max_dist, diff.length_squared())

            # Also make sure that they are not out of range of the original
            col = img2.get_xel_val(x, y)
            assert col.r <= 100
            assert col.g >= 50 and col.g <= 100
            assert col.b in (0, 1)

    assert max_dist < 0.1 ** 2
예제 #2
0
def test_pnmimage_add_sub_image():
    dst = PNMImage(2, 2)
    dst.fill(0.5, 0, 0)  #adding color to dst
    #dst_color will store rgb values at each pixel of dst
    dst_color = ((dst.get_xel(0, 0), dst.get_xel(0, 1)), (dst.get_xel(1, 0),
                                                          dst.get_xel(1, 1)))

    src = PNMImage(1, 1)
    src.fill(0, 0.7, 0)  #adding color to src
    #src_color will store rgb values at each pixel of src
    src_color = src.get_xel(0, 0)

    dst.add_sub_image(src, 1, 1, 0, 0, 1, 1)
    final_color = ((dst.get_xel(0, 0), dst.get_xel(0, 1)), (dst.get_xel(1, 0),
                                                            dst.get_xel(1, 1)))
    assert final_color[0][0] == dst_color[0][0]
    assert final_color[0][1] == dst_color[0][1]
    assert final_color[1][0] == dst_color[1][0]
    assert final_color[1][1] == dst_color[1][1] + src_color
예제 #3
0
    def __init__(self):

        # Setup window size, title and so on
        load_prc_file_data("", """
        win-size 1600 900
        window-title Render Pipeline - Benchmark
        """)

        # ------ Begin of render pipeline code ------

        # Insert the pipeline path to the system path, this is required to be
        # able to import the pipeline classes
        pipeline_path = "../../"

        # Just a special case for my development setup, so I don't accidentally
        # commit a wrong path. You can remove this in your own programs.
        if not os.path.isfile(os.path.join(pipeline_path, "setup.py")):
            pipeline_path = "../../RenderPipeline/"

        sys.path.insert(0, pipeline_path)

        from rpcore import RenderPipeline, PointLight
        self.render_pipeline = RenderPipeline()
        self.render_pipeline.create(self)

        # This is a helper class for better camera movement - its not really
        # a rendering element, but it included for convenience
        from rpcore.util.movement_controller import MovementController

        # ------ End of render pipeline code, thats it! ------

        # Set time of day
        self.render_pipeline.daytime_mgr.time = "17:41"

        self.camLens.set_fov(90)

        model = self.loader.load_model("scene/Scene.bam")
        model.reparent_to(self.render)

        model.flatten_strong()
        num_rows = 255

        img = PNMImage("scene/lights.png")

        for x in range(num_rows):
            for y in range(num_rows):
                light = PointLight()
                # light.direction = (0, 0, -1)
                # light.fov = 60
                # light.set_color_from_temperature(randint(2000, 20000))
                light.color = img.get_xel(x * 1, y * 1)
                light.energy = 5000 * (x / num_rows)
                light.pos = Vec3(-(x - num_rows // 2) / num_rows * 1000.0,
                                 (y - num_rows // 2) / num_rows * 1000.0, 2)
                light.radius = 4
                light.inner_radius = 0.5
                light.casts_shadows = False
                light.shadow_map_resolution = 256
                self.render_pipeline.add_light(light)

        self.render_pipeline.prepare_scene(model)

        # Init movement controller
        self.controller = MovementController(self)
        self.controller.set_initial_position(Vec3(0, 450, 200), Vec3(0))
        self.controller.setup()

        self.accept("l", self.benchmark)
            for i, s_nxv in enumerate(reversed(nxv_values)):
                if NxV >= s_nxv:
                    index = i
                    break
            index = len(nxv_values) - index - 1
            next_index = index + 1 if index < dest_size - 1 else index

            curr_nxv = nxv_values[index]
            next_nxv = nxv_values[next_index]

            lerp_factor = (NxV - curr_nxv) / max(1e-10, abs(next_nxv - curr_nxv))
            lerp_factor = max(0.0, min(1.0, lerp_factor))
            indices.append((index, next_index, lerp_factor))

        # Generate the final linear lut using the lerp weights
        for y in xrange(dest_h):
            for x in xrange(dest_size):
                curr_i, next_i, lerp = indices[x]
                curr_v = img.get_xel(curr_i, y)
                next_v = img.get_xel(next_i, y)
                dest.set_xel(x, y, curr_v * (1 - lerp) + next_v * lerp)


        out_name = config["out_name"].replace("{}", str(pass_index))
        dest.write(config["out_dir"] + "/" + out_name)

try:
    os.remove("scene.png")
except:
    pass
예제 #5
0
from __future__ import division, print_function

from panda3d.core import PNMImage, Vec3


def approx(roughness):
    return 1.0 - 0.5 * roughness

for i in range(11):
    r = i / 10.0
    fname = "batch_compare/Gold-R" + str(r) + ".png"

    img = PNMImage(fname)
    # color = (img.get_xel(img.get_x_size() // 2 + 3, img.get_y_size() // 2))
    color = (img.get_xel(256, 47))

    color.x = pow(color.x, 2.2)
    color.y = pow(color.y, 2.2)
    color.z = pow(color.z, 2.2)

    # print(color)

    basecolor = Vec3(1, 0.867136, 0.358654)

    ref_r, apprx_r = color.x, approx(r) * (0.5 + 0.5 * basecolor.x)
    ref_g, apprx_g = color.y, approx(r) * (0.5 + 0.5 * basecolor.y)
    ref_b, apprx_b = color.z, approx(r) * (0.5 + 0.5 * basecolor.z)
    print("Roughness:", r, ", color = ", ref_r, ref_g, ref_b, "vs", apprx_r, apprx_g, apprx_b)
    l = abs(ref_r - apprx_r) + abs(ref_g - apprx_g) + abs(ref_b - apprx_b)
    print("  --> ", l)
from __future__ import division, print_function

from panda3d.core import PNMImage, Vec3


def approx(roughness):
    return 1.0 - 0.5 * roughness


for i in range(11):
    r = i / 10.0
    fname = "batch_compare/Gold-R" + str(r) + ".png"

    img = PNMImage(fname)
    # color = (img.get_xel(img.get_x_size() // 2 + 3, img.get_y_size() // 2))
    color = (img.get_xel(256, 47))

    color.x = pow(color.x, 2.2)
    color.y = pow(color.y, 2.2)
    color.z = pow(color.z, 2.2)

    # print(color)

    basecolor = Vec3(1, 0.867136, 0.358654)

    ref_r, apprx_r = color.x, approx(r) * (0.5 + 0.5 * basecolor.x)
    ref_g, apprx_g = color.y, approx(r) * (0.5 + 0.5 * basecolor.y)
    ref_b, apprx_b = color.z, approx(r) * (0.5 + 0.5 * basecolor.z)
    print("Roughness:", r, ", color = ", ref_r, ref_g, ref_b, "vs", apprx_r,
          apprx_g, apprx_b)
    l = abs(ref_r - apprx_r) + abs(ref_g - apprx_g) + abs(ref_b - apprx_b)
예제 #7
0
write_diff_img = False

img_a = PNMImage(source_a)
img_b = PNMImage(source_b)

w, h = img_a.get_x_size(), img_a.get_y_size()
img_dest = PNMImage(w, h, 3)

error_scale = 10.0

total_diff = 0.0

for x in xrange(w):
    for y in xrange(h):
        val_a = img_a.get_xel(x, y)
        val_b = img_b.get_xel(x, y)

        abs_diff = (val_a - val_b) * error_scale
        r, g, b = abs(abs_diff.x), abs(abs_diff.y), abs(abs_diff.z)

        img_dest.set_xel(x, y, r, g, b)
        total_diff += r + g + b

total_diff /= float(w * h)
total_diff /= error_scale

print("Average difference: ", total_diff, " in RGB: ", total_diff * 255)

img_dest.write("difference.png")
            for i, s_nxv in enumerate(reversed(nxv_values)):
                if NxV >= s_nxv:
                    index = i
                    break
            index = len(nxv_values) - index - 1
            next_index = index + 1 if index < dest_size - 1 else index

            curr_nxv = nxv_values[index]
            next_nxv = nxv_values[next_index]

            lerp_factor = (NxV - curr_nxv) / max(1e-10,
                                                 abs(next_nxv - curr_nxv))
            lerp_factor = max(0.0, min(1.0, lerp_factor))
            indices.append((index, next_index, lerp_factor))

        # Generate the final linear lut using the lerp weights
        for y in xrange(dest_h):
            for x in xrange(dest_size):
                curr_i, next_i, lerp = indices[x]
                curr_v = img.get_xel(curr_i, y)
                next_v = img.get_xel(next_i, y)
                dest.set_xel(x, y, curr_v * (1 - lerp) + next_v * lerp)

        out_name = config["out_name"].replace("{}", str(pass_index))
        dest.write(config["out_dir"] + "/" + out_name)

try:
    os.remove("scene.png")
except:
    pass
예제 #9
0
from __future__ import division, print_function
def approx(roughness):
    alpha = roughness * roughness
    return 1.0 - 0.5 * roughness
from panda3d.core import PNMImage, Vec3
import os
for i in range(11):
    r = i / 10.0
    fname = "batch_compare/Gold-R" + str(r) + ".png"
    img = PNMImage(fname)
    # color = (img.get_xel(img.get_x_size() // 2 + 3, img.get_y_size() // 2))
    color = (img.get_xel(256, 47))
    color.x = pow(color.x, 2.2)
    color.y = pow(color.y, 2.2)
    color.z = pow(color.z, 2.2)
    # print(color)
    basecolor = Vec3(1, 0.867136, 0.358654)
    ref_r, apprx_r = color.x, approx(r) * (0.5 + 0.5 * basecolor.x)
    ref_g, apprx_g = color.y, approx(r) * (0.5 + 0.5 * basecolor.y)
    ref_b, apprx_b = color.z, approx(r) * (0.5 + 0.5 * basecolor.z)
    print("Roughness:", r, ", color = ", ref_r, ref_g, ref_b, "vs", apprx_r, apprx_g, apprx_b)
    l = abs(ref_r - apprx_r) + abs(ref_g - apprx_g) + abs(ref_b - apprx_b)
    print("  --> ", l)
    # print("Roughness:", r, ", color = ", ref, "vs", apprx, " =\t", abs(ref - apprx) * 100.0)
예제 #10
0
write_diff_img = False

img_a = PNMImage(source_a)
img_b = PNMImage(source_b)

w, h = img_a.get_x_size(), img_a.get_y_size()
img_dest = PNMImage(w, h, 3)

error_scale = 10.0

total_diff = 0.0

for x in xrange(w):
    for y in xrange(h):
        val_a = img_a.get_xel(x, y)
        val_b = img_b.get_xel(x, y)

        abs_diff = (val_a - val_b) * error_scale
        r, g, b = abs(abs_diff.x), abs(abs_diff.y), abs(abs_diff.z)

        img_dest.set_xel(x, y, r, g, b)
        total_diff += r + g + b

total_diff /= float(w * h)
total_diff /= error_scale

print("Average difference: ", total_diff, " in RGB: ", total_diff * 255)

img_dest.write("difference.png")