Documentation for image upload and calculation

Issue #257 invalid
Former user created an issue

I appreciate I am probably jumping the gun here, but I have only limited time to demonstrate this. I have uploaded an image and performed a calculation on it - feels like a hack but is this the way to go?

  1. Create a file upload test called 'Image' with macro name 'image'. Include a calculation procedure:
import numpy as np
  1. This test doesn't display the required data since the green upload bar covers it. Therefore create a composite test called 'Image Shape' and assign this to image data
image_shape = image

I could perform a bunch of calculations in the upload macro and export the results as a dict. However I am guessing the image is available as a numpy array, rather than file object?


UPDATE: I see this is your method in

Comments (23)

  1. Randle Taylor


    You can do something similar to the following. Create a file upload test (check off Display Image) with something similar to this procedure:

    from scipy.misc import imread
    from scipy.ndimage import gaussian_filter
    data = imread(BIN_FILE)
    homer = {
        "max": float(data.max()),
        "min": float(data.min()),
        "mean": float(data.mean()),
    blurred = gaussian_filter(data, 10)
    write_file('blurred_homer.png', blurred)

    And another composite test with macro_name mean_homer with calculation like:

    mean_homer = homer['mean']

    homer.png mean_homer.png homer_test_list.png

    That write_file function should also be able to take e.g. a matplotlib axes or figure instance and generate an image with it too. So you can generate plots with matplotlib and have them displayed as images.

  2. Randle Taylor

    @rob_cole For Pylinac like you asked you will need to do e.g. pf = pylinac.PicketFence(

  3. Former user Account Deleted reporter

    Thanks Randle, that was fast! However I keep getting image FAILED and it is failing at the import of imread (upload succeeds if I comment it out) I have scipy==0.18.1


  4. Randle Taylor

    Ah right...scipy.imread requires PIL I think. matplotlib.image.imread might work without PIL. Otherwise you can install Pillow (I guess at this point you would add it to your requirements.txt file for Docker).

  5. Former user Account Deleted reporter

    Interesting, that works on my Mac but fails on QAtrack.. Will try Pillow next week


  6. Former user Account Deleted reporter

    OK added pillow == 4.1.1 to the requirements and your code is now working :-)

  7. Simon Biggs

    I just want to say Randle that I am exceptionally impressed what you have achieved in this program package (QATrack+).

    Thank you for building what you have built :) it is beautiful :)

  8. Randle Taylor

    Thanks for the kind words...I certainly can't take all the credit as I had lots of guidance about the way things should work from a clinical perspective especially from @xtal. Lots of warts still to be resolved and improvements to be made but we're getting there!

  9. Former user Account Deleted reporter

    Hi all trying and failing to read a dicom file into QAtrack. Any ideas?

    import dicom
    my_dcm = dicom.read_file(BIN_FILE)   
    flatsym = 1
  10. Randle Taylor

    Strange, I thought that would have worked. If you try

    my_dcm = dicom.read_file(

    do you still see the same error?

  11. Randle Taylor

    Could be an issue with the dicom file missing the dicom header? pydicom has a force option that will force dicom parsing regardless of whether the header is present in the file or not. Try my_dcm = dicom.read_file(BIN_FILE, force=True)

    I'd also maybe just try using pydicom to open the file in a local python interpreter.

  12. Randle Taylor

    Closing this because there will be many docs to be written before release including image upload/analysis.

  13. Ruoxi WANG

    Hi @randlet, @rob_cole I was following some snippet in this thread and trying to reproduce what you guys have done here. And when I tried to save the blurred image, I got a permission denied exception. For the moment I could not find the exact location where apache2 is trying to save the blurred image. I have checked the media/uploads/ location, the permission looks fine so that might not be the image-saving location. Is there any systematic way to resolve this kind of issue?

    Plus, I have not used the write_file method to save images and fall back on scipy.misc.imsave, since the write_file method is not recognizable for the python interpreter. Thank you all in advance.

  14. Randle Taylor

    Hi @ruoxi_wang1812 the write_file method and viewing the resulting images is only available in v0.3.0 which hasn't been released yet. Are you using v0.2.9 or working with v0.3.0 code? If you are trying to use scipy.misc.imsave, then you likely need to use the full path to save an image (e.g. scipy.misc.imsave('/home/ruoxi_wang1812/web/qatrackplus/media/uploads/tmp/your_file.png', ....).

  15. Ruoxi WANG

    Hi @randlet Thank you for your quick response! I am using the v0.2.9. I think that I'll save the image with the absolute path for the moment! Is there any way to insert any breakpoints so that the location to save the file can be visualized?

  16. Randle Taylor

    Sorry there's no way to set break points at this time. Without an absolute path imsave just saves in the current directory the QATrack+ process is running from...usually that would be e.g. /home/ruoxi/web/qatrackplus/ but I'm not certain.

  17. Log in to comment