return exposure times, image averages for each exposure time
966785
def getDarkCurrentAverages(exposuretimes, imgs):
    '''
    
    '''
    x, imgs_p = sortForSameExpTime(exposuretimes, imgs)
    s0, s1 = imgs[0].shape

    imgs = np.empty(shape=(len(x), s0, s1),
                    dtype=imgs[0].dtype)
    for i, ip in zip(imgs, imgs_p):
        if len(ip) == 1:
            i[:] = ip[0]
        else:
            i[:] = averageSameExpTimes(ip)
    return x, imgs
1015110
def rgChromaticity(img):
    '''
    
    '''
    out = _calc(img)
    if img.dtype == np.uint8:
        out = (255 * out).astype(np.uint8)
    return out
141734
def inasafe_exposure_summary_field_values(field, feature, parent):
    
    _ = feature, parent  # NOQA

    layer = exposure_summary_layer()
    if not layer:
        return None

    index = layer.fields().lookupField(field)
    if index < 0:
        return None

    values = []
    for feat in layer.getFeatures():
        value = feat[index]
        values.append(value)

    return str(values)
130789
def resp_graph(dataframe, image_name, dir='./'):
    
    fig = pygal.TimeLine(x_title='Elapsed Time In Test (secs)',
                         y_title='Response Time (secs)',
                         x_label_rotation=25,
                         js=('scripts/pygal-tooltip.min.js',))
    fig.add('AVG', [(get_local_time(index), row['mean'] if pd.notnull(row['mean']) else None)
                    for index, row in dataframe.iterrows()])
    fig.add('90%', [(get_local_time(index), row['90%'] if pd.notnull(row['90%']) else None)
                    for index, row in dataframe.iterrows()])
    fig.add('80%', [(get_local_time(index), row['80%'] if pd.notnull(row['80%']) else None)
                    for index, row in dataframe.iterrows()])
    fig.render_to_file(filename=os.path.join(dir, image_name))
1273891
function _imageCopyResampledWorkaround2(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
    {
        ImagePaletteCopy($dst_img, $src_img);
        $rX = $src_w / $dst_w;
        $rY = $src_h / $dst_h;
        $w = 0;
        for ($y = $dst_y; $y < $dst_h; $y++)
        {
            $ow = $w;
            $w = round(($y + 1) * $rY);
            $t = 0;
            for ($x = $dst_x; $x < $dst_w; $x++)
            {
                $r = $g = $b = 0;
                $a = 0;
                $ot = $t;
                $t = round(($x + 1) * $rX);
                for ($u = 0; $u < ($w - $ow); $u++)
                {
                    for ($p = 0; $p < ($t - $ot); $p++)
                    {
                        $c = ImageColorsForIndex($src_img, ImageColorAt($src_img, $ot + $p, $ow + $u));
                        $r += $c['red'];
                        $g += $c['green'];
                        $b += $c['blue'];
                        $a++;
                    }
                }
                ImageSetPixel($dst_img, $x, $y, ImageColorClosest($dst_img, $r / $a, $g / $a, $b / $a));
            }
        }
    }
928403
def bench(image, thread_count):
  
  threads = [threading.Thread(target=lambda: encoder.encode_png(image))
             for _ in xrange(thread_count)]
  start_time = datetime.datetime.now()
  for thread in threads:
    thread.start()
  for thread in threads:
    thread.join()
  end_time = datetime.datetime.now()
  delta = (end_time - start_time).total_seconds()
  return delta
1176970
def get_qpimage_raw(self, idx):
        """"""
        with self._qpseries() as qps:
            qpi = qps.get_qpimage(index=idx).copy()
        # Remove previously performed background correction
        qpi.set_bg_data(None)
        # Force meta data
        for key in self.meta_data:
            qpi[key] = self.meta_data[key]
        # set identifier
        qpi["identifier"] = self.get_identifier(idx)
        return qpi
1071783
def get_qpimage_raw(self, idx):
        """"""
        ds = self._get_dataset(idx)
        qpi = ds.get_qpimage_raw()
        qpi["identifier"] = self.get_identifier(idx)
        return qpi
440195
def rgb2gray(img):
    """"""
    T = np.linalg.inv(np.array([
        [1.0,  0.956,  0.621],
        [1.0, -0.272, -0.647],
        [1.0, -1.106,  1.703],
    ]))
    r_c, g_c, b_c = T[0]
    r, g, b = np.rollaxis(as_float_image(img), axis=-1)
    return r_c * r + g_c * g + b_c * b
491928
def scaled_exposure_time(self):
        
        if self._data_count_unit == 'ADU':
            exp_time = self.ccd_gain * self.exposure_time
        else:
            exp_time = self.exposure_time
        return exp_time
448237
function getImagePixels() {
    var w = width;
    var h = height;
    pixels = [];
    var data = image;
    var count = 0;

    for (var i = 0; i < h; i++) {

      for (var j = 0; j < w; j++) {

        var b = (i * w * 4) + j * 4;
        pixels[count++] = data[b];
        pixels[count++] = data[b + 1];
        pixels[count++] = data[b + 2];

      }

    }
  }
353891
def get_background_threshold(image, mask = None):
    """"""
    cropped_image = np.array(image.flat) if mask is None else image[mask]
    if np.product(cropped_image.shape)==0:
        return 0
    img_min = np.min(cropped_image)
    img_max = np.max(cropped_image)
    if img_min == img_max:
        return cropped_image[0]
    
    # Only do the histogram between values a bit removed from saturation
    robust_min = 0.02 * (img_max - img_min) + img_min
    robust_max = 0.98 * (img_max - img_min) + img_min
    nbins = 256
    cropped_image = cropped_image[np.logical_and(cropped_image > robust_min,
                                                 cropped_image < robust_max)]
    if len(cropped_image) == 0:
        return robust_min
    
    h = scipy.ndimage.histogram(cropped_image, robust_min, robust_max, nbins)
    index = np.argmax(h)
    cutoff = float(index) / float(nbins-1)
    #
    # If we have a low (or almost no) background, the cutoff will be
    # zero since the background falls into the lowest bin. We want to
    # offset by the robust cutoff factor of .02. We rescale by 1.04
    # to account for the 0.02 at the top and bottom.
    #
    cutoff = (cutoff + 0.02) / 1.04
    return img_min + cutoff * 2 * (img_max - img_min)
1046981
def medianThreshold(img, threshold=0.1, size=3, condition='>', copy=True):
    '''
    
    '''
    from scipy.ndimage import median_filter

    indices = None
    if threshold > 0:
        blur = np.asfarray(median_filter(img, size=size))
        with np.errstate(divide='ignore', invalid='ignore', over='ignore'):

            if condition == '>':
                indices = abs((img - blur) / blur) > threshold
            else:
                indices = abs((img - blur) / blur) < threshold

        if copy:
            img = img.copy()

        img[indices] = blur[indices]
    return img, indices
684541
def estimate_sub_second_time(files, interval=0.0):
    '''
    
    '''
    if interval <= 0.0:
        return [exif_time(f) for f in tqdm(files, desc="Reading image capture time")]

    onesecond = datetime.timedelta(seconds=1.0)
    T = datetime.timedelta(seconds=interval)
    for i, f in tqdm(enumerate(files), desc="Estimating subsecond time"):
        m = exif_time(f)
        if not m:
            pass
        if i == 0:
            smin = m
            smax = m + onesecond
        else:
            m0 = m - T * i
            smin = max(smin, m0)
            smax = min(smax, m0 + onesecond)
    if not smin or not smax:
        return None
    if smin > smax:
        # ERROR LOG
        print('Interval not compatible with EXIF times')
        return None
    else:
        s = smin + (smax - smin) / 2
        return [s + T * i for i in range(len(files))]
785699
def tenengrad(img, ksize=3):
    '''''''
    Gx = cv2.Sobel(img, ddepth=cv2.CV_64F, dx=1, dy=0, ksize=ksize)
    Gy = cv2.Sobel(img, ddepth=cv2.CV_64F, dx=0, dy=1, ksize=ksize)
    FM = Gx*Gx + Gy*Gy
    mn = cv2.mean(FM)[0]
    if np.isnan(mn):
        return np.nanmean(FM)
    return mn
785567
def symmetry_average(image, symmetry):
    
    img_sym = np.zeros_like(image)
    angle = 360./symmetry
    for i in range(symmetry):
        img_sym += rotateImage(image, angle*i)
    img_sym /= symmetry
    return img_sym
405902
function _imageCopyResampledWorkaround(&$dst_img, &$src_img, $dst_x, $dst_y, $src_x, $src_y, $dst_w, $dst_h, $src_w, $src_h)
    {
        /*
        for ($i = 0; $i < imagecolorstotal($src_img); $i++)
        {
            $colors = ImageColorsForIndex ($src_img, $i);
            ImageColorAllocate ($dst_img, $colors['red'],$colors['green'], $colors['blue']);
        }
        */
        $scaleX = ($src_w - 1) / $dst_w;
        $scaleY = ($src_h - 1) / $dst_h;

        $scaleX2 = $scaleX / 2.0;
        $scaleY2 = $scaleY / 2.0;

        for ($j = $src_y; $j < $src_y + $dst_h; $j++)
        {
            $sY = $j * $scaleY;
            for ($i = $src_x; $i < $src_x + $dst_w; $i++)
            {
                $sX = $i * $scaleX;

                $c1 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY + $scaleY2));
                $c2 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX, (int)$sY));
                $c3 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY + $scaleY2));
                $c4 = ImageColorsForIndex($src_img, ImageColorAt($src_img, (int)$sX + $scaleX2, (int)$sY));

                $red = (integer)(($c1['red'] + $c2['red'] + $c3['red'] + $c4['red']) / 4);
                $green = (integer)(($c1['green'] + $c2['green'] + $c3['green'] + $c4['green']) / 4);
                $blue = (integer)(($c1['blue'] + $c2['blue'] + $c3['blue'] + $c4['blue']) / 4);

                $color = ImageColorClosest($dst_img, $red, $green, $blue);
                ImageSetPixel($dst_img, $dst_x + $i - $src_x, $dst_y + $j - $src_y, $color);
            }
        }
    }