|
| 1 | +from deepbench.image import SkyImage, ShapeImage |
| 2 | +from deepbench.physics_object import HamiltonianPendulum, Pendulum |
| 3 | +import matplotlib.pyplot as plt |
| 4 | +import numpy as np |
| 5 | + |
| 6 | + |
| 7 | +# Each image is 480,480 |
| 8 | +image_shape = (480, 480) |
| 9 | + |
| 10 | +# Total images N and figure size |
| 11 | +fig, subplots = plt.subplots(2, 4, figsize=(12, 6)) |
| 12 | + |
| 13 | +# Center of all images is at 480/2, 480/2 |
| 14 | +center = image_shape[0] / 2 |
| 15 | + |
| 16 | + |
| 17 | +# Parameters for each ellipse |
| 18 | +ellipse_params = { |
| 19 | + "center": (center, center), |
| 20 | + "width": 100, |
| 21 | + "height": 200, |
| 22 | + "fill": True, |
| 23 | + "angle": 30, |
| 24 | +} |
| 25 | +shape_single = ShapeImage(image_shape, object_noise_level=0.0) |
| 26 | +single_shape_noiseless = shape_single.combine_objects( |
| 27 | + ["ellipse"], object_params=[ellipse_params] |
| 28 | +) |
| 29 | + |
| 30 | +subplots[0, 0].imshow(single_shape_noiseless) |
| 31 | + |
| 32 | +# Use the same parameters to make an ellipse with noise |
| 33 | +shape_single = ShapeImage(image_shape, object_noise_level=0.4) |
| 34 | +shape_single_noisy = shape_single.combine_objects( |
| 35 | + ["ellipse"], object_params=[ellipse_params] |
| 36 | +) |
| 37 | + |
| 38 | +subplots[0, 1].imshow(shape_single_noisy) |
| 39 | + |
| 40 | +# Produce a rectangle with specified line widths |
| 41 | +line_params = { |
| 42 | + "center": (center + int(center / 2), center), |
| 43 | + "width": 120, |
| 44 | + "height": 200, |
| 45 | + "line_width": 20, |
| 46 | +} |
| 47 | +shape_two = ShapeImage(image_shape, object_noise_level=0) |
| 48 | +# Use the combine objects method to make ellipses and rectangles with the above prameters |
| 49 | +shape_two_noiseless = shape_two.combine_objects( |
| 50 | + ["ellipse", "rectangle"], object_params=[ellipse_params, line_params] |
| 51 | +) |
| 52 | + |
| 53 | +subplots[0, 2].imshow(shape_two_noiseless) |
| 54 | + |
| 55 | +# Do it with a noise argument now |
| 56 | +shape_two = ShapeImage(image_shape, object_noise_level=0.2) |
| 57 | +shape_two_noisy = shape_single.combine_objects( |
| 58 | + ["ellipse", "rectangle"], object_params=[ellipse_params, line_params] |
| 59 | +) |
| 60 | + |
| 61 | +subplots[0, 3].imshow(shape_two_noisy) |
| 62 | + |
| 63 | +# Read the process with specifiations for astronomy objects |
| 64 | +star_instance = {"radius": 100.0, "amplitude": 100.0} |
| 65 | +star_params = {"center_x": center - int(center / 2), "center_y": center} |
| 66 | + |
| 67 | +galaxy_instance = {"radius": 30.0, "amplitude": 200.0, "ellipse": 0.8, "theta": 0.2} |
| 68 | +galaxy_params = {"center_x": center, "center_y": center + int(center / 2)} |
| 69 | +subplots[1, 0].set_ylabel("Astronomy", labelpad=8.0) |
| 70 | + |
| 71 | +one_image_sky = SkyImage(image_shape) |
| 72 | +one_sky = one_image_sky.combine_objects( |
| 73 | + ["star"], instance_params=[star_instance], object_params=[star_params] |
| 74 | +) |
| 75 | + |
| 76 | +subplots[1, 0].imshow(one_sky) |
| 77 | + |
| 78 | + |
| 79 | +one_sky_noise = SkyImage(image_shape, object_noise_level=0.4) |
| 80 | +one_image_sky_noise = one_sky_noise.combine_objects( |
| 81 | + ["star"], instance_params=[star_instance], object_params=[star_params] |
| 82 | +) |
| 83 | + |
| 84 | +subplots[1, 1].imshow(one_image_sky_noise) |
| 85 | + |
| 86 | +one_image_sky = SkyImage(image_shape) |
| 87 | +one_sky = one_image_sky.combine_objects( |
| 88 | + ["star", "galaxy"], |
| 89 | + instance_params=[star_instance, galaxy_instance], |
| 90 | + object_params=[star_params, galaxy_params], |
| 91 | +) |
| 92 | + |
| 93 | +subplots[1, 2].imshow(one_sky) |
| 94 | + |
| 95 | + |
| 96 | +one_sky_noise = SkyImage(image_shape, object_noise_level=0.4) |
| 97 | +one_image_sky_noise = one_sky_noise.combine_objects( |
| 98 | + ["star", "galaxy"], |
| 99 | + instance_params=[star_instance, galaxy_instance], |
| 100 | + object_params=[star_params, galaxy_params], |
| 101 | +) |
| 102 | + |
| 103 | +subplots[1, 3].imshow(one_image_sky_noise) |
| 104 | + |
| 105 | + |
| 106 | +one_sky_noise = SkyImage(image_shape, object_noise_level=0.4) |
| 107 | +one_image_sky_noise = one_sky_noise.combine_objects( |
| 108 | + ["star", "galaxy"], |
| 109 | + instance_params=[star_instance, galaxy_instance], |
| 110 | + object_params=[star_params, galaxy_params], |
| 111 | +) |
| 112 | + |
| 113 | +subplots[1, 3].imshow(one_image_sky_noise) |
| 114 | + |
| 115 | +# Y axis labels for each row |
| 116 | +subplots[0, 0].set_ylabel("Geometry", labelpad=10.0) |
| 117 | + |
| 118 | +# Remove unnecessary ticks, only put them on the 100 pixel marks |
| 119 | +# Flip the images so it starts at 0.,0. |
| 120 | +ticks = np.linspace(0, image_shape[0], int(image_shape[0] / 100)) |
| 121 | +for plot in subplots.ravel(): |
| 122 | + plot.autoscale(tight=True) |
| 123 | + plot.set_yticks(ticks.tolist()[::-1]) |
| 124 | + plot.invert_yaxis() |
| 125 | + plot.set_xticks(ticks) |
| 126 | + |
| 127 | +# All object titles |
| 128 | +subplots[0, 0].set_title("Noiseless Single Object") |
| 129 | +subplots[0, 2].set_title("Noiseless Multi-Object") |
| 130 | +subplots[0, 1].set_title("Noisy Single Object") |
| 131 | +subplots[0, 3].set_title("Noisy Multi-Object") |
| 132 | + |
| 133 | +# Scale information |
| 134 | +fig.supxlabel("pixel") |
| 135 | +fig.supylabel("pixel") |
| 136 | + |
| 137 | +plt.savefig("../example_objects.png") |
0 commit comments