예제 #1
0
def brightness(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    change = input(
        "How much should the brightness be altered? Positive and negative integers are both valid. "
    )
    for x in range(w):
        for y in range(h):
            red = pic.getPixelRed(x, y)
            pic2.setPixelRed(x, y, red + change)
            blue = pic.getPixelBlue(x, y)
            pic2.setPixelBlue(x, y, blue + change)
            green = pic.getPixelGreen(x, y)
            pic2.setPixelGreen(x, y, green + change)
            if red > 256:
                red = 256
            if red < 0:
                red = 0
            if blue > 256:
                blue = 256
            if blue < 0:
                blue = 0
            if green > 256:
                green = 256
            if green < 0:
                green = 0
    pic2.display()
    raw_input()
예제 #2
0
def posterize(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    for x in range(w):
        for y in range(h):
            red = pic.getPixelRed(x, y)
            green = pic.getPixelGreen(x, y)
            blue = pic.getPixelBlue(x, y)
            rc = red % 32
            if rc < 16:
                red = red - rc
            else:
                red = red - rc + 32
            pic2.setPixelRed(x, y, red)
            bc = blue % 32
            if bc < 16:
                blue = blue - bc
            else:
                blue = blue - bc + 32
            pic2.setPixelBlue(x, y, blue)
            gc = green % 32
            if gc < 16:
                green = green - gc
            else:
                green = green - gc + 32
            pic2.setPixelGreen(x, y, green)
    pic2.display()
    raw_input()
예제 #3
0
def Copier(pic,w,h):
    pic = picture2.Picture("crayons.bmp")
    w = pic.getWidth()
    h = pic.getHeight()
    Copy = picture2.Picture(w,h)
    for i in range(0,(w-1)):
        for j in range(0, (h-1)):
            r,g,b = pic.getPixelColor(i,j)
            Copy.setPixelColor(i,j,r,g,b)
    return(Copy)
예제 #4
0
def frame(pic):

    pic = picture2.Picture("crayons.bmp")
    W = pic.getWidth()
    H = pic.getHeight()
    pic2 = picture2.Picture(W, H)
    for j in range(5, H - 5):
        for i in range(5, W - 5):
            r, g, b = pic.getPixelColor(i, j)
            pic2.setPixelColor(i, j, r, g, b)
    return pic2
예제 #5
0
def rotate(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    for x in range(w):
        for y in range(h):
            red = pic.getPixelRed(x, y)
            pic2.setPixelRed(w - x - 1, h - y - 1, red)
            blue = pic.getPixelBlue(x, y)
            pic2.setPixelBlue(w - x - 1, h - y - 1, blue)
            green = pic.getPixelGreen(x, y)
            pic2.setPixelGreen(w - x - 1, h - y - 1, green)
    pic2.display()
    raw_input()
예제 #6
0
def channels(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    for x in range(w):
        for y in range(h):
            red = pic.getPixelRed(x, y)
            green = pic.getPixelGreen(x, y)
            blue = pic.getPixelBlue(x, y)
            pic2.setPixelRed(x, y, blue)
            pic2.setPixelBlue(x, y, green)
            pic2.setPixelGreen(x, y, red)
    pic2.display()
    raw_input()
예제 #7
0
def negative(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    for x in range(w):
        for y in range(h):
            red = pic.getPixelRed(x, y)
            pic2.setPixelRed(x, y, 256 - red)
            green = pic.getPixelGreen(x, y)
            pic2.setPixelGreen(x, y, 256 - green)
            blue = pic.getPixelBlue(x, y)
            pic2.setPixelBlue(x, y, 256 - blue)
    pic2.display()
    raw_input()
예제 #8
0
def blur(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    for x in range(w):
        for y in range(h):
            try:
                num = 9
                red1 = pic.getPixelRed(x, y)
                red2 = pic.getPixelRed(x - 1, y)
                red3 = pic.getPixelRed(x - 1, y - 1)
                red4 = pic.getPixelRed(x, y - 1)
                red5 = pic.getPixelRed(x + 1, y)
                red6 = pic.getPixelRed(x + 1, y + 1)
                red7 = pic.getPixelRed(x, y + 1)
                red8 = pic.getPixelRed(x + 1, y - 1)
                red9 = pic.getPixelRed(x - 1, y - 1)
                red = (red1 + red2 + red3 + red4 + red5 + red6 + red7 + red8 +
                       red9) // num
                pic2.setPixelRed(x, y, red)
                num = 9
                Green1 = pic.getPixelGreen(x, y)
                Green2 = pic.getPixelGreen(x - 1, y)
                Green3 = pic.getPixelGreen(x - 1, y - 1)
                Green4 = pic.getPixelGreen(x, y - 1)
                Green5 = pic.getPixelGreen(x + 1, y)
                Green6 = pic.getPixelGreen(x + 1, y + 1)
                Green7 = pic.getPixelGreen(x, y + 1)
                Green8 = pic.getPixelGreen(x + 1, y - 1)
                Green9 = pic.getPixelGreen(x - 1, y - 1)
                Green = (Green1 + Green2 + Green3 + Green4 + Green5 + Green6 +
                         Green7 + Green8 + Green9) // num
                pic2.setPixelGreen(x, y, Green)
                num = 9
                Blue1 = pic.getPixelBlue(x, y)
                Blue2 = pic.getPixelBlue(x - 1, y)
                Blue3 = pic.getPixelBlue(x - 1, y - 1)
                Blue4 = pic.getPixelBlue(x, y - 1)
                Blue5 = pic.getPixelBlue(x + 1, y)
                Blue6 = pic.getPixelBlue(x + 1, y + 1)
                Blue7 = pic.getPixelBlue(x, y + 1)
                Blue8 = pic.getPixelBlue(x + 1, y - 1)
                Blue9 = pic.getPixelBlue(x - 1, y - 1)
                Blue = (Blue1 + Blue2 + Blue3 + Blue4 + Blue5 + Blue6 + Blue7 +
                        Blue8 + Blue9) // num
                pic2.setPixelBlue(x, y, Blue)
            except Exception as wrong:
                type(wrong)
                str(wrong)
    pic2.display()
    raw_input()
예제 #9
0
def grayscale(fileName, w, h):
    pic = picture2.Picture(fileName)
    pic2 = picture2.Picture(w, h)
    for x in range(w):
        for y in range(h):
            red = pic.getPixelRed(x, y)
            green = pic.getPixelGreen(x, y)
            blue = pic.getPixelBlue(x, y)
            grey = (red + blue + green) // 3
            pic2.setPixelRed(x, y, grey)
            pic2.setPixelGreen(x, y, grey)
            pic2.setPixelBlue(x, y, grey)
    pic2.display()
    raw_input()
예제 #10
0
def zoom(w, h, pic):
    pic2 = picture2.Picture(w / 2, h / 2)
    for x in range(w / 4, (3 * w) / 4):
        for y in range(h / 4, (3 * h) / 4):
            r, g, b = pic.getPixelColor(x, y)
            pic2.setPixelColor(x - (w / 4), y - (h / 4), r, g, b)
    picZoom = picture2.Picture(w, h)
    for x in range(0, w):
        if x % 2 == 0 and x != w:
            for y in range(0, h - 1):
                r, g, b = pic2.getPixelColor(x / 2, y / 2)
                picZoom.setPixelColor(x, y, r, g, b)
                picZoom.setPixelColor(x + 1, y + 1, r, g, b)
    return picZoom
예제 #11
0
def colorBlindRed(pic):
    pic = picture2.Picture("crayons.bmp")
    w = pic.getWidth()
    h = pic.getHeight()
    pic2 = picture2.Picture(w, h)
    for j in range(0, h - 1):
        for i in range(0, w - 1):
            g = pic.getPixelGreen(i, j)
            b = pic.getPixelBlue(i, j)
            r = 0
            pic2.setPixelGreen(i, j, g)
            pic2.setPixelBlue(i, j, b)
            pic2.setPixelRed(i, j, r)
    return pic2
예제 #12
0
def flip(pic, w, h):
    pic2 = picture2.Picture(w, h)
    for j in range(h):
        for i in range(w):
            R, G, B = pic.getPixelColor(w-1-i, j)
            pic2.setPixelColor(i, j, R, G, B)
    return pic2
예제 #13
0
def copy(pic,W,H):
    pic2 = picture2.Picture(W,H)
    for y in range(H):
        for x in range(W):
            r,g,b = pic.getPixelColor(x,y)
            pic2.setPixelColor(x,y,r,g,b)
    return pic2
예제 #14
0
def copy(pic, w, h):
    picCopy = picture2.Picture(w, h)
    for i in range(0, w-1):
        for j in range(0, h-1):
            r, g, b = pic.getPixelColor(i,j)
            picCopy.setPixelColor(i, j, r, g, b)
    return picCopy
예제 #15
0
def gOOgley(pic):

    pic2 = picture2.Picture(w, h)
    picCopy(pic2)
    for y in range(0, h - 7, 6):
        for x in range(0, w - 7, 6):
            nine = 0
            rRR = 0
            bBB = 0
            gGG = 0
            for k in range(0, 3):
                for j in range(0, 3):

                    getR = pic2.getPixelRed(x + k, y + j)
                    getB = pic2.getPixelBlue(x + k, y + j)
                    getG = pic2.getPixelGreen(x + k, y + j)

                    rRR = rRR + getR
                    bBB = bBB + getB
                    gGG = gGG + getG

                    nine = nine + 1

                    getR = rRR / nine
                    getB = bBB / nine
                    getG = gGG / nine

            for k in range(0, 6):
                for j in range(0, 6):

                    pic.setPixelBlue(x + k, y + j, getB)
                    pic.setPixelRed(x + k, y + j, getR)
                    pic.setPixelGreen(x + k, y + j, getG)
예제 #16
0
 def Contrast(picEdit):
     pic = picEdit
     w = pic.getWidth()
     h = pic.getHeight()
     picNew = picture2.Picture(w, h)
     for i in range(0, h):
         for j in range(0, w):
             x = j
             y = i
             [r, g, b] = pic.getPixelColor(x, y)
             P = [r, g, b]
             C = []
             for e in P:
                 v = e
                 if (v > 128):
                     d = v - 128
                     c = (v + d)
                     C = C + [c]
                 elif (v <= 128):
                     d = 128 - v
                     c = (v - d)
                     C = C + [c]
             rCont = C[0]
             gCont = C[1]
             bCont = C[2]
             picNew.setPixelColor(x, y, rCont, gCont, bCont)
     return picNew
예제 #17
0
 def Posterize(picEdit):
     pic = picEdit
     w = pic.getWidth()
     h = pic.getHeight()
     picNew = picture2.Picture(w, h)
     for i in range(0, h):
         for j in range(0, w):
             x = j
             y = i
             [r, g, b] = pic.getPixelColor(x, y)
             P = [r, g, b]
             C = []
             for e in P:
                 p = e // 32
                 multLess = p * 32
                 multGreat = (multLess + 32)
                 mLdist = (e - multLess)
                 mGdist = (multGreat - e)
                 if (mLdist < mGdist):
                     C = C + [multLess]
                 else:
                     C = C + [multGreat]
             rPost = C[0]
             gPost = C[1]
             bPost = C[2]
             picNew.setPixelColor(x, y, rPost, gPost, bPost)
     return picNew
예제 #18
0
def zoom(pic):
    w = pic.getWidth()
    h = pic.getHeight()
    pic2 = picture2.Picture("crayons.bmp")
    for x in range(0, w - 1):
        for y in range(0, h - 1):
            if x % 2 == 0 and y % 2 == 0:
                r = pic2.getPixelRed(w / 4 - 1 + x / 2, h / 4 - 1 + y / 2)
                g = pic2.getPixelGreen(w / 4 - 1 + x / 2, h / 4 - 1 + y / 2)
                b = pic2.getPixelBlue(w / 4 - 1 + x / 2, h / 4 - 1 + y / 2)
            if x % 2 == 1 and y % 2 == 0:
                r = pic2.getPixelRed(w / 4 - 1 + (x - 1) / 2,
                                     h / 4 - 1 + y / 2)
                g = pic2.getPixelGreen(w / 4 - 1 + (x - 1) / 2,
                                       h / 4 - 1 + y / 2)
                b = pic2.getPixelBlue(w / 4 - 1 + (x - 1) / 2,
                                      h / 4 - 1 + y / 2)
            if x % 2 == 0 and y % 2 == 1:
                r = pic2.getPixelRed(w / 4 - 1 + x / 2,
                                     h / 4 - 1 + (y - 1) / 2)
                g = pic2.getPixelGreen(w / 4 - 1 + x / 2,
                                       h / 4 - 1 + (y - 1) / 2)
                b = pic2.getPixelBlue(w / 4 - 1 + x / 2,
                                      h / 4 - 1 + (y - 1) / 2)
            if x % 2 == 1 and y % 2 == 1:
                r = pic2.getPixelRed(w / 4 - 1 + (x - 1) / 2,
                                     h / 4 - 1 + (y - 1) / 2)
                g = pic2.getPixelGreen(w / 4 - 1 + (x - 1) / 2,
                                       h / 4 - 1 + (y - 1) / 2)
                b = pic2.getPixelBlue(w / 4 - 1 + (x - 1) / 2,
                                      h / 4 - 1 + (y - 1) / 2)
            pic.setPixelColor(x, y, r, g, b)
    return pic
예제 #19
0
def CopyPic(pic, width, height):
    picCopy = picture2.Picture(width, height)
    for x in range(width):
        for y in range(height):
            red, blue, green = pic.getPixelColor(x, y)
            picCopy.setPixelColor(x, y, red, blue, green)
    return picCopy
예제 #20
0
def main():
    print "Welcome to my Image Editor!"
    pic = picture2.Picture("crayons.bmp")
    pic.display()
    print"Please choose from the following options and put your response in quotes:"
    print"flip"
    print"mirror"
    print"scoll"
    print"negative"
    print"grayscale"
    print"cycle color"
    print"zoom"
    print"posterize"
    print"change brightness"
    print"increase the contrast"
    print"rotate 180 degrees"
    print"collide"
    print"shadowize"
    w = pic.getWidth()
    h = pic.getHeight()
    pic1 = createcopy(pic,w,h)
    pic2 = createcopy(pic,w,h)
    cont = "yes"
    while cont == "yes" or cont == "Yes":
            command(pic,pic1,pic2,w,h)
예제 #21
0
def outlines(pic):
    posterize(pic)
    
    w = pic.getWidth()
    h = pic.getHeight()
    
    pic2 = picture2.Picture(w,h)
    pic2 = copyImage(pic,pic2)
    
    oldred,oldgreen,oldblue = pic.getPixelRed(0,0),pic.getPixelGreen(0,0),pic.getPixelBlue(0,0)
    
    for x in range(1,w-1):
        for y in range(1,h-1):
            newred = pic2.getPixelRed(x,y)
            newgreen = pic2.getPixelGreen(x,y)
            newblue = pic2.getPixelBlue(x,y)
            if newred != oldred or newgreen != oldgreen or newblue != oldblue:
                pic.setPixelColor(x,y,0,0,0)
                oldred,oldgreen,oldblue = newred,newgreen,newblue
            
    for y in range(1,h-1):
        for x in range(1,w-1):
            newred = pic2.getPixelRed(x,y)
            newgreen = pic2.getPixelGreen(x,y)
            newblue = pic2.getPixelBlue(x,y)
            
            if newred != oldred or newgreen != oldgreen or newblue != oldblue:
                pic.setPixelColor(x,y,0,0,0)
                oldred,oldgreen,oldblue = newred,newgreen,newblue
예제 #22
0
def zoom(pic, w, h): 
    pic2 = picture2.Picture(w, h)
    for i in range(w):
        for j in range(h):
            R, G, B = pic.getPixelColor(w/4 + i//2, h/4 + j//2)
            pic2.setPixelColor(i, j, R, G, B)
    return pic2
예제 #23
0
def Bright(pic):
    W=pic.getWidth()
    H=pic.getHeight()
    bright=picture2.Picture(W,H)
    a=input("How much would you like to adjust the brightness?")
    for x in range (0,W):
        for y in range (0,H):
            (r,g,b)=pic.getPixelColor(x,y)


            if r+a<=0:
                R=0
            if r+a>=255:
                R=255
            else:
                R=r+a
            if b+a<=0:
                B=0
            if b+a>=255:
                B=255
            else:
                B=b+a
            if g+a<=0:
                G=0
            if g+a>=255:
                G=255
            else:
                G=g+a
            bright.setPixelColor(x,y,R,G,B)
    return (bright)
예제 #24
0
def copy(pic, W, H):
    picCopy = picture2.Picture(W, H)
    for j in range(0, H):
        for i in range(0, W):
            r, g, b = pic.getPixelColor(i, j)
            picCopy.setPixelColor(i, j, r, g, b)
    return picCopy
예제 #25
0
 def Scroll(picEdit):
     pic = picEdit
     uI = eval(raw_input("Please enter a number of pixels: "))
     userInput = uI
     i = 1
     while (i == 1):
         try:
             n = userInput
             w = pic.getWidth()
             h = pic.getHeight()
             picNew = picture2.Picture(w, h)
             for i in range(0, h):
                 for j in range(0, w):
                     x = j
                     y = i
                     (r, g, b) = pic.getPixelColor(x, y)
                     s = (x + n)
                     if (s < w):
                         picNew.setPixelColor(s, y, r, g, b)
                     else:
                         picNew.setPixelColor((s - w), y, r, g, b)
             return picNew
         except IndexError:
             errInd = eval(
                 raw_input("You entered too high a number! Try again: "))
             userInput = errInd
         except:
             errGen = eval(
                 raw_input("Sorry, something went wrong! Try again: "))
             userInput = errGen
예제 #26
0
def picCopy(w, h, pic):
    pic2 = picture2.Picture(w, h)
    for y in range(h - 1):
        for x in range(w - 1):
            r1, g1, b1 = pic.getPixelColor(x, y)
            pic2.setPixelColor(x, y, r1, g1, b1)
    return pic2
예제 #27
0
 def Brightness(picEdit):
     pic = picEdit
     w = pic.getWidth()
     h = pic.getHeight()
     picNew = picture2.Picture(w, h)
     n = eval(raw_input("Please enter a positive or negative number: "))
     for i in range(0, h):
         for j in range(0, w):
             x = j
             y = i
             [r, g, b] = pic.getPixelColor(x, y)
             P = [r, g, b]
             C = []
             for e in P:
                 c = e + n
                 if (c < 0):
                     C = C + [0]
                 if (c > 255):
                     C = C + [255]
                 else:
                     C = C + [e + n]
             rBright = C[0]
             gBright = C[1]
             bBright = C[2]
             picNew.setPixelColor(x, y, rBright, gBright, bBright)
     return picNew
예제 #28
0
def scroll(pic):
    goodInput = False
    while not goodInput:
        try:
            scrollpix = input(
                "How many pixels do you want the image shifted to the right?  "
            )
            goodInput = True
        except Exception as e:
            print
            print
            print "Something went wrong.. Make sure you only enter an integer! Try again."
            print
            print(type(e))
            print(str(e))
            print

    pic2 = picture2.Picture(w, h)
    picCopy(pic2)
    for y in range(0, h - 1):
        for x in range(0, w - 1):
            getR = pic2.getPixelRed(x, y)
            getB = pic2.getPixelBlue(x, y)
            getG = pic2.getPixelGreen(x, y)

            if x + scrollpix > w - 1:
                x = (x + scrollpix) - (w - 1)
            else:
                x = x + scrollpix

            pic.setPixelBlue(x, y, getB)
            pic.setPixelRed(x, y, getR)
            pic.setPixelGreen(x, y, getG)
    return pic
예제 #29
0
 def Neon(picEdit):
     pic = picEdit
     w = pic.getWidth()
     h = pic.getHeight()
     picNew = picture2.Picture(w, h)
     for i in range(0, h):
         for j in range(0, w):
             x = j
             y = i
             [r, g, b] = pic.getPixelColor(x, y)
             P = [r, g, b]
             C = []
             for e in P:
                 v = e
                 if (v < 128):
                     p = (128 - v)
                     C = C + [e - p]
                 if (v > 128):
                     p = (v - 128)
                     C = C + [e - p]
                 else:
                     C = C + [e]
             rNeon = C[0]
             gNeon = C[1]
             bNeon = C[2]
             picNew.setPixelColor(x, y, rNeon, gNeon, bNeon)
     return picNew
예제 #30
0
def chickenpox(pic):
    rRR = 0
    bBB = 0
    gGG = 0
    nine = 0
    pic2 = picture2.Picture(w, h)
    picCopy(pic2)
    for y in range(0, h - 1, h / 40):

        for x in range(0, w - 1, 3):
            for k in range(0, 3):
                for j in range(0, 3):

                    getR = pic2.getPixelRed(x + k, y + j)
                    getB = pic2.getPixelBlue(x + k, y + j)
                    getG = pic2.getPixelGreen(x + k, y + j)

                    rRR = rRR + getR
                    bBB = bBB + getB
                    gGG = gGG + getG

                    nine = nine + 2

                    getR = rRR // nine * nine
                    getB = getB // nine * nine
                    getG = getG // nine * nine

                    getR = (getR // 100) * 100
                    getB = (getB // 100) * 100
                    getG = (getG // 100) * 100
            pic.setPixelBlue(x, y, getB)
            pic.setPixelRed(x, y, getR)
            pic.setPixelGreen(x, y, getG)
    return pic