def execute(path, newChannel):

    img = Image.open(path)
    pixels = img.load()

    list = [[0 for x in range(img.width)] for y in range(img.height)]

    linha = img.width
    coluna = img.height
    pixel = 0
    auxiliar = [0] * 246

    if (linha > 0):
        if ((newChannel > 0) and (newChannel < 128)):
            divisao = 246 / newChannel
            auxiliarValor = 0

            for i in range(0, linha):
                for j in range(0, coluna):
                    pixel = pixels[i, j]
                    auxiliarValor = pixel % (divisao)
                    auxiliarValor = divisao - auxiliarValor - 1
                    pixel = pixel + auxiliarValor
                    list[i][j] = pixel
                    img.putpixel((i, j), pixel)

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    img.save("result.bmp")
Example #2
0
def execute(path):

    img = Image.open(path)
    pixels = img.load()

    list = [[0 for x in range(img.width)] for y in range(img.height)]

    channel = 247

    auxiliar = [0] * channel
    novo = [0] * channel
    ideal = (img.width * img.height) / channel

    for i in range(0, img.width):
        for j in range(0, img.height):

            color = pixels[i, j]
            auxiliar[color] = auxiliar[color] + 1

    auxiliarValor = 0
    for x in range(0, channel):
        auxiliarValor = auxiliarValor + auxiliar[x]
        if (((auxiliarValor / ideal) - 1) > 0):
            novo[x] = (auxiliarValor / ideal) - 1
        else:
            novo[x] = 0

    for i in range(0, img.width):
        for j in range(0, img.height):
            color = pixels[i, j]
            list[i][j] = novo[color]
            img.putpixel((i, j), novo[color])

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    img.save("result.bmp")
def execute(path):

    img = Image.open(path)
    pixels = img.load()

    lines = 3
    columns = 3
    matrix = [[-1 for x in range(columns)] for y in range(lines)]
    list = [[0 for x in range(img.width)] for y in range(img.height)]

    for i in range(0, img.width):
        for j in range(0, img.height):

            totalPixels = 0
            pixelSum = 0
            average = 0.00

            for x in range(0, lines):
                for y in range(0, columns):
                    if (i - 1 + x < 0) or (j - 1 + y < 0) or (
                            i - 1 + x >= img.width) or (j - 1 + y >=
                                                        img.width):
                        matrix[x][y] = -1
                    else:
                        matrix[x][y] = pixels[i - 1 + x, j - 1 + y]
                        totalPixels = totalPixels + 1
                        pixelSum = pixelSum + pixels[i - 1 + x, j - 1 + y]

            average = pixelSum / totalPixels
            list[i][j] = average
            img.putpixel((i, j), average)

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    img.save("result.bmp")
def execute(path):

    img = Image.open(path)
    pixels = img.load()

    lines = 3
    columns = 3
    matrix = [[-1 for x in range(columns)] for y in range(lines)]
    list = [[0 for x in range(img.width)] for y in range(img.height)]

    for i in range(0, img.width):
        for j in range(0, img.height):

            totalPixels = 0
            pixelSum = 0

            mask = ((0, -1, 0), (-1, 4, -1), (0, -1, 0))

            for x in range(0, lines):
                for y in range(0, columns):
                    if (i - 1 + x < 0) or (j - 1 + y < 0) or (
                            i - 1 + x >= img.width) or (j - 1 + y >=
                                                        img.width):
                        matrix[x][y] = -1
                    else:
                        matrix[x][y] = pixels[i - 1 + x, j - 1 + y]

                        pixelSum = pixelSum + (mask[x][y] *
                                               pixels[i - 1 + x, j - 1 + y])

            img.putpixel((i, j), pixelSum)
            list[i][j] = pixelSum

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    img.save("result.bmp")
Example #5
0
def execute(path):

    img = Image.open(path)
    pixels = img.load()
    list = [[0 for x in range(img.width)] for y in range(img.height)]

    for i in range(0, img.width):
        for j in range(0, img.height):
            fator = pixels[i, j]
            if fator > 127:
                img.putpixel((i, j), 246)
                list[i][j] = 246
            else:
                img.putpixel((i, j), 0)
                list[i][j] = 0

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)

    img.save("result.bmp")
Example #6
0
def execute(path):

    img = Image.open(path)
    pixels = img.load()

    lines = 3
    columns = 3
    matrix = [[-1 for x in range(columns)] for y in range(lines)]
    list = [[0 for x in range(img.width)] for y in range(img.height)]

    for i in range(0, img.width):
        for j in range(0, img.height):

            totalPixels = 0
            pixelSum = 0
            popular = 0
            value = 0.00

            pixelList = [0] * 256

            for x in range(0, lines):
                for y in range(0, columns):
                    if (i - 1 + x < 0) or (j - 1 + y < 0) or (
                            i - 1 + x >= img.width) or (j - 1 + y >=
                                                        img.width):
                        matrix[x][y] = -1
                    else:
                        matrix[x][y] = pixels[i - 1 + x, j - 1 + y]
                        totalPixels = totalPixels + 1
                        pixelList[pixels[i - 1 + x, j - 1 +
                                         y]] = pixelList[pixels[i - 1 + x,
                                                                j - 1 + y]] + 1

            for x in range(0, 256):
                if (popular < pixelList[x]):
                    popular = x

            img.putpixel((i, j), popular)
            list[i][j] = popular

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    img.save("result.bmp")
Example #7
0
def execute(path, k):

    img = Image.open(path)
    pixels = img.load()

    lines = 3
    columns = 3
    matrix = [[-1 for x in range(columns)] for y in range(lines)]
    list = [[0 for x in range(img.width)] for y in range(img.height)]

    for i in range(0, img.width):
        for j in range(0, img.height):

            totalPixels = 0
            medium = 0.00
            pixelList = []

            for x in range(0, lines):
                for y in range(0, columns):
                    if (i - 1 + x < 0) or (j - 1 + y < 0) or (
                            i - 1 + x >= img.width) or (j - 1 + y >=
                                                        img.width):
                        matrix[x][y] = -1
                    else:
                        matrix[x][y] = pixels[i - 1 + x, j - 1 + y]
                        totalPixels = totalPixels + 1
                        pixelList.append(pixels[i - 1 + x, j - 1 + y])

            bubbleSort.execute(pixelList)

            if len(pixelList) > k:
                medium = pixelList[k]
            else:
                medium = pixelList[len(pixelList) - 1]

            img.putpixel((i, j), medium)
            list[i][j] = medium

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    img.save("result.bmp")
def execute(path):

    img = Image.open(path)
    imgHorizontal = Image.open(path)
    imgVertical = Image.open(path)
    pixels = img.load()

    lines = 3
    columns = 3
    matrix = [[-1 for x in range(columns)] for y in range(lines)]
    list = [[0 for x in range(img.width)] for y in range(img.height)]
    listHorizontal = [[0 for x in range(img.width)] for y in range(img.height)]
    listVertical = [[0 for x in range(img.width)] for y in range(img.height)]

    for i in range(0, img.width):
        for j in range(0, img.height):

            totalPixels = 0
            pixelSum = 0
            pixelSumX = 0
            pixelSumY = 0
            average = 0.00

            maskX = ((1, 0, 0), (0, -1, 0), (0, 0, 0))
            maskY = ((0, 0, 1), (0, -1, 0), (0, 0, 0))

            for x in range(0, lines):
                for y in range(0, columns):
                    if (i - 1 + x < 0) or (j - 1 + y < 0) or (
                            i - 1 + x >= img.width) or (j - 1 + y >=
                                                        img.width):
                        matrix[x][y] = -1
                    else:
                        matrix[x][y] = pixels[i - 1 + x, j - 1 + y]

                        totalPixels = totalPixels + 1
                        if (maskX[x][y] >= 0):
                            pixelSumX = pixelSumX + (
                                maskX[x][y] * pixels[i - 1 + x, j - 1 + y])
                        else:
                            pixelSumX = pixelSumX - (
                                maskX[x][y] * pixels[i - 1 + x, j - 1 + y])

                        if (maskX[x][y] >= 0):
                            pixelSumY = pixelSumY + (
                                maskY[x][y] * pixels[i - 1 + x, j - 1 + y])
                        else:
                            pixelSumY = pixelSumY - (
                                maskY[x][y] * pixels[i - 1 + x, j - 1 + y])

            if pixelSumX < 0:
                pixelSumX = pixelSumX * -1
            if pixelSumY < 0:
                pixelSumY = pixelSumY * -1
        # pixelSum =  pixelSumX + pixelSumY

        # pixelSumP1 = (matrix[0][0] + 0*matrix[0][1] + 0*matrix[0][2]) - (0*matrix[1][0] + (-1*matrix[1][1]) + 0*matrix[1][2])
        # pixelSumP2 = (0*matrix[0][0] + 0*matrix[0][1] + matrix[0][2]) - (0*matrix[1][0] + (-1*matrix[1][1]) + 0*matrix[1][2])

            pixelSumP1 = (matrix[1][1] - matrix[2][2])
            pixelSumP2 = (matrix[1][2] - matrix[2][1])

            if pixelSumP1 < 0:
                pixelSumP1 = pixelSumP1 * -1
            if pixelSumP2 < 0:
                pixelSumP2 = pixelSumP2 * -1

            pixelSum = pixelSumP1 + pixelSumP2
            img.putpixel((i, j), pixelSum)
            imgHorizontal.putpixel((i, j), pixelSumP1)
            imgVertical.putpixel((i, j), pixelSumP2)
            list[i][j] = pixelSum
            listHorizontal[i][j] = pixelSumP1
            listVertical[i][j] = pixelSumP2

    histograma.saveHistogram('histogram.txt', list, img.width, img.height)
    histograma.saveHistogram('histogramHorizontal.txt', listHorizontal,
                             img.width, img.height)
    histograma.saveHistogram('histogramVertical.txt', listVertical, img.width,
                             img.height)

    img.save("result.bmp")
    imgHorizontal.save("resultHorizontal.bmp")
    imgVertical.save("resultVertical.bmp")