Example #1
0
    def test_single_image_correct_size(self):
        grid = figuregen.Grid(1, 1)

        img_blue = np.tile([x / 255 for x in colors[2]], (32, 64, 1))
        grid[0, 0].image = figuregen.PNG(img_blue)

        backend = TikzBackend()
        sz = backend.compute_aligned_sizes([grid], 13)

        self.assertAlmostEqual(sz[0][0].width_mm, 13)
        self.assertAlmostEqual(sz[0][0].height_mm, 13 / 2)

        self.assertAlmostEqual(sz[0][1].width_mm, 13)
        self.assertAlmostEqual(sz[0][1].height_mm, 13 / 2)
Example #2
0
    def test_image_with_title_correct_pos(self):
        grid = figuregen.Grid(1, 1)

        img_blue = np.tile([x / 255 for x in colors[2]], (32, 64, 1))
        grid[0, 0].image = figuregen.PNG(img_blue)

        grid.set_col_titles("top", ["hi there"])
        grid.layout.set_col_titles("top", 5, 0.5)

        backend = TikzBackend()
        sz = backend.compute_aligned_sizes([grid], 13)

        # grid size should include title
        self.assertAlmostEqual(sz[0][0].width_mm, 13)
        self.assertAlmostEqual(sz[0][0].height_mm, 13 / 2 + 5.5)

        # image size should be same as without title
        self.assertAlmostEqual(sz[0][1].width_mm, 13)
        self.assertAlmostEqual(sz[0][1].height_mm, 13 / 2)

        imgpos = calc.image_pos(grid, sz[0][1], 0, 0)
        self.assertAlmostEqual(imgpos[0], 5.5)
        self.assertAlmostEqual(imgpos[1], 0)
Example #3
0
import figuregen
import numpy as np
import single_module

# generate test images
blue = np.tile([0.2, 0.3, 0.9], (32, 32, 1))
yellow = np.tile([0.9, 0.8, 0.2], (32, 32, 1))

# load the two images
images = [figuregen.PNG(blue), figuregen.PNG(yellow)]

# ---- Grid Module ----
grid0 = figuregen.Grid(1, 1)
grid0.get_layout().set_padding(right=0.5)
e0 = grid0.get_element(0, 0).set_image(images[1])
e0.set_frame(0.3, [0, 0, 0])
e0.set_marker(pos=[2, 12],
              size=[10, 10],
              color=[155, 155, 155],
              linewidth_pt=0.6)
e0.set_marker(pos=[15, 1],
              size=[10, 15],
              color=[186, 98, 82],
              linewidth_pt=0.6)

# ---- Grid Module ----
grid1 = figuregen.Grid(2, 2)
layout1 = grid1.get_layout()
layout1.set_padding(top=0.2, right=0.5)

# fill grid with image data
Example #4
0
            rmin = y[i]

    return (ddx, ddy)


def get_plot_data(scene, method_list):
    return [
        load_error(scene, method, metric='MRSE*', clip=True)
        for method in method_list[:-1]
    ]


# ---------- REFERENCE Module ----------
ref_grid = figuregen.Grid(1, 1)
ref_img = get_image(scene[idx], seconds[idx])
reference = ref_grid.get_element(0, 0).set_image(figuregen.PNG(ref_img))

# marker
for crop in crops[idx]:
    reference.set_marker(pos=crop.get_marker_pos(),
                         size=crop.get_marker_size(),
                         color=[242, 113, 0],
                         linewidth_pt=0.6)
# titles
ref_grid.set_title('south', scene[idx].replace('-', ' ').title())

# layout
ref_layout = ref_grid.get_layout().set_padding(bottom=0.1, right=0.5)
ref_layout.set_title('south', field_size_mm=7., offset_mm=0.5, fontsize=8)

# ---------- COMPARE Module ----------
Example #5
0
import figuregen
import os
import numpy as np
import vertical_stack

# Note: LaTeX and PPTX-backend do not support html files
# if test_html is True, we only generate the figure with the html backend
test_html = False

# PNG test
blue = [82, 110, 186]
img_blue = np.tile([x / 255 for x in blue], (32, 32, 1))
img_png = figuregen.PNG(img_blue)

if test_html:
    # HTML test
    figuregen.figure(vertical_stack.v_grids,
                     width_cm=15.,
                     filename='v-stacked.html')
    htmlfile = os.path.abspath('v-stacked.html')
    img_test = figuregen.HTML(htmlfile, aspect_ratio=0.3)
else:
    # PDF test
    figuregen.figure(vertical_stack.v_grids,
                     width_cm=15.,
                     filename='v-stacked.pdf')
    pdffile = os.path.abspath('v-stacked.pdf')
    img_test = figuregen.PDF(pdffile)

images = [
    img_test,
Example #6
0
              image.SplitImage([img_yellow, img_l_blue, img_blue],
                               vertical=False,
                               weights=[1, 2, 3],
                               degree=0),
          ]]

# ---------- Simple Grid with SplitImages ----------
n_rows = 2
top_cols = 2
top_grid = figuregen.Grid(num_rows=n_rows, num_cols=top_cols)

# fill grid with image data
for row in range(n_rows):
    for col in range(top_cols):
        s_img = images[row][col]
        raw_img = figuregen.PNG(s_img.get_image())
        e = top_grid.get_element(row, col).set_image(raw_img)
        e.draw_lines(s_img.get_start_positions(),
                     s_img.get_end_positions(),
                     linewidth_pt=0.5,
                     color=[0, 0, 0])

top_grid.set_col_titles('top',
                        ['Horizontal Split', 'Vertical Split', 'C)', 'D)'])

# LAYOUT: Specify paddings (unit: mm)
top_lay = top_grid.get_layout()
top_lay.set_padding(column=1.0, right=1.5)
top_lay.set_col_titles('top', field_size_mm=5.0)

if __name__ == "__main__":
Example #7
0
import figuregen
import numpy as np

img_blue = np.tile([x / 255 for x in [94, 163, 188]], (32, 64, 1))
img_yellow = np.tile([x / 255 for x in [232, 181, 88]], (32, 64, 1))

grid = figuregen.Grid(1, 2)
grid[0, 0].set_image(figuregen.JPEG(img_blue))
grid[0, 1].set_image(figuregen.JPEG(img_yellow))

figuregen.horizontal_figure([grid], 8, "jpeg_export.pdf")
figuregen.horizontal_figure([grid], 8, "jpeg_export.pptx")
figuregen.horizontal_figure([grid], 8, "jpeg_export.html")

grid = figuregen.Grid(1, 2)
grid[0, 0].set_image(figuregen.PNG(img_blue))
grid[0, 1].set_image(figuregen.PNG(img_yellow))

figuregen.horizontal_figure([grid], 8, "png_export.pdf")
figuregen.horizontal_figure([grid], 8, "png_export.pptx")
figuregen.horizontal_figure([grid], 8, "png_export.html")
Example #8
0
# generate test images
img_blue = np.tile([x / 255 for x in colors[2]], (32, 64, 1))
img_yellow = np.tile([x / 255 for x in colors[0]], (32, 64, 1))

# load the two images
images = [img_blue, img_yellow]

# ------ Create Grid including markers, frames, (sub)titles, labels, etc. -------
n_rows, n_cols = 2, 3
grid = figuregen.Grid(n_rows, n_cols)

# fill grid with image data
for row in range(n_rows):
    for col in range(n_cols):
        img = figuregen.PNG(images[row])
        grid.get_element(row, col).set_image(img)

layout = grid.get_layout()
layout.set_padding(top=0.5, bottom=1.5)

# marker
grid.get_element(0, 0).set_marker(pos=[32, 12], size=[15, 10], color=colors[4])
grid.get_element(0, 0).set_marker(pos=[1, 1],
                                  size=[15, 10],
                                  color=colors[-1],
                                  linewidth_pt=0.9,
                                  is_dashed=True)

# frame
grid.get_element(0, 1).set_frame(linewidth=2., color=colors[4])
Example #9
0
def make_figure(frame: FrameData, title=True, add_placeholder=True):
    # Define the cropping area of the raw tech zoom-ins
    half_width = int(frame.method_images[0].shape[1] / 2)
    height = frame.method_images[0].shape[0]
    tech_crop_left = util.image.Cropbox(top=0,
                                        left=0,
                                        width=half_width,
                                        height=height,
                                        scale=1)
    tech_crop_right = util.image.Cropbox(top=0,
                                         left=half_width,
                                         width=half_width,
                                         height=height,
                                         scale=1)

    # Define the cropping areas (one half of the image each)
    third_width = int(frame.method_images[0].shape[1] / 3)
    left_crop = util.image.Cropbox(top=0,
                                   left=0,
                                   width=third_width,
                                   height=height,
                                   scale=1)
    center_crop = util.image.Cropbox(top=0,
                                     left=third_width,
                                     width=third_width,
                                     height=height,
                                     scale=1)
    right_crop = util.image.Cropbox(top=0,
                                    left=2 * third_width,
                                    width=third_width,
                                    height=height,
                                    scale=1)

    renderings = figuregen.Grid(1, 3)
    if title:
        renderings.set_title("top", "(c) MIS combinations")
        renderings.set_col_titles("top", [
            f'{frame.methods[0][0]}',
            f'{frame.methods[1][0]}',
            f'{frame.methods[2][0]}',
        ])
    renderings.set_col_titles("bottom", [
        f"${frame.errors[0]:.3f}$",
        f"${frame.errors[1]:.3f}$",
        f"${frame.errors[2]:.3f}$",
    ])
    left = renderings[0, 0]
    left.set_image(tonemap(left_crop.crop(frame.method_images[0])))
    center = renderings[0, 1]
    center.set_image(tonemap(center_crop.crop(frame.method_images[1])))
    right = renderings[0, 2]
    right.set_image(tonemap(right_crop.crop(frame.method_images[2])))

    weights = figuregen.Grid(1, 3)

    if title:
        weights.set_col_titles("top", [
            f"{frame.methods[0][0]}", f"{frame.methods[1][0]}",
            f"{frame.methods[2][0]}"
        ])
        weights.set_title("top", "(d) MIS weights")

    # Compute the MIS weight images
    left = weights[0, 0]
    w, m = compute_weight(frame, 0, 0, 0)
    w = 1 - w
    m1 = 1 - m
    left.set_image(figuregen.JPEG(colormap(left_crop.crop(w)), quality=80))

    center = weights[0, 1]
    w, m = compute_weight(frame, 1, 0, 0)
    w = 1 - w
    m2 = 1 - m
    center.set_image(figuregen.JPEG(colormap(center_crop.crop(w)), quality=80))

    right = weights[0, 2]
    w, m = compute_weight(frame, 2, 0, 0)
    w = 1 - w
    m3 = 1 - m
    right.set_image(figuregen.JPEG(colormap(right_crop.crop(w)), quality=80))

    weights.set_col_titles("bottom",
                           [f"avg.: ${m1:.2f}$", f"${m2:.2f}$", f"${m3:.2f}$"])

    # Add a simple color bar
    cbar = figuregen.Grid(1, 1)
    cbar[0, 0].set_image(figuregen.PNG(colorbar()))

    # Show crops of the raw technique results
    techs_grid = figuregen.Grid(1, 2)
    t2 = techs_grid[0, 0]
    t2.set_image(
        tonemap(tech_crop_left.crop(frame.raw_technique_images[1][0][0])))
    t1 = techs_grid[0, 1]
    t1.set_image(
        tonemap(tech_crop_right.crop(frame.raw_technique_images[1][0][1])))
    t2.set_frame(1, color=[0, 113, 188])
    t1.set_frame(1, color=[175, 10, 38])

    tech_error = [
        util.image.relative_mse(frame.raw_technique_images[1][0][0],
                                frame.raw_technique_images[0][0][0]),
        util.image.relative_mse(frame.raw_technique_images[1][0][1],
                                frame.raw_technique_images[0][0][0]),
    ]

    techs_grid.set_col_titles("bottom", [
        f"relMSE: ${tech_error[0]:.2f}$",
        f"${tech_error[1]:.2f} \\,({tech_error[1]/tech_error[0]:.2f}\\times)$",
    ])

    if title:
        techs_grid.set_col_titles(
            "top", ["Merge at $\\mathbf{x}_1$", "Merge at $\\mathbf{x}_2$"])
        techs_grid.set_title("top", "(b) Individual techniques")

    # placeholder for illustrations
    placeholder = figuregen.Grid(1, 1)
    placeholder[0, 0].set_image(
        figuregen.PNG(
            util.image.lin_to_srgb(np.tile(np.array([1, 1, 1]), (7, 2)))))
    if title:
        placeholder.set_title("top", "(a) Scene layout")

    # define the layout
    renderings.layout.set_col_titles("bottom", 2.8, offset_mm=0.5, fontsize=8)
    renderings.layout.set_padding(right=2.0, column=0.5)
    if title:
        renderings.layout.set_col_titles("top", 2.8, fontsize=8, offset_mm=0.0)
        renderings.layout.set_title("top", 2.8, fontsize=8, offset_mm=0.5)

    # align all other modules
    weights.copy_layout(renderings)
    cbar.copy_layout(renderings)
    techs_grid.copy_layout(renderings)
    placeholder.copy_layout(renderings)

    # Add extra paddings
    weights.layout.set_padding(right=0.5)
    cbar.layout.set_padding(right=4)

    if add_placeholder:
        return [placeholder, techs_grid, renderings, weights, cbar]
    else:
        return [techs_grid, renderings, weights, cbar]
Example #10
0
                      height_mm=2.5,
                      offset_mm=[0.4, 0.4],
                      fontsize=6,
                      bg_color=[20, 20, 20],
                      txt_color=[255, 255, 255],
                      txt_padding_mm=0.2)


# ---------- Horizontal Figure TOP ----------
top_cols = len(method_filenames)
top_grid = figuregen.Grid(num_rows=1, num_cols=top_cols)

# fill grid with image data
for col in range(top_cols):
    e = top_grid.get_element(0, col)
    e.set_image(figuregen.PNG(get_image(method_filenames[col])))

    if col == 0:  # reference
        place_label(e, txt='relMSE')
    else:  # Method
        rmse = get_error(method_filenames[col])
        place_label(e, txt=rmse)

    # Add markers for all crops
    c_idx = 0
    for c in crops:
        e.set_marker(c.get_marker_pos(),
                     c.get_marker_size(),
                     color=crop_colors[c_idx],
                     linewidth_pt=0.5)
        c_idx += 1