import pylinac
from pylinac.core.image_generator import generate_picketfence, GaussianFilterLayer, PerfectFieldLayer, RandomNoiseLayer, AS1200Image
from pylinac.picketfence import Orientation

# the file name to write the DICOM image to disk to
pf_file = "perfect_.dcm"
# create a PF image with 5 pickets with 40mm spacing between them and 3mm gap. Also applies a gaussian filter to simulate the leaf edges.
generate_picketfence(
    simulator=AS1200Image(sid=1000),
    field_layer=PerfectFieldLayer,
    file_out=pf_file,
    final_layers=[
        GaussianFilterLayer(sigma_mm=1),
    ],
    pickets=5,
    picket_spacing_mm=40,
    picket_width_mm=3,
    orientation=Orientation.UP_DOWN,
)
# load it just like any other
pf = pylinac.PicketFence(pf_file)
pf.analyze(separate_leaves=False, nominal_gap_mm=4)
print(pf.results_data())
pf.plot_analyzed_image()