python - Viewing dicom image with Bokeh -


i'm trying set graph background dicom image. followed this example, image data given dicom.pixel_array isn't rgba. i'm not sure how convert it, either. i'm not sure bokeh expecting. i've tried finding specifics in documentation, not such luck.

from bokeh.plotting import figure, show, output_file import dicom import numpy np   path = "/pathtodicomimage.dcm" data = dicom.read_file(path) img = data.pixel_array  p = figure(x_range=(0,10), y_range=(0,10))  # must give vector of images p.image_rgba(image=[img], x=0, y=0, dw=10, dh=10)  output_file("image_rgba.html", title="image_rgba.py example")  show(p)  

this code doesnt give me errors, doesn't display anything. maybe pixel array doesn't have alpha data, alpha defaults 0? i'm not sure. also, can't quite figure out how test it.

solved

as pointed out, needed map pixel data rgba space. instance, means duplicating data each channel, , setting alpha way.

def dicom_image_to_rgba(image_data):     rows = len(image_data)     cols = rows     img = np.empty((rows,cols), dtype=np.uint32)     view = img.view(dtype=np.uint8).reshape((rows, cols, 4))     in range(0,rows):         j in range(0,cols):             view[i][j][0] = image_data[i][j]             view[i][j][1] = image_data[i][j]             view[i][j][2] = image_data[i][j]             view[i][j][3] = 255     return img 

not being expert in python, have had glance @ pydicom's capabilities in handling pixel data. figured out pixel_array value of pixel-data attribute of dicom dataset as is , pydicom not offer functionality convert standard format can handled uniformly. means have convert rgb in cases quite compilcated , error-prone task.

things consider in this:

  • the encoding (big/little endian, various compression methods jpeg, jpeg-ls, rle, zip) - dicom attribute (0002,0010) transfersyntaxuid
  • the type of pixeldata (grayscale, rgb, ...) - dicom attribute (0028,0004) photometricinterpretation, (0028,0103) pixelrepresentation
  • in case of color images: values encoded colur plane (rrrrr,.....ggggg,.....bbbbb) or colour pixel expect (rgb rgb...)
  • the bit depth , bits used actual pixel data values (0028,0100) bitsallocated, (0028,0101) bitsstored, (0028,0102) highbit.
  • are pixel data values values displayed or indices colour/grayscale lookup table (0028,3000) modalitylutsequence, (0028,3002) lutdescriptor, (0028,3003) lutexplanation, (0028,3004) modalityluttype, (0028,3006) lutdata.

scary, isn't it? modern image classes enhanced mr, there more that.

however, if constrain particular type of image (e.g. computed radiography). limitations above mentioned apply make life bit easier.

if post dicom dump of image header give hints how display particular image.

hth

kritzel


Comments

Popular posts from this blog

sequelize.js - Sequelize group by with association includes id -

android - Robolectric "INTERNET permission is required" -

java - Android raising EPERM (Operation not permitted) when attempting to send UDP packet after network connection -