<commit_before># -*- coding: utf-8 -*-

import os.path
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage, misc


def weightedAverage(pixel):
    return 0.299*pixel[0] + 0.587*pixel[1] + 0.114*pixel[2]

def show(color_array):
    """ Function to show image"""
    plt.imshow(color_array)
    plt.show()
    plt.axis('off')

def show_gray(gray_array):
    """ Function to show grayscale image"""
    plt.imshow(gray_array, cmap=plt.cm.Greys_r)
    plt.show()
    plt.axis('off')

class Image(object):
    """Class for Image"""

    def __init__(self, fmt, path):
        self.path = os.path.join("image_set", fmt, str(path))
        self.fmt = fmt
        self.array = misc.imread(self.path)
        self.shape = self.array.shape
    
    @property
    def grayScale(self):
        """Grayscale image"""
        grey = np.zeros((self.shape[0], self.shape[1]))
        for row in range(len(self.array)):
            for col in range(len(self.array[row])):
                grey[row][col] = weightedAverage(self.array[row][col])
        self._grayScale = grey
        return self._grayScale

    def get_saturation_image(self):
        red_canal = self.array[:, :, 0]
        green_canal = self.array[:, :, 1]
        blue_canal = self.array[:, :, 2]
        mean = (red_canal + green_canal + blue_canal) / 3
        saturation = np.sqrt(((red_canal - mean)**2 + (green_canal - mean)**2 + (blue_canal - mean)**2)/3)
        return saturation
    
        
    def contrast(self):
        """Function that return the Constrast numpy array"""
        grey = self.grayScale
        contrast = np.zeros((self.shape[0], self.shape[1]))
        grey_extended = np.zeros((self.shape[0]+2, self.shape[1]+2))
        grey_extended[1:self.shape[0]+1,1:self.shape[1]+1]=grey
        kernel = np.array([[ -1,-1, -1 ],
                           [ -1, 8, -1 ],
                            [ -1, -1, -1 ]])
        for row in range(self.shape[0]):
            for col in range(self.shape[1]):
                contrast[row][col] = np.abs((kernel* grey_extended[row:(row+3),col:(col+3)]).sum())
        return contrast
        
    def sobel(self):
        """Function that return the Constrast numpy array"""
        grey = self.grayScale
        sobel_h = np.zeros((self.shape[0], self.shape[1]))
        sobel_v = np.zeros((self.shape[0], self.shape[1]))
        grey_extended = np.zeros((self.shape[0]+2, self.shape[1]+2))
        grey_extended[1:self.shape[0]+1,1:self.shape[1]+1]=grey
        kernel1 = np.array([[ -1,-2, -1 ],
                           [ 0, 0, 0 ],
                            [ 1, 2, 1 ]])
        kernel2 = np.array([[ -1,0, 1 ],
                           [ -2, 0, 2 ],
                            [ -1, 0, -1 ]])
        for row in range(self.shape[0]):
            for col in range(self.shape[1]):
                sobel_h[row][col] = np.abs((kernel1* grey_extended[row:(row+3),col:(col+3)]).sum())
                sobel_v[row][col] = np.abs((kernel2* grey_extended[row:(row+3),col:(col+3)]).sum())
        return sobel_h,sobel_v       
        
<commit_msg>method get_well_exposedness<commit_after># -*- coding: utf-8 -*-

import os.path
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage, misc


def weightedAverage(pixel):
    return 0.299*pixel[0] + 0.587*pixel[1] + 0.114*pixel[2]

def show(color_array):
    """ Function to show image"""
    plt.imshow(color_array)
    plt.show()
    plt.axis('off')

def show_gray(gray_array):
    """ Function to show grayscale image"""
    plt.imshow(gray_array, cmap=plt.cm.Greys_r)
    plt.show()
    plt.axis('off')

class Image(object):
    """Class for Image"""

    def __init__(self, fmt, path):
        self.path = os.path.join("image_set", fmt, str(path))
        self.fmt = fmt
        self.array = misc.imread(self.path)
        self.shape = self.array.shape
    
    @property
    def grayScale(self):
        """Grayscale image"""
        grey = np.zeros((self.shape[0], self.shape[1]))
        for row in range(len(self.array)):
            for col in range(len(self.array[row])):
                grey[row][col] = weightedAverage(self.array[row][col])
        self._grayScale = grey
        return self._grayScale

    def get_saturation_image(self):
        """Function to get the Saturation map"""
        red_canal = self.array[:, :, 0]
        green_canal = self.array[:, :, 1]
        blue_canal = self.array[:, :, 2]
        mean = (red_canal + green_canal + blue_canal) / 3
        saturation = np.sqrt(((red_canal - mean)**2 + (green_canal - mean)**2 + (blue_canal - mean)**2)/3)
        return saturation
    
        
    def contrast(self):
        """Function that return the Constrast numpy array"""
        grey = self.grayScale
        contrast = np.zeros((self.shape[0], self.shape[1]))
        grey_extended = np.zeros((self.shape[0]+2, self.shape[1]+2))
        grey_extended[1:self.shape[0]+1,1:self.shape[1]+1]=grey
        kernel = np.array([[ -1,-1, -1 ],
                           [ -1, 8, -1 ],
                            [ -1, -1, -1 ]])
        for row in range(self.shape[0]):
            for col in range(self.shape[1]):
                contrast[row][col] = np.abs((kernel* grey_extended[row:(row+3),col:(col+3)]).sum())
        return contrast
        
    def sobel(self):
        """Function that return the Constrast numpy array"""
        grey = self.grayScale
        sobel_h = np.zeros((self.shape[0], self.shape[1]))
        sobel_v = np.zeros((self.shape[0], self.shape[1]))
        grey_extended = np.zeros((self.shape[0]+2, self.shape[1]+2))
        grey_extended[1:self.shape[0]+1,1:self.shape[1]+1]=grey
        kernel1 = np.array([[ -1,-2, -1 ],
                           [ 0, 0, 0 ],
                            [ 1, 2, 1 ]])
        kernel2 = np.array([[ -1,0, 1 ],
                           [ -2, 0, 2 ],
                            [ -1, 0, -1 ]])
        for row in range(self.shape[0]):
            for col in range(self.shape[1]):
                sobel_h[row][col] = np.abs((kernel1* grey_extended[row:(row+3),col:(col+3)]).sum())
                sobel_v[row][col] = np.abs((kernel2* grey_extended[row:(row+3),col:(col+3)]).sum())
        return sobel_h,sobel_v       
        
    def get_well_exposedness_image(self):
        """Function to get the Well-Exposedness map"""
        red_canal = self.array[:, :, 0]/255
        green_canal = self.array[:, :, 1]/255
        blue_canal = self.array[:, :, 2]/255
        sigma = 0.2
        red_exp = np.exp(-(red_canal - 0.5)**2/(2*sigma**2))
        green_exp = np.exp(-(green_canal - 0.5) ** 2 / (2 * sigma ** 2))
        blue_exp = np.exp(-(blue_canal - 0.5) ** 2 / (2 * sigma ** 2))
        return red_exp*green_exp*blue_exp

{'fraction_non_alphanumeric': 0.16775340841730882, 'fraction_numerical': 0.031861292234736216, 'mean_word_length': 2.093033913840513, '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': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3531775', 'n_tokens_mistral': 2429, 'n_tokens_neox': 2297, 'n_words': 461}