pysilcam/tests/synthesizer.py
def synthesize(diams, bin_limits_um, nd, imx, imy, PIX_SIZE):
    '''synthesize an image and measure droplets

    Args:
      diams   (array)                       :  size bins of the number distribution
      bin_limits_um (array)                 :  limits of the size bins where dias are the mid-points
      nd      (array)                       :  number of particles per size bin
      imx     (float)                       :  image width in pixels
      imy     (float)                       :  image height in pixels
      PIX_SIZE          (float)             :  pixel size of the setup [um]

    Returns:
      img (unit8)                         : segmented image from pysilcam
      log_vd (array)                      : a volume distribution of the randomly selected particles put into the synthetic image

    '''
    nc = int(sum(nd)) # number concentration

    # preallocate the image and logged volume distribution variables
    img = np.zeros((imy, imx, 3), dtype=np.uint8()) + 230 # scale the initial brightness down a bit
    log_ecd = np.zeros(nc)
    # randomly select a droplet radii from the input distribution
    rad = np.random.choice(diams / 2, size=nc, p=nd / sum(nd)) / PIX_SIZE  # radius is in pixels
    log_ecd = rad * 2 * PIX_SIZE  # log these sizes as a diameter in um
    for rad_ in rad:
        # randomly decide where to put particles within the image
        col = np.random.randint(1, high=imx - rad_)
        row = np.random.randint(1, high=imy - rad_)
        rr, cc = circle(row, col, rad_) # make a cirle of the radius selected from the distribution
        img[rr, cc, :] = 0 # make the circle completely non-transmitting (i.e. black)

    necd, edges = np.histogram(log_ecd, bin_limits_um) # count the input diameters into a number distribution
    log_vd = scpp.vd_from_nd(necd, diams) # convert to a volume distribution

    # add some noise to the synthesized image
    img = np.uint8(255 * util.random_noise(np.float64(img) / 255), var=0.01 ** 2)

    img = np.uint8(img) # convert to uint8
    return img, log_vd
synthesize an image and measure droplets

    Args:
      diams   (array)                       :  size bins of the number distribution
      bin_limits_um (array)                 :  limits of the size bins where dias are the mid-points
      nd      (array)                       :  number of particles per size bin
      imx     (float)                       :  image width in pixels
      imy     (float)                       :  image height in pixels
      PIX_SIZE          (float)             :  pixel size of the setup [um]

    Returns:
      img (unit8)                         : segmented image from pysilcam
      log_vd (array)                      : a volume distribution of the randomly selected particles put into the synthetic image

    
synthesize an image and measure droplets
synthesize an image and measure droplets
def synthesize(diams, bin_limits_um, nd, imx, imy, PIX_SIZE):
    nc = int(sum(nd)) 
    img = np.zeros((imy, imx, 3), dtype=np.uint8()) + 230 
    log_ecd = np.zeros(nc)
    rad = np.random.choice(diams / 2, size=nc, p=nd / sum(nd)) / PIX_SIZE  
    log_ecd = rad * 2 * PIX_SIZE  
    for rad_ in rad:
        col = np.random.randint(1, high=imx - rad_)
        row = np.random.randint(1, high=imy - rad_)
        rr, cc = circle(row, col, rad_) 
        img[rr, cc, :] = 0 
    necd, edges = np.histogram(log_ecd, bin_limits_um) 
    log_vd = scpp.vd_from_nd(necd, diams) 
    img = np.uint8(255 * util.random_noise(np.float64(img) / 255), var=0.01 ** 2)
    img = np.uint8(img) 
    return img, log_vd
def synthesize ( diams , bin_limits_um , nd , imx , imy , PIX_SIZE ) : nc = int ( sum ( nd ) ) img = np . zeros ( ( imy , imx , 3 ) , dtype = np . uint8 ( ) ) + 230 log_ecd = np . zeros ( nc ) rad = np . random . choice ( diams / 2 , size = nc , p = nd / sum ( nd ) ) / PIX_SIZE log_ecd = rad * 2 * PIX_SIZE for rad_ in rad : col = np . random . randint ( 1 , high = imx - rad_ ) row = np . random . randint ( 1 , high = imy - rad_ ) rr , cc = circle ( row , col , rad_ ) img [ rr , cc , : ] = 0 necd , edges = np . histogram ( log_ecd , bin_limits_um ) log_vd = scpp . vd_from_nd ( necd , diams ) img = np . uint8 ( 255 * util . random_noise ( np . float64 ( img ) / 255 ) , var = 0.01 ** 2 ) img = np . uint8 ( img ) return img , log_vd
synthesize an image and measure droplets
synthesize an image and measure droplets
'''synthesize an image and measure droplets

    Args:
      diams   (array)                       :  size bins of the number distribution
      bin_limits_um (array)                 :  limits of the size bins where dias are the mid-points
      nd      (array)                       :  number of particles per size bin
      imx     (float)                       :  image width in pixels
      imy     (float)                       :  image height in pixels
      PIX_SIZE          (float)             :  pixel size of the setup [um]

    Returns:
      img (unit8)                         : segmented image from pysilcam
      log_vd (array)                      : a volume distribution of the randomly selected particles put into the synthetic image

    ''' # number concentration # preallocate the image and logged volume distribution variables # scale the initial brightness down a bit # randomly select a droplet radii from the input distribution # radius is in pixels # log these sizes as a diameter in um # randomly decide where to put particles within the image # make a cirle of the radius selected from the distribution # make the circle completely non-transmitting (i.e. black) # count the input diameters into a number distribution # convert to a volume distribution # add some noise to the synthesized image # convert to uint8
img (unit8)                         : segmented image from pysilcam
log_vd (array)                      : a volume distribution of the randomly selected particles put into the synthetic image
img ( unit8 ) : segmented image from pysilcam log_vd ( array ) : a volume distribution of the randomly selected particles put into the synthetic image
diams
size bins of the number distribution
size bins of the number distribution
bin_limits_um
limits of the size bins where dias are the mid-points
limits of the size bins where dias are the mid - points
nd
number of particles per size bin
number of particles per size bin
imx
image width in pixels
image width in pixels
imy
image height in pixels
image height in pixels
PIX_SIZE
pixel size of the setup [um]
pixel size of the setup [ um ]