FieldProfileAnalysis fails on 20×20 FFF fields unless image is inverted

27 views
Skip to first unread message

WP Struweg

unread,
Sep 15, 2025, 7:33:57 AMSep 15
to Pylinac
When analyzing large FFF fields (e.g., 20×20 cm²) with FieldProfileAnalysis, the analysis only completes successfully if the image array is inverted (image.invert()). Smaller fields (e.g., 10×10 cm²) with identical DICOM headers work as expected without inversion. 

WP Struweg

unread,
Sep 15, 2025, 7:39:53 AMSep 15
to Pylinac
Traceback (most recent call last):
File "C:\Users\dell\Documents\Python Scripts\FA\pylinac_fa.py", line 17, in <module>
fa.analyze(
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\pylinac\core\warnings.py", line 43, in wrapper
result = method(self, *args, **kwargs)
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\pylinac\field_profile_analysis.py", line 184, in analyze
self.x_profile.compute(metrics=metrics)
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\pylinac\core\profile.py", line 570, in compute
values[key] = metric.calculate()
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\pylinac\metrics\profile.py", line 272, in calculate
lower_index = self.profile.x_at_y(y=lower_search_value, side=self.side)
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\pylinac\core\profile.py", line 285, in x_at_y
new_x = f(y)
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\scipy\interpolate\_polyint.py", line 80, in __call__
y = self._evaluate(x)
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\scipy\interpolate\_interpolate.py", line 755, in _evaluate
below_bounds, above_bounds = self._check_bounds(x_new)
File "C:\Users\dell\anaconda3\envs\pylinac-env\lib\site-packages\scipy\interpolate\_interpolate.py", line 784, in _check_bounds
raise ValueError("A value ({}) in x_new is below "
ValueError: A value (0.4542599314519169) in x_new is below the interpolation range's minimum value (0.8566166052706019).

Anne Monseux

unread,
Sep 25, 2025, 3:18:26 AMSep 25
to Pylinac
Hi,
I use pylinac v 3.15 and met a similar problem with FFF beam 20x20cm², no problem with flat beam or smaller fields in FFF.
As you adviced I invert the image for the 20x20 FFF and displayed it (I'm sure it is well inverted) but the problem remains. Did you do anything else or use different arguments in  "analyze"?

thx
Anne

WP Struweg

unread,
Sep 25, 2025, 3:37:35 AMSep 25
to Pylinac
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")

Anne Monseux

unread,
Sep 25, 2025, 6:46:29 AMSep 25
to Pylinac
Hi,
I verified  if the condition about the centre pixel value is verified for my 20x20FFF and this the case. But the program doesn't work for this field. It's ok for the 10x10cm².
Here are the error message, with in first the pixel values and the image plotted. Perhaps it can help to understand...
prompt.PNG
image.PNG
For another similar image, I also obtained this strange result, even if I didn't invert the dark/light in the script. The image is finally inverted and the profile are outside the field in the pdf.
The centre pixel value is 0.0945717
The max is 0.096
wrong.PNG

Many thanks for your help
Anne

WP Struweg

unread,
Sep 25, 2025, 6:55:40 AMSep 25
to Anne Monseux, Pylinac
Hi Anne,

Looking at your center pixel value it will pass the if statement, but still obviously needs inversion as the analysis is failing. Maybe try and force the inversion on the 20x20FFF using my script instead of using the “if statement”.

Just run fa.image.invert() before the if statement.

I hope this works.


--
You received this message because you are subscribed to a topic in the Google Groups "Pylinac" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/pylinac/Q63aVe7GhPg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to pylinac+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pylinac/5fb3796e-cbd0-46e2-b8dc-03d96ea52cdan%40googlegroups.com.

WP Struweg

unread,
Sep 25, 2025, 6:58:00 AMSep 25
to Anne Monseux, Pylinac
Maybe try this:


# 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
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")

 
Message has been deleted

Anne Monseux

unread,
Sep 26, 2025, 3:11:42 PM (13 days ago) Sep 26
to Pylinac
Hi,
Unfortunately, the problem remains after inverting the image.
The pixel value are now  : centre 0.016 and max 0.096.
I observed similar values for the 10x10 and it works inverted or not.

Anne

WP Struweg

unread,
Sep 29, 2025, 4:28:01 AM (10 days ago) Sep 29
to Anne Monseux, Pylinac
Hi Anne,

Sorry to hear it's not working. If you want you can send me the DCM files for the 10x10 and 20x20 so I can compare and try and troubleshoot on my end. Otherwise we might have to wait for one of the Pylinac developers to help out with this issue.

Kind regards,
WP

You received this message because you are subscribed to the Google Groups "Pylinac" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylinac+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/pylinac/04b010d5-e703-4705-8d08-763066a0dfb9n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages