<commit_before>#!/usr/bin/env python

from idl_functions import histogram

def histogram_backprojection(array, roi, nbins=256):
    """
    
    """
    # the histogram of the full image should be done first
    # so as to get the full dynamic range
    h = histogram(roi, nbins=nbins, omin='omin', omax='omax',
                  locations='loc')

    hist = h['histogram']
    omin = h['omin']
    omax = h['omax']
    loc = h['loc']

    binsz = loc[1] - loc[0]

    total_h = numpy.sum(hist, dtype='float')

    # Normalise the histogram
    norm_h = hist / total_h
    # Or use the pdf??? hist / max(hist) ??

    # Produce the probability image
    # i.e. index into the pdf via the bin location for every pixel

    return None<commit_msg>Added a first cut for histogram_backprojection.<commit_after>#!/usr/bin/env python

import numpy
from idl_functions import histogram


def histogram_backprojection(array, roi, nbins=256):
    """
    
    """
    # the histogram of the full image should be done first
    # so as to get the full dynamic range
    h = histogram(roi, nbins=nbins, omin='omin', omax='omax',
                  locations='loc')

    hist = h['histogram']
    omin = h['omin']
    omax = h['omax']
    loc = h['loc']

    binsz = loc[1] - loc[0]

    total_h = numpy.sum(hist, dtype='float')

    # Normalise the histogram
    norm_h = hist / total_h
    # Or use the pdf??? hist / max(hist) ??

    # Produce the probability image
    # i.e. index into the pdf via the bin location for every pixel
    result = numpy.zeros(array.shape, dtype='float32').ravel()
    h_arr = histogram(array, nbins=nbins, minv=omin, maxv=omax,
                      reverse_indices='ri')
    hist_arr = h_arr['histogram']
    total_hist_arr = numpy.sum(hist_arr, dtype='float')
    norm_hist_arr = hist_arr / total_hist_arr
    ri = h_arr['ri']

    for i in range(norm_hist_arr.shape[0]):
        if norm_hist_arr[i] == 0:
            continue
        result[ri[ri[i]:ri[i+1]]] = norm_h[i] / norm_hist_arr[i]

    return result.reshape(array.shape)
{'fraction_non_alphanumeric': 0.12414800389483933, 'fraction_numerical': 0.007302823758519961, 'mean_word_length': 2.75, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6164118', 'n_tokens_mistral': 723, 'n_tokens_neox': 672, 'n_words': 192}