#!/usr/bin/python 
# -*- coding: utf-8 -*- 

import argparse

def heller(pixel, width, height, maxb, value): 
    ''' change the brightness (percentage) of each pixel '''
    pixel = [0 if p + float(maxb) / 100 * value < 0
            else 255 if p + float(maxb) / 100 * value > 255
            else int(p + float(maxb) / 100 * value) for p in pixel] 
    return pixel


def gamma(img, value=0):
    ''' change the actual brightness of each pixel ''' 
    pass

def binarisieren(img, value=128):
    ''' convert image to real black and white (FFF and 000) ''' 
    pass


def parse_img(img):
    ''' extracts information out of pgm-img '''
    width, height = img[1].split()
    brightness = img[2].strip()
    pixel =''
    for line in img[3:]:
        pixel += line[:-1]
    pixel = [int(p) for p in pixel.split()]
    return width, height, brightness, pixel




if __name__ == '__main__': 

    parser = argparse.ArgumentParser(description='Change pixelvalues of greyscale images.')
    parser.add_argument('function', help='gamma, heller or binarisieren')
    parser.add_argument('value', type=float, help='factor to change image')
    parser.add_argument('input', type=str, help='input filename')
    parser.add_argument('output', type=str, help='output filname')
    parser.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true')
    args = parser.parse_args()

    with open(args.input) as f: 
        img = f.readlines()
        img = [int(v) for v in [l for l in img[3:]].split()]
        print img 
        width, height, maxb, pixel = parse_img(img)


    if args.function == 'heller': 
        img = heller(pixel, width, height, maxb, args.value)
        save(img, args.output)

    if args.function == 'gamma':
        gamma(img, args.value)

    if args.function == 'binarisieren': 
        binarisieren(img, args.value)




fcdfbd0329be64ba149222c8bce1ff246bd3573a
#!/usr/bin/python 
# -*- coding: utf-8 -*- 

import argparse

def heller(pixel, width, height, maxb, value): 
    ''' change the brightness (percentage) of each pixel '''
    pixel = [0 if p + float(maxb) / 100 * value < 0
            else 255 if p + float(maxb) / 100 * value > 255
            else int(p + float(maxb) / 100 * value) for p in pixel] 
    return pixel


def gamma(img, value=0):
    ''' change the actual brightness of each pixel ''' 
    pass

def binarisieren(img, value=128):
    ''' convert image to real black and white (FFF and 000) ''' 
    pass


def parse_img(img):
    ''' extracts information out of pgm-img '''
    width, height = img[1].split()
    brightness = img[2].strip()
    pixel =''
    for line in img[3:]:
        pixel += line[:-1]
    pixel = [int(p) for p in pixel.split()]
    return width, height, brightness, pixel




if __name__ == '__main__': 

    parser = argparse.ArgumentParser(description='Change pixelvalues of greyscale images.')
    parser.add_argument('function', help='gamma, heller or binarisieren')
    parser.add_argument('value', type=float, help='factor to change image')
    parser.add_argument('input', type=str, help='input filename')
    parser.add_argument('output', type=str, help='output filname')
    parser.add_argument('-v', '--verbose', help='increase output verbosity', action='store_true')
    args = parser.parse_args()

    with open(args.input) as f: 
        img = f.readlines()
        img = [int(v) for v in [l for l in img[3:]].split()]
        print img 
        width, height, maxb, pixel = parse_img(img)


    if args.function == 'heller': 
        img = heller(pixel, width, height, maxb, args.value)
        save(img, args.output)

    if args.function == 'gamma':
        gamma(img, args.value)

    if args.function == 'binarisieren': 
        binarisieren(img, args.value)



