getFile.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. import labkeyInterface
  2. import labkeyFileBrowser
  3. import io
  4. import pydicom
  5. import numpy
  6. import itk
  7. net=labkeyInterface.labkeyInterface()
  8. net.init('/home/studen/.labkey/merlin.json')
  9. b=labkeyFileBrowser.labkeyFileBrowser(net)
  10. url=b.formatPathURL('DORA/Radiomics',"")
  11. ok,dirs=b.listRemoteDir(url)
  12. url=dirs[10]
  13. ok,dirs=b.listRemoteDir(url)
  14. url=dirs[0]
  15. ok,dirs=b.listRemoteDir(url)
  16. fileUrl=dirs[0]
  17. resp=net.get(fileUrl)
  18. fileObj=io.BytesIO(resp.data)
  19. #get dcm representation of the file
  20. dcm=pydicom.dcmread(fileObj)
  21. #matrix dimension
  22. ConstPixelDims = (int(dcm.Rows), int(dcm.Columns))
  23. npArray = numpy.zeros(ConstPixelDims, dtype=dcm.pixel_array.dtype)
  24. npArray[:, :] = dcm.pixel_array
  25. #get it to itk
  26. itkImg=itk.GetImageFromArray(npArray)
  27. #works for DORA dicoms, but it would be great to be able to get that from itkImg
  28. InputPixelType = itk.SS
  29. #required by Canny
  30. OutputPixelType = itk.F
  31. Dimension = 2
  32. InputImageType = itk.Image[InputPixelType, Dimension]
  33. OutputImageType = itk.Image[OutputPixelType, Dimension]
  34. #recast to F
  35. castImageFilter = itk.CastImageFilter[InputImageType, OutputImageType].New()
  36. castImageFilter.SetInput(itkImg)
  37. #for debugging
  38. castImageFilter.Update()
  39. itkImg1=castImageFilter.GetOutput()
  40. variance=2
  41. upperThreshold=5
  42. lowerThreshold=0.4*upperThreshold
  43. cannyFilter = itk.CannyEdgeDetectionImageFilter[
  44. OutputImageType,
  45. OutputImageType].New()
  46. cannyFilter.SetInput(castImageFilter.GetOutput())
  47. cannyFilter.SetVariance(variance)
  48. cannyFilter.SetLowerThreshold(lowerThreshold)
  49. cannyFilter.SetUpperThreshold(upperThreshold)
  50. cannyFilter.Update()
  51. canny=cannyFilter.GetOutput()
  52. npCanny=itk.GetArrayFromImage(canny)