<commit_before>from PIL import Image
import numpy as np
import matplotlib.pyplot as plt


def max_filter(path, regionSize):
    '''
    Filters a given region for max values (Folien 4 Seite 43)
    :param path:
    :param regionSize:
    :return:
    '''




if __name__ == "__main__":<commit_msg>Update max_filter.py<commit_after>from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
import math

def max_filter(path, region_size):
    '''
        Values for every pixel equals to the max of all values in the region
        :param path: path to the image
        :param region_size: size of the region that will be extracted and its median will be calculated
        :return: resulting image
        '''

    # initializing image and other helping variables
    i = Image.open(path)
    image_array = np.asarray(i, dtype=int)
    image_height, image_width = i.size
    half_size = math.floor(region_size / 2)
    resulting_img = np.zeros(image_height * image_width).reshape(image_height, image_width)
    # iterating over the image
    for i in range(half_size, image_height - half_size):

        for j in range(half_size, image_width - half_size):
            # extraction of region of the given size and calculation of its median
            region = (image_array[i - half_size:i + half_size + 1, j - half_size:j + half_size + 1]).ravel()
            resulting_img[i, j] = np.max(region)

    return resulting_img


if __name__ == "__main__":
    max_img = max_filter('lena.png', 3)
    plt.imshow(max_img, cmap='gray', interpolation='nearest')
    plt.show()

{'fraction_non_alphanumeric': 0.08712121212121213, 'fraction_numerical': 0.004419191919191919, 'mean_word_length': 3.149214659685864, 'pattern_counts': {'":': 2, '<': 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': '6396618', 'n_tokens_mistral': 499, 'n_tokens_neox': 485, 'n_words': 163}