Hi Anne,
Here is a simple script I used to just do a 10 x 10 and 20 x 20 FFF square field. I added a check to see if the center pixel value is at least 80% the value of the max pixel value, because I noticed that if I printed the center pixel value for big fields it is very small compared to the max pixel value. I definitely think its a normalization issue on the FFF fields. This if statement will invert the pixel data if that condition isn't met. I encourage you to compare the center pixel value with the max value! Sorry if my code doesn't make sense, but at least focus on the "fa.image.invert()" part. Let me know if you have any issues.
P.S. I am still working on a robust way to know when to flip the data before analyzing it, because I have noticed that this "if" statement doesn't work for all field sizes, but it should work for your 20 x 20 cm field.
# Import all the necessary packages
import matplotlib.pyplot as plt
import numpy as np
from pylinac import FieldProfileAnalysis, Centering, Normalization, Edge
from pylinac.metrics.profile import (
PenumbraLeftMetric,
PenumbraRightMetric,
SymmetryAreaMetric,
FlatnessDifferenceMetric,
)
# Enter your path to the DCM image
path = r"C:\Users\dell\Documents\Python Scripts\FA\20.dcm"
# Define the Field Analysis
fa = FieldProfileAnalysis(path)
# --- Access the image pixels Pylinac is using ---
pixels = fa.image.array
rows, cols = pixels.shape
# Beam center pixel (middle of array)
cy, cx = rows // 2, cols // 2
center_value = pixels[cy, cx]
# Pylinac image object has a .invert() method
# This section checks if the data needs to be flipped
if center_value > 0.8*pixels.max():
print("The image data need not be flipped")
else:
print("The image data needs to be flipped")
fa.image.invert()
# Now analyze the data
fa.analyze(
centering=Centering.BEAM_CENTER,
x_width=0.02,
y_width=0.02,
normalization=Normalization.BEAM_CENTER,
edge_type=Edge.INFLECTION_DERIVATIVE,
ground=True,
metrics=(
PenumbraLeftMetric(),
PenumbraRightMetric(),
SymmetryAreaMetric(),
FlatnessDifferenceMetric(),
),
)
fa.plot_analyzed_images(show_grid=True, mirror="beam")
print(fa.results_data())
fa.publish_pdf(filename="flatsym.pdf")