Exemple #1
0
def enlarge(input_img, output_img):
    img = image.Image(input_img)
    
    scale = ""
    while scale == "":
        try:
            scale = int(input("How big do you want the new picture compared to the original? "))
        except ValueError:
            print("Error: You must enter an integer!")
            
    width = img.getWidth()
    height = img.getHeight()
    newimg = image.EmptyImage(width*scale,height*scale)    

    for col in range(width):
        for row in range(height):
            px = img.getPixel(col,row)
            newimg.setPixel(col*scale,row*scale,px)
            for x in range(1,scale):
                for y in range(1, scale):
                    newimg.setPixel(col*scale + x,row*scale,px)
                    newimg.setPixel(col*scale,row*scale + y,px)
                    newimg.setPixel(col*scale + x,row*scale + y,px)

    newimg.saveTk(output_img)
Exemple #2
0
def pixelMapper(image, pMapping):

    img = cImage.Image(image)
    newimg = cImage.EmptyImage(img.getWidth(), img.getHeight())
    win = cImage.ImageWin()

    for col in range(img.getWidth()):
        for row in range(img.getHeight()):
            p = img.getPixel(col, row)

            red = p.getRed()
            green = p.getGreen()
            blue = p.getBlue()
            new_value = (red + green + blue) / 3
            white = cImage.Pixel(255, 255, 255)
            black = cImage.Pixel(0, 0, 0)
            pMapping = cImage.Pixel(128, 128, 128)

            if new_value < (255 / 3):
                newimg.setPixel(col, row, black)
            elif new_value > (255 / 3) and new_value < (255 * 2) / 3:
                newimg.setPixel(col, row, pMapping)
            else:
                newimg.setPixel(col, row, white)

    newimg.draw(win)
Exemple #3
0
def pixel_grigi(immagine, lista):
    img = image.Image(immagine)
    for riga in range(img.getHeight()):
        for colonna in range(img.getWidth()):
            p = img.getPixel(colonna, riga)
            media = (p.getRed() + p.getGreen() + p.getBlue()) // 3
            lista[media] += 1
def load(img):
    img = image.Image(img)
    iDim = img.getWidth(), img.getHeight()
    newimg = image.EmptyImage(iDim[0], iDim[1])

    win = image.ImageWin(iDim[0], iDim[1])

    # newimg.setDelay(0) #no animation
    # newimg.setDelay(1,100) #animated
    print "Loading..."
    for y in range(iDim[1]):
        for x in range(iDim[0]):
            #pix = img.getPixel(x, y)

            # try calling a function here to change the rgb values
            # maybe call function from image.Pixel

            newb = Filter.invert(img, x, y)
            newpixel = image.Pixel(newb[0], newb[1], newb[2])
            newimg.setPixel(x, y, newpixel)
        newimg.draw(
            win
        )  #remove this for no animation, chrome sees it as frozen (is not)
    sys('cls')
    newimg.draw(win)
    win.exitonclick()
Exemple #5
0
def change_pixels():
    img = image.Image("Husky.gif")
    img2 = image.EmptyImage(img.getWidth(), img.getHeight())

    win = image.ImageWin()
    win2 = image.ImageWin()

    for y in range(img.getHeight()):
        for x in range(img.getWidth()):
            pix = img.getPixel(x, y)

            red = pix.getRed()
            green = pix.getGreen()
            blue = pix.getBlue()

            brightness = int(red + green + blue)

            if brightness >= 470:
                new_pix = image.Pixel(
                    254, 228, 169)  #converts pixels to new color scheme
            elif brightness >= 370:  # depending on brightness.
                new_pix = image.Pixel(112, 152, 162)
            elif brightness >= 270:
                new_pix = image.Pixel(215, 26, 33)
            else:
                new_pix = image.Pixel(0, 50, 77)

            img2.setPixel(x, y, new_pix)  #puts appropriate color into pixel

    img.draw(win)
    img2.draw(win2)
    win.exitonclick()
    win2.exitonclick()
Exemple #6
0
def convolution(filename):
    img = image.Image(filename)
    win = image.ImageWin(img.getWidth(), img.getHeight())
    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p = img.getPixel(col, row)
            oldpixel = image.Pixel(p.getRed(), p.getGreen(), p.getBlue())
            pixel_list = []
            if ((col and row) > 0) and (col + 1 < img.getWidth()) and (
                    row + 1 < img.getHeight()
            ):  #working with all but the edges for simplicity
                for nearcol in range(col, col + 2):
                    for nearrow in range(row, row + 2):
                        nearp = img.getPixel(nearcol, nearrow)
                        greynearp = greyscale(nearp)
                        greypvalue = greynearp.getRed()
                        pixel_list = pixel_list + [greypvalue]
                    print('start', pixel_list, 'end')
                nearmatrix = int(pixel_list[0]) + int(pixel_list[1]) * 0 - int(
                    pixel_list[2])
                print(nearmatrix)
                outputpixel = image.Pixel(255 - nearmatrix, 255 - nearmatrix,
                                          255 - nearmatrix)
                #print(outputpixel)
                img.setPixel(col, row, outputpixel)
                #print(pixel_list)
            else:
                img.setPixel(col, row, oldpixel)
    img.draw(win)
    win.exitonclick()
def black_white(pic):

    image = cImage.Image(pic)  #Creates image object using the golden pic

    w = image.getWidth()  #Get height and width
    h = image.getHeight()

    window = cImage.ImageWin(pic, w,
                             h)  #Makes a window for the pic to show up in

    image.draw(window)  #Draw the image in

    for col in range(w):  #Nested iteration to cover all pixels
        for row in range(h):
            pixel = image.getPixel(col, row)  #Get pixel
            red = pixel.getRed()  #Get each color value of the pixel
            green = pixel.getGreen()
            blue = pixel.getBlue()
            average = (red + green + blue
                       ) / 3  #Get the average so it will be black and white
            average = int(average)  #Convert float to int

            pixel.red = average  #Change each color value of the pixel
            pixel.green = average
            pixel.blue = average
            image.setPixel(col, row,
                           pixel)  #Apply the new color value to the pixel

    new_window = cImage.ImageWin(
        pic, w, h)  #Makes a new window for the new pic to show up in

    image.draw(new_window)  #Draw image with shitty quality

    window.exitOnClick()  #Must close window before closing new_window
    new_window.exitOnClick()
def sepia():
    img = cImage.Image("elliot.gif")

    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p = img.getPixel(col, row)
            newRed = int((.393 * p.getRed()) + (.769 * p.getGreen()) +
                         (.189 * p.getBlue()))
            newGreen = int((.349 * p.getRed()) + (.686 * p.getGreen()) +
                           (.168 * p.getBlue()))
            newBlue = int((.272 * p.getRed()) + (.534 * p.getGreen()) +
                          (.131 * p.getBlue()))
            if newRed > 255:
                newRed = 255
            elif newRed < 0:
                newRed = 0
            if newGreen > 255:
                newGreen = 255
            elif newGreen < 0:
                newGreen = 0
            if newBlue > 255:
                newBlue = 255
            elif newBlue < 0:
                newBlue = 0
            newPixel = cImage.Pixel(newRed, newGreen, newBlue)
            img.setPixel(col, row, newPixel)
    img.draw(win)
Exemple #9
0
def enlarge_image(pic):

    img = cImage.Image(pic)

    w = img.getWidth()
    h = img.getHeight()

    win = cImage.ImageWin(img,w,h)

    img.draw(win)

    img_large = cImage.EmptyImage(w*2,h*2)              #Make new large image

    win_large = cImage.ImageWin(img_large, w*2, h*2)        #Make window for new large image

    for col in range (w):                   #Nested iteration
        for row in range (h):
            
            pixel = img.getPixel(col,row)       #Get pixel

            img_large.setPixel(col*2, row*2, pixel)             #Set same pixel on 4 different spots next to
            img_large.setPixel(col*2+1, row*2, pixel)       #each other on the large image
            img_large.setPixel(col*2, row*2+1, pixel)
            img_large.setPixel(col*2+1, row*2+1, pixel)

    img_large.draw(win_large)                                           #Draw large image on large window

    return(img_large)
Exemple #10
0
def pos(file_name):
    """Displays the positive version of the chosen picture."""
    import cImage
    img = cImage.Image(file_name)
    width = img.getWidth()
    height = img.getHeight()
    win = cImage.ImageWin(width, height)
    return img.draw(win)
def gScale():
    img = cImage.Image("elliot.gif")

    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p = img.getPixel(col, row)
            newCol = int((p.getRed() + p.getGreen() + p.getBlue()) / 3)
            newPixel = cImage.Pixel(newCol, newCol, newCol)
            img.setPixel(col, row, newPixel)
    img.draw(win)
def red():
    img = cImage.Image("elliot.gif")

    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p = img.getPixel(col, row)
            newRed = 255 - p.getRed()
            newPixel = cImage.Pixel(newRed, p.getGreen(), p.getBlue())
            img.setPixel(col, row, newPixel)
    img.draw(win)
Exemple #13
0
 def __init__(self, img_file, draw=1):
     "Initialize image, clone it, get its size and create a canvas"
     self.img_file = img_file
     self.oldimg = image.Image(self.img_file)
     self.width = self.oldimg.getWidth()
     self.height = self.oldimg.getHeight()
     self.newimg = self.oldimg.copy()
     # Decides whether to skip drawing the image in a popup window.
     self.draw = draw
     if self.draw:
         self.win = image.ImageWin(self.img_file, self.width, self.height)
Exemple #14
0
	def compatibility(self):

		img = image.Image(self.imagesource)
		imgHeight = img.getHeight()
		imgWidth = img.getWidth() 

		'''
		Minimum dimensions
			Height : 32
			Width  : 32
		'''

		if (imgHeight < 32) or (imgWidth < 32) :
			sys.exit("\n!! Error : Source image not compatible [minimum dimension -> 32 x 32] \n")			

		headerHeight = math.floor(imgHeight / 10)
		textHeight = imgHeight - headerHeight
		textWidth = imgWidth

		totalEncodableLength = textWidth * textHeight

		'''
		If image was already steganized, caution-prompt displayed
		'''

		'''
		Fill this variable with runLengthEncoded 'stegan' , key used to tell decoder or encoder that image contains data

		'''

		match_SteganSymbol=0

		for row in range(0,1) :
			for column in range (1,19) :
				pix = img.getPixel(column,row)
				pixR = format(pix.getRed(), '#10b')[2:]
				pixG = format(pix.getGreen(), '#10b')[2:]
				pixB = format(pix.getBlue(), '#10b')[2:]

				#print("R: %s G: %s B: %s" % (bin(pixR)[2:],bin(pixG)[2:],bin(pixB)[2:]))
				runLength_SteganSymbol = (int(pixR[6]) * 8) + (int(pixR[7]) * 4) + (int(pixG[6]) * 2) + (int(pixG[7]) * 1)
				value_SteganSymbol = int(pixB[7])

				if (runLength_SteganSymbol == self.steganSymbolArray[column-1]['runlength']) and (value_SteganSymbol == self.steganSymbolArray[column-1]['value']) : 
					match_SteganSymbol = match_SteganSymbol + 1
				else : 
					break

		#print("Number of matches : %d" % match_SteganSymbol)
		if not self.forceoption :
			if match_SteganSymbol == 18 :
				sys.exit("\n!! Error : Image already contains steganized data [Use '-force' to force new steganization] \n")

		return totalEncodableLength
Exemple #15
0
def main():
    """This function defines the window, the original image, and its width and height."""

    #old image values
    window = image.ImageWin()
    oldimg = image.Image("spacetacocat.gif")
    width = oldimg.getWidth()
    height = oldimg.getHeight()

    #calls drawImage function
    drawImage(width, height, oldimg, window)
Exemple #16
0
def flip_vertical(input_img, output_img):
    img = image.Image(input_img)
    width = img.getWidth()
    height = img.getHeight()
    newimg = image.EmptyImage(width,height)
    
    for col in range(width):
        for row in range(height):
            px = img.getPixel(col,height - 1 - row)
            newimg.setPixel(col,row,px)
    
    newimg.saveTk(output_img)  
Exemple #17
0
def flip_horizontal(input_img, output_img):
    #TODO
    img = image.Image(input_img)
    width = img.getWidth()
    height = img.getHeight()
    newimg = image.EmptyImage(width, height)

    for col in range(width):
        for row in range(height):
            i = width - col - 1
            px = img.getPixel(i, row)
            newimg.setPixel(col, row, px)

    newimg.saveTk(output_img)
Exemple #18
0
def main():
    img = cImage.Image("summer.jpg")
    newimg = cImage.EmptyImage(img.getWidth(), img.getHeight())
    win = cImage.ImageWin()
    for col in range(int((img.getWidth() / 2))):
        for row in range(int((img.getHeight() / 2))):
            p = img.getPixel(col, row)
            green = 255 - p.getGreen()
            blue = 255 - p.getBlue()
            red = 255 - p.getRed()
            newpixel = cImage.Pixel(red, green, blue)
            newimg.setPixel(col, row, newpixel)
    for col in range(int((img.getWidth() / 2)), img.getWidth()):
        for row in range(int((img.getHeight() / 2))):
            p = img.getPixel(col, row)
            green = p.getGreen()
            blue = p.getBlue()
            red = p.getRed()
            newcolor = int((red + green + blue) / 3)
            newpixel = cImage.Pixel(newcolor, newcolor, newcolor)
            newimg.setPixel(col, row, newpixel)
    for col in range(int((img.getWidth() / 2)), img.getWidth()):
        for row in range(int((img.getHeight() / 2)), img.getHeight()):
            p = img.getPixel(col, row)
            green = p.getGreen()
            blue = p.getBlue()
            red = p.getRed()
            newcolor = int((red + green + blue) / 3)
            newpixel = cImage.Pixel(newcolor, newcolor, newcolor)
            newimg.setPixel(col, row, newpixel)
    for col in range(int((img.getWidth() / 2)), img.getWidth()):
        for row in range(int((img.getHeight() / 2)), img.getHeight()):
            p = img.getPixel(col, row)
            red = p.getRed()
            if red > 140:
                val = 255
            else:
                val = 0
            newpixel = cImage.Pixel(val, val, val)
            newimg.setPixel(col, row, newpixel)
    for col in range(int((img.getWidth() / 2))):
        for row in range(int((img.getHeight() / 2)), img.getHeight()):
            p = img.getPixel(col, row)
            green = 0
            blue = p.getBlue()
            red = p.getRed()
            newpixel = cImage.Pixel(red, green, blue)
            newimg.setPixel(col, row, newpixel)
    newimg.draw(win)
    win.exitonclick()
Exemple #19
0
def main():
    win = image.ImageWin()
    img = image.Image("treeSmall.gif")
    w = img.getWidth()
    h = img.getHeight()
    newImage = image.EmptyImage(w, h)

    for row in range(h):
        for col in range(w):
            p = img.getPixel(col, row)
            newpixel = image.Pixel(p.getRed(), 0, 0)
            newImage.setPixel(col, row, newpixel)

    newImage.draw(win)
    win.exitonclick()
Exemple #20
0
def enlarge(input_img, output_img):
    #TODO
    img = image.Image(input_img)
    width = img.getWidth() * 4
    height = img.getHeight() * 4
    newimg = image.EmptyImage(width, height)

    for col in range(width):
        for row in range(height):
            new_col = col // 4
            new_row = row // 4
            px = img.getPixel(new_col, new_row)
            newimg.setPixel(col, row, px)

    newimg.saveTk(output_img)
def pixelMapper(rgbFunction):

    img = image.Image(input("Enter image name, including file extension: "))
    newimg = image.EmptyImage(img.getWidth(), img.getHeight())

    for x in range(img.getWidth()):
        for y in range(img.getHeight()):

            originalpixel = img.getPixel(x, y)
            newpixel = rgbFunction(originalpixel)
            newimg.setPixel(x, y, newpixel)

    win = image.ImageWin()
    newimg.draw(win)
    win.exitonclick()
def main():
    try:
        imm = input(
            "Inserisci il nome dell'immagine con cui desideri giocare: ")
        immagine = image.Image(imm + str('.gif'))
    except:
        print(
            "Caratteri errati. Verifica si tratti di una immagine .gif e che sia presente nella stessa directory dell'algoritmo."
        )
        print(' ')
        main()
    print(' ')
    print("Definisci livello di gioco:")
    print(" 1. Facile")
    print(" 2. Intermedio")
    print(" 3. Difficile")
    print(" 4. (livello avanzato random 20-30)")
    scelta = input("Scelta ---> ")
    while scelta != "1" and scelta != "2" and scelta != "3" and scelta != "4":
        scelta = input(
            "Il carattere inserito non corrisponde a nessuna delle proposte. Riprova: "
        )
    liv = 0
    if scelta == "1":
        liv += 5
    elif scelta == "2":
        liv += 10
    elif scelta == "3":
        liv += 15
    else:
        liv += random.randrange(20, 31, 1)

    lista_return = prepara_pixel(immagine)
    print(' ')
    print("Questa è l'immagine che ricomposta ti assicurerà la vittoria!")
    print('Potrai riuscirci anche con ' + str(liv) + ' mosse! Buona fortuna!')
    print(' ')
    print('Ora attendi il rimescolamento delle tessere...')
    vittoria = livello(liv, lista_return[1], lista_return[0], lista_return[3],
                       lista_return[2], lista_return[5], lista_return[4],
                       lista_return[6], lista_return[7])
    print(' ')
    print('VIA!!!')
    print('')
    num_click = 0
    click_gioco(lista_return[4], lista_return[1], lista_return[0],
                lista_return[3], lista_return[2], vittoria, imm, num_click,
                liv, lista_return[6], lista_return[7])
Exemple #23
0
def main():
    import cImage
    file_name = input("What is the name of the image file? ")
    question = input("Ex: positive, negative, gray scale, hidden, exit. ")
    if question == "positive" or question == "p":
        call = pos(file_name)
    elif question == "negative" or question == "n":
        call = neg(file_name)
    elif question == "gray scale" or question == "g":
        call = graysc(file_name)
    elif question == "hidden" or question == "h":
        call = hidden_message(file_name)
    if question != "exit" or question != "e":
        img = cImage.Image(file_name)
        win = cImage.ImageWin(img.getWidth(), img.getHeight())
        img.draw(win)
        win.exitonclick()
def greyScale():

    img = image.Image(input("Enter image name, including file extension: "))
    newimg = image.EmptyImage(img.getWidth(), img.getHeight())

    for x in range(img.getWidth()):
        for y in range(img.getHeight()):

            p = img.getPixel(x, y)
            avg_pixel = int((p[0] + p[1] + p[2]) / 3)

            newPixel = image.Pixel(avg_pixel, avg_pixel, avg_pixel)
            newimg.setPixel(x, y, newPixel)

    win = image.ImageWin()
    newimg.draw(win)
    win.exitonclick()
def __convert(convert_type , filename):
    old_image = image.Image(filename)
    width,height = old_image.getWidth(),old_image.getHeight()

    new_image = image.EmptyImage(width, height)
        
    old_image.setPosition(0,0)



    for row in range(height):
        for col in range(width):
            old_pixel = old_image.getPixel(col,row)
            R,G,B = old_pixel.getRed() , old_pixel.getGreen() , old_pixel.getBlue()
            
            if convert_type == "grayscale":
                # Add the three colors together and then divide by 3 to get the average color
                R = G = B = (R + G + B) // 3
                
            elif convert_type == "sepia_tone":
                R = int(R * 0.393 + G * 0.769 + B * 0.189)
                G = int(R * 0.349 + G * 0.686 + B * 0.168)
                B = int(R * 0.272 + G * 0.534 + B * 0.131)
                
            elif convert_type == "negative":
                R = 255 - R
                G = 255 - G
                B = 255 - B
             
            elif convert_type == "black_and_white":
                # if total of 3 colors are bigger than (128*3) or 384 set 255 otherwise 0
                # it means that pixel is bright or dark
                # when it's bigger than average then convert it to the maximum and conversely
                R = G = B = 255 if ((R + G + B) >= 128 * 3) else 0

            
            new_pixel = image.Pixel(R,G,B)    
            new_image.setPixel( col , row , new_pixel )
            
            
    new_file_name = convert_type + "@" + filename

    save_image_as_gif(new_image, new_file_name)

    show_images(old_image,new_image)
Exemple #26
0
def makeaDictionary(path):
    '''
    Specify a path, receive a dictionary of cImage files accessed by set name (key)
    :param path: path containing image files
    :return: dictionary of set Keys and cImage objects.
    '''
    dict = {}
    setNames = []
    included_ext = ['jpg', 'png', 'bmp']
    cleanSetList = [
        fn for fn in os.listdir(path) if any(
            fn.endswith(ext) for ext in included_ext)
    ]
    for set in cleanSetList:
        img = image.Image(path + set)
        set = set[:-4]
        dict[set] = img
    return dict
Exemple #27
0
def main():
    win = image.ImageWin()
    img = image.Image("spacetacocat.gif")
    w = img.getWidth()
    h = img.getHeight()
    newImage = image.EmptyImage(w,h)

    for row in range(h):
        for col in range(w):
            p = img.getPixel(col,row)
            newImage.setPixel(col,row,p)


    

    
    newImage.draw(win)
    win.exitonclick()
def noise_reduction(median):

    img = image.Image(input("Enter image name, including file extension: "))
    newimg = image.EmptyImage(img.getWidth(), img.getHeight())

    for x in range(1,
                   img.getWidth() -
                   1):  # ignore the edge pixels for simplicity
        for y in range(1,
                       img.getHeight() -
                       1):  # ignore the edge pixels for simplicity

            p0 = img.getPixel(x - 1, y - 1)
            p1 = img.getPixel(x - 1, y)
            p2 = img.getPixel(x - 1, y + 1)
            p3 = img.getPixel(x, y - 1)
            p4 = img.getPixel(x, y)
            p5 = img.getPixel(x, y + 1)
            p6 = img.getPixel(x + 1, y - 1)
            p7 = img.getPixel(x + 1, y)
            p8 = img.getPixel(x + 1, y + 1)

            r = int(
                median([
                    p0[0], p1[0], p2[0], p3[0], p4[0], p5[0], p6[0], p7[0],
                    p8[0]
                ]))
            g = int(
                median([
                    p0[1], p1[1], p2[1], p3[1], p4[1], p5[1], p6[1], p7[1],
                    p8[1]
                ]))
            b = int(
                median([
                    p0[2], p1[2], p2[2], p3[2], p4[2], p5[2], p6[2], p7[2],
                    p8[2]
                ]))

            newPixel = image.Pixel(r, g, b)
            newimg.setPixel(x, y, newPixel)

    win = image.ImageWin()
    newimg.draw(win)
    win.exitonclick()
def main():
    win = image.ImageWin()
    img = image.Image("kitten1.gif")

    img.draw(win)

    bw_img = convertBlackWhite(img)
    bw_img.setPosition(img.getWidth() + 10, 0)
    bw_img.draw(win)

    half_img = halfSize(img)
    half_img.setPosition(0, img.getHeight() + 10)
    half_img.draw(win)

    blur_img = blur(img)
    blur_img.setPosition(img.getWidth() + 10, img.getHeight() + 10)
    blur_img.draw(win)

    win.exitonclick()
def removeRed():

    img = image.Image(input("Enter image name, including file extension: "))
    newimg = image.EmptyImage(img.getWidth(), img.getHeight())

    for x in range(img.getWidth()):
        for y in range(img.getHeight()):

            p = img.getPixel(x, y)
            r = 0
            g = p[1]
            b = p[2]

            newPixel = image.Pixel(r, g, b)
            newimg.setPixel(x, y, newPixel)

    win = image.ImageWin()
    newimg.draw(win)
    win.exitonclick()