image format(s), conversions to use images with FlatSym


I would like to use FLatSym for images taken with a camera and stored as JPEG.
How should I convert the images to open with FlatSym ?

Thank you.

I just tested it and Pylinac happily took a jpg file as an input for the FlatSym module (e.g. fs = pylinac.FlatSym(“/path/to/your/file.jpg”). Also, you might already be aware, but jpg is typically a lossy format (although there is lossless jpg as well IIRC) which uses compression to reduce the file size. This reduces the amount of information in the image and may introduce artifacts that can be an issue for scientific purposes. Don’t know if that applies in your situation or not but its worth mentioning for future visitors!


Hi Taylor,
Thank you for your reply.
I’ve tried several image formats : Jpeg, tiff, dcm and always get errors when feeding them to FlatSym.
I’ve tried to reducing channels to one, converting to dcm,…
If I export a Varian integrated image (dcm file) then I have no problems analyzing the image
My intention is to use it for a project were we use a scintilator sheet and a camera to grab the fluence/output and then analyze this.
The camera outputs a jpg.

Suggestions to solve my issue are very welcome :slight_smile:

Thank you.

What error do you get? Is your camera able to export RAW files? If so, I would probably first try exporting as RAW and then convert RAW to tiff.

Have you looked at a profile of pixel values across the image? It’s quite possible that the profile looks completely flat or has some artifact that prevents pylinac from analyzing it (you may need to smooth the image or the profile before analyzing).


What version are you using?

Hi James, Taylor,

Thank you for the feedback.
I’m using pylinac 2.3.2
It seems that I have no problem opening the image file, analyzing it and plotting it. Which is already a relief :slight_smile:
The errors occur while printing the results and saving as pdf.
I haven’t done any smoothing of the image.
Should I limit the image to just one channel eg. RED or is this not necessary ?
Printing and extracting the results and being able to print the PDF would be really nice.

Code :
img = load(“iris.jpg”)
my_img.analyze(flatness_method=‘varian’, symmetry_method=‘varian’, vert_position=0.5, horiz_position=0.5)
print(my_img.results()) # print results
my_img.plot() # matplotlib image
my_img.publish_pdf(filename=“flatsym.pdf”) # create PDF and save to file

Console :

“C:\Users\Eric\Desktop\DOSEVIEW PROJECTS\CYBERKNIFE QC\Diaphragm2\venv\Scripts\python.exe” “C:/Users/Eric/Desktop/DOSEVIEW PROJECTS/CYBERKNIFE QC/Diaphragm2/”
Traceback (most recent call last):
File “C:/Users/Eric/Desktop/DOSEVIEW PROJECTS/CYBERKNIFE QC/Diaphragm2/”, line 29, in
print(my_img.results()) # print results
File “C:\Users\Eric\Desktop\DOSEVIEW PROJECTS\CYBERKNIFE QC\Diaphragm2\venv\lib\site-packages\pylinac\”, line 171, in results
horiz_penum = self.symmetry[‘horizontal’][‘profile’].penumbra_width() / self.image.dpmm
TypeError: unsupported operand type(s) for /: ‘int’ and ‘NoneType’

Process finished with exit code 1

Ah. This is because you haven’t defined the pixel to distance property. A JPG has no physical units. Pylinac wants to give you the penumbra of the field in mm, but it has no way of knowing.

Pylinac is really only meant for EPID images, so you’ll need to do add these props manually. Try this gist.

Ok. Thank you James !

Hi all,

I’m back at my code for using FlatSym but I’m stuck even at trying to use the demo code :frowning:

from pylinac import FlatSym
import matplotlib.pyplot as plt

fs = FlatSym.from_demo_image()

fs.analyze(flatness_method=‘varian’, symmetry_method=‘varian’, vert_position=0.5, horiz_position=0.5)

My errors :

Traceback (most recent call last):
File “C:\Users\Eric\Desktop\DOSEVIEW PROJECTS\CYBERKNIFE QC\Diaphragm2\”, line 6, in
fs.analyze(flatness_method=‘varian’, symmetry_method=‘varian’, vert_position=0.5, horiz_position=0.5)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\”, line 156, in analyze
self.symmetry = self._calc_symmetry(symmetry_method, vert_position, horiz_position, vert_width, horiz_width)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\”, line 233, in _calc_symmetry
vert_profile = self._get_vert_profile(vert_position, vert_width)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\”, line 215, in _get_vert_profile
left_width = int(round(self.array.shape[1]*vert_position - self.array.shape[1]*vert_width/2))
AttributeError: ‘FlatSym’ object has no attribute ‘array’

I’m using pylinac 2.3.2.

Please advise.
Thank you !

Revert to 2.3.1. 2.3.2 introduced a bug in the flatsym module.

Hi James,

I’ve now tried opening a tif image and setting the dpmm to eg 5.

from pylinac import FlatSym

my_img.analyze(flatness_method=‘varian’, symmetry_method=‘varian’, vert_position=0.5, horiz_position=0.5)
#print(my_img.results()) # print results
my_img.plot() # matplotlib image

I’m getting the following error :

C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\python.exe “C:/Users/Eric/Desktop/DOSEVIEW PROJECTS/CYBERKNIFE QC/Diaphragm2/”
Traceback (most recent call last):
File “C:/Users/Eric/Desktop/DOSEVIEW PROJECTS/CYBERKNIFE QC/Diaphragm2/”, line 6, in
AttributeError: ‘NoneType’ object has no attribute ‘image’

Opening the same image as a jpeg gives :

C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\python.exe “C:/Users/Eric/Desktop/DOSEVIEW PROJECTS/CYBERKNIFE QC/Diaphragm2/”
Traceback (most recent call last):
File “C:/Users/Eric/Desktop/DOSEVIEW PROJECTS/CYBERKNIFE QC/Diaphragm2/”, line 3, in
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\”, line 108, in init
self.image = image.load(path)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\core\”, line 153, in load
elif _is_dicom(path):
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\core\”, line 229, in _is_dicom
return is_dicom_image(file=path)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pylinac\core\”, line 52, in is_dicom_image
img = pydicom.dcmread(file, force=True)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydicom\”, line 870, in dcmread
dataset = read_partial(fp, stop_when, defer_size=defer_size,
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydicom\”, line 742, in read_partial
dataset = read_dataset(fileobj, is_implicit_VR, is_little_endian,
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydicom\”, line 363, in read_dataset
raw_data_element = next(de_gen)
File “C:\Users\Eric\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pydicom\”, line 192, in data_element_generator
value = (fp_read(length) if length > 0

Please advise.
Thank you.

I’m using now 2.3.1.

Hi James,

Can you please point me in the right direction to analyze some images ?
I’m getting this error :

from pylinac import FlatSym

#my_img.analyze(flatness_method='varian', symmetry_method='varian', vert_position=0.5, horiz_position=0.5)
#print(my_img.results())  # print results
#my_img.plot()  # matplotlib image
#my_img.publish_pdf(filename="flatsym.pdf")  # create PDF and save to file


Thank you.
Best regards,

image.tif (2.67 MB)