How to use the ndlib.ndtype.DTYPE_uint16 function in ndlib

To help you get started, we’ve selected a few ndlib examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github neurodata / ndstore / webservices / ndwsrest.py View on Github external
# argument of format channel/service/imageargs
    m = re.match("([\w+,]+)/(\w+)/([\w+,/-]+)$", chanargs)
    [channels, service, imageargs] = [i for i in m.groups()]
  except Exception as e:
    logger.error("Arguments not in the correct format {}. {}".format(chanargs, e))
    raise NDWSError("Arguments not in the correct format {}. {}".format(chanargs, e))

  try:
    ch = proj.getChannelObj(channels.split(',')[0])
    cubedata = channelIterCutout(channels, imageargs, proj, db)
  
    xdim, ydim, zdim = cubedata[0,:,:,:].shape[::-1]
    #cubedata = np.swapaxes(cubedata[0,:,:,:], 0,2).reshape(xdim*zdim, ydim)
    cubedata = cubedata[0,:,:,:].reshape(ydim*zdim, xdim)
    
    if ch.channel_datatype in DTYPE_uint16:
      img = Image.fromarray(cubedata, mode='I;16')
      img = img.point(lambda i:i*(1./256)).convert('L')
    elif ch.channel_datatype in DTYPE_uint32:
      img = Image.fromarray(cubedata, mode='RGBA')
    else:
      img = Image.fromarray(cubedata)
    fileobj = BytesIO()
    img.save ( fileobj, "JPEG" )

    fileobj.seek(0)
    return fileobj.read()

  except Exception as e:
    logger.error("{}".format(e))
    raise NDWSError("{}".format(e))
github neurodata / ndstore / webservices / ndwsnifti.py View on Github external
def queryNIFTI ( tmpfile, ch, db, proj ):
  """ Return a NII file that contains the entire DB"""

  try:
    # get the header in a fileobj
    nh = NDNiftiHeader.fromChannel(ch)

    cuboid = db.cutout ( ch, (0,0,0), proj.datasetcfg.dataset_dim(0), 0, timerange=ch.time_range) 

    # transpose to nii's xyz format
    niidata = cuboid.data.transpose()

    # coerce the data type 
    if ch.channel_datatype in DTYPE_uint8:   
      niidata = np.array(niidata, dtype='
github neurodata / ndstore / django / synaptogram / views.py View on Github external
(ylow, yhigh) = (ylow-yoffset, yhigh-yoffset)
      (zlow, zhigh) = (zlow-zoffset, zhigh-zoffset)

      corner = [ xlow, ylow, zlow ]
      dim = [ xhigh-xlow, yhigh-ylow, zhigh-zlow ]

      outputdict = {}

      # get the data region for each channel 
      for chan in channels:
        # data type on a per channel basis
        ch = proj.getChannelObj(chan)
        try: 
          cb = db.cutout ( ch, corner, dim, resolution )
          # apply window for 16 bit projects 
          if ch.getDataType() in DTYPE_uint16:
            [startwindow, endwindow] = window_range = ch.window_range
            if (endwindow != 0):
              cb.data = np.uint8(windowCutout(cb.data, window_range))
          
          outputdict[chan] = []
          for zslice in cb.data:
          
            if ch.getChannelType() in ANNOTATION_CHANNELS:
              # parse annotation project
              imagemap = np.zeros( [ dim[1], dim[0] ], dtype=np.uint32 )
              imagemap = recolor_ctype( zslice, imagemap )
              img = Image.frombuffer( 'RGBA', (dim[0],dim[1]), imagemap, 'raw', 'RGBA', 0, 1 )

            else: 
              # parse image project  
              img = Image.frombuffer( 'L', (dim[0], dim[1]), zslice.flatten(), 'raw', 'L', 0, 1 )