示例#1
0
def main():
    IMAGE_FILE = 'cap.gif'
    MINION_FILE = 'minion-greenscreen.gif'
    CONTRAST = 0.8  # factor for contrast transform < 1 for reduced contrast, > 1 for more contrast
    BRIGHTNESS = 100

    # open and display the image from file
    original_img = image.Image(IMAGE_FILE)
    win1 = image.ImageWin(original_img.getWidth(), original_img.getHeight())
    original_img.draw(win1)

    minion_img = image.Image(MINION_FILE)
    win3 = image.ImageWin(minion_img.getWidth(), minion_img.getHeight())
    minion_img.draw(win3)

    # Create a transformed copy of the image and display it
    transformed_img = adjustBrightnessAndContrast(original_img, BRIGHTNESS,
                                                  CONTRAST)
    transformed_img = adjustGrey(original_img)
    win2 = image.ImageWin(transformed_img.getWidth(),
                          transformed_img.getHeight())
    transformed_img.draw(win2)

    # Create a transformed copy of the image and display it
    green_screen_img = superposeGreenScreen(minion_img, original_img)
    transformed_img = adjustGrey(original_img)
    win4 = image.ImageWin(green_screen_img.getWidth(),
                          green_screen_img.getHeight())
    green_screen_img.draw(win4)
示例#2
0
def main():

    img = image.Image('luther.jpg')
    wn = image.ImageWin(img.getWidth(), img.getHeight())

    newImage = operateOnPixel(img, removeRedFromPixel)
    newImage.draw(wn)
示例#3
0
def photo_smoothed(filename):
    img=image.Image(filename)
    win=image.ImageWin(img.getWidth(),img.getHeight())
    img.setDelay(0)
    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p=img.getPixel(col,row)
            nearred=0
            neargreen=0
            nearblue=0
            if ((col and row)>0) and ((col,row)<(img.getWidth(),img.getHeight())): #smoothing all but the edges for simplicity
                for nearcol in range (col-1,col+1):
                    for nearrow in range (row-1,row+1):
                        nearp=img.getPixel(nearcol,nearrow)
                        nearred=0.1111*nearp.getRed()+nearred
                        neargreen=0.1111*nearp.getGreen()+neargreen
                        nearblue=0.1111*nearp.getBlue()+nearblue
                newpixel=image.Pixel(nearred,neargreen,nearblue)
                img.setPixel(col,row,newpixel)
            
            newR=(p.getRed()*0.393+p.getGreen()*0.769+p.getBlue()*0.189)
            newG=(p.getRed()*0.349+p.getGreen()*0.686+p.getBlue()*0.168)
            newB=(p.getRed()*0.272+p.getGreen()*0.534+p.getBlue()*0.131)
            newpixel=image.Pixel(newR,newG,newB)
            img.setPixel(col,row,newpixel)
    img.draw(win)
    win.exitonclick()
示例#4
0
def main():
    scaleFactor = 2
    img = image.Image('luther.jpg')
    wn = image.ImageWin(img.getWidth() * scaleFactor,
                        img.getHeight() * scaleFactor)
    newImage = doubleImageSize(img, scaleFactor)
    newImage.draw(wn)
def photo_median_replace(filename):
    img = image.Image(filename)
    win = image.ImageWin(img.getWidth(), img.getHeight())
    img.setDelay(0)
    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())
            nearred = 0
            neargreen = 0
            nearblue = 0
            if ((col and row) > 0) and (col + 1 < img.getWidth()) and (
                    row + 1 < img.getHeight()
            ):  #smoothing all but the edges for simplicity
                for nearrow in range(col - 1, col + 2):
                    for nearcol in range(row - 1, row + 2):
                        nearp = img.getPixel(nearrow, nearcol)
                        nearred = nearred + 0.13 * nearp.getRed()
                        neargreen = neargreen + 0.13 * nearp.getGreen()
                        nearblue = nearblue + 0.13 * nearp.getBlue()
                newpixel = image.Pixel(nearred - 0.13 * p.getRed(),
                                       neargreen - 0.13 * p.getGreen(),
                                       nearblue - 0.13 * p.getBlue())
                img.setPixel(col, row, newpixel)
            else:
                img.setPixel(col, row, oldpixel)
    img.draw(win)
    win.exitonclick()
示例#6
0
def main():
    img = image.Image("luther.jpg")
    win = image.ImageWin(img.getWidth() * 2, img.getHeight() * 2)

    big_img = double(img)
    big_img.draw(win)

    win.exitonclick()
示例#7
0
def main():
    img = image.Image("luther.jpg")
    win = image.ImageWin(img.getWidth(), img.getHeight())

    bw_img = convert_black_white(img)
    bw_img.draw(win)

    win.exitonclick()
def main():
    img = image.Image('image.jpg')
    imgWin = image.ImageWin(img.getWidth, img.getHeight)
    img.draw(imgWin)

    for i in range(img.getHeight()):
        for j in range(img.getWidth()):
            oldPixel = img.getPixel(i, j)
            newPixel = image.Pixel(oldPixel.getRed(), 0, 0)
            img.setPixel(j, i, newPixel)

    img.draw(imgWin)
    imgWin.exitonclick()
示例#9
0
def pixel_mapper(filename, map_function):
    img = image.Image(filename)
    img.setDelay(0)
    win = image.ImageWin(img.getWidth(), img.getHeight())

    for col in range(img.getWidth()):
        for row in range(img.getHeight()):
            imgp = img.getPixel(col, row)
            initialpixel = image.Pixel(imgp.getRed(), imgp.getGreen(),
                                       imgp.getBlue())
            newpixel = img.setPixel(col, row, map_function(initialpixel))
    img.draw(win)
    win.exitonclick()
示例#10
0
def main():
	original= image.FileImage('tree.jpg')
	
	OGWidth= original.getWidth()
	OGHeight= original.getHeight()
	new= image.EmptyImage(OGWidth, OGHeight)
	spring_to_fall(OGWidth,OGHeight, new, original)
	
	
	window=image.ImageWin(OGWidth,OGHeight, "Seasonal Tree")		
	new.draw(window)
	new.save('fall_tree.jpg')
	window.exitOnClick()
示例#11
0
def photo_to_sepia(filename):
    img=image.Image(filename)
    win=image.ImageWin(img.getWidth(),img.getHeight())
    img.draw(win)
    img.setDelay(0)
    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p=img.getPixel(col,row)
            newR=(p.getRed()*0.393+p.getGreen()*0.769+p.getBlue()*0.189)
            newG=(p.getRed()*0.349+p.getGreen()*0.686+p.getBlue()*0.168)
            newB=(p.getRed()*0.272+p.getGreen()*0.534+p.getBlue()*0.131)
            newpixel=image.Pixel(newR,newG,newB)
            img.setPixel(col,row,newpixel)
    img.draw(win)
    win.exitonclick()
示例#12
0
def photo_to_bw(filename):
    img = image.Image(filename)
    win = image.ImageWin(img.getWidth(), img.getHeight())
    img.draw(win)
    img.setDelay(0)
    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p = img.getPixel(col, row)
            newvalue = (p.getRed() + p.getGreen() + p.getBlue()) // 3
            if newvalue > 127:
                pixelvalue = 255
            else:
                pixelvalue = 0
            newpixel = image.Pixel(pixelvalue, pixelvalue, pixelvalue)
            img.setPixel(col, row, newpixel)
    img.draw(win)
    win.exitonclick()
示例#13
0
def img_create(board, resolution, name, name1, name2, name3, power, print_tipe,
               color):
    ''' Taking the square board and output it as a png file or in a window '''

    # define the image parameters
    height = int(resolution // 1.75)
    width = int(resolution)
    if (print_tipe == 1): win = image.ImageWin(width, height)
    img = image.EmptyImage(width, height)

    # iterating over the pixels in the img
    counter = 0
    for row in range(height):
        for col in range(width):
            # sets the color black if the value is 0
            if board[counter] == 0:
                this_pixel = image.Pixel(0, 0, 0)
            else:
                # checks if color is required
                if (color == 0):
                    # sets the colors according to the value
                    (red, green, blue) = colors(board[counter])
                    this_pixel = image.Pixel(red, green, blue)
                else:
                    # sets thhe gray levels according to the value
                    pix_val = board[counter] // power
                    this_pixel = image.Pixel(pix_val, pix_val, pix_val)
            img.set_pixel(col, row, this_pixel)
            counter += 1

    if (print_tipe == 1):
        img.draw(win)
        print('')
        input()
    else:
        img.save(f'{name}_{name1}_{name2}_{name3}.png')
示例#14
0
listoflists = []
for i in range(len(listofwindows)):
    listoflists.append(np.fft.fft(listofwindows[i]))
"""Takes the list of lists of values which have gone through the FFT, and converts them to log magnitudes. Furthermore, it then converts them to log scale with the formula 10*log10 square magnitude."""
listofmagnitudes = []
for i in range(len(listoflists)):
    listofmags1 = []
    for j in range(len(listoflists[i])):
        real = (listoflists[i][j]).real
        imaginary = (listoflists[i][j]).imag
        listofmags1.append(10 * math.log(math.sqrt((real**2) +
                                                   (imaginary**2))))
    listofmagnitudes.append(listofmags1)
amin = np.amin(listofmagnitudes)
amax = np.amax(listofmagnitudes)
"""Takes the final 2D list, along with the minimum and maximum values in the list, and turns them into an image with set pixel colors."""
win = image.ImageWin("Spectrogram", len(listofmagnitudes),
                     len(listofmagnitudes[0]))
myImage = image.EmptyImage(len(listofmagnitudes), len(listofmagnitudes[0]))
for row in range(myImage.getHeight()):
    for col in range(myImage.getWidth()):
        i = (255 * ((listofmagnitudes[col][row] - amin) / (amax - amin)))
        v = myImage.getPixel(col, row)
        v.red = 255 - i
        v.green = 255 - i
        v.blue = 255 - i
        #            x = map(lambda x: 255-x, v)
        myImage.setPixel(col, row, v)
myImage.setPosition(0, 0)
myImage.draw(win)
win.exitOnClick()
示例#15
0
#to remove the red from an image. To make the red pixel value to zero.
import image

img = image.Image("luther.jpg")
win = image.ImageWin(img.getWidth(), img.getHeight()) #to get the image in a separate window
img.draw(win)
img.setDelay(0)

for row in range(img.getHeight()):
    for col in range(img.getWidth()):
        pix = img.getPixel(col,row)
        
        newRed = 0 #removing red component     
        newpix = image.Pixel(newRed, pix.getGreen(),pix.getBlue())
        
        img.setPixel(col,row,newpix)
        
win.exitonclick()
import image

source_image = image.Image("giraffe.jpg")  #open an image

width = source_image.get_width()  #find the width and
height = source_image.get_height()  #height of the image

window = image.ImageWin(width, height)  #create a window

source_image.draw(window)

#Set up Loops to Visit every pixel and do some work

for x in range(width):
    for y in range(height):
        #retrieve the current pixel
        current_pixel = source_image.get_pixel(x, y)

        #access the R,G,B component values
        r = current_pixel.get_red()
        g = current_pixel.get_green()
        b = current_pixel.get_blue()

        #is this pixel on the bottom half??
        if y > height / 2:
            r = g
            b = g

        new_pixel = image.Pixel(r, g, b)  #create a new pixel
        source_image.set_pixel(x, y, new_pixel)  #create a new pixel
示例#17
0
# if you attempt to run this code, and get a ModuleNotFoundError: No module named 'image',
# you need to (in Thonny), select Tools -> Manage Packages..., type in cs20-image, click
# search, then click install
import image

# open an image
img = image.Image("giraffe.jpg")

# figure out how large the image is
width = img.get_width()
height = img.get_height()

# make a window to draw on
win = image.ImageWin(width, height)

# draw the original image onto the window
img.draw(win)

# use a nested for loop to look at every pixel in the image
for x in range(width):
    for y in range(height):
        if y <= height / 2:
            # get the current pixel
            this_pixel = img.get_pixel(x, y)
        else:
            distance_from_midline = y - height / 2
            this_pixel = img.get_pixel(x, height / 2 - distance_from_midline)

        # access the amount of red, green and blue for this pixel
        r = this_pixel.get_red()
        g = this_pixel.get_green()
示例#18
0
import image

img = image.Image("luther.jpg")
h = img.getHeight()
w = img.getWidth()
newimg = image.EmptyImage(w, h)
win = image.ImageWin(w, h)


def avg(x):
    return sum(x) / len(x)


# for col in range(w):
#     for row in range(h):
#         p = img.getPixel(col, row)
#         newimg.setPixel(2 * col, 2 * row, p)
#         newimg.setPixel(2 * col + 1, 2 * row, p)
#         newimg.setPixel(2 * col, 2 * row + 1, p)
#         newimg.setPixel(2 * col + 1, 2 * row + 1, p)
for col in range(1, w - 1):
    for row in range(1, h - 1):
        indexes = [0, 0], [0, 1], [1, 0], [-1, 0], [0, -1]
        r = []
        g = []
        b = []

        for pixelIndex in indexes:
            pixel = img.getPixel(col + pixelIndex[0], row + pixelIndex[1])
            r.append(pixel.getRed())
            g.append(pixel.getGreen())
示例#19
0
def main():
    wn = image.ImageWin()
    img = image.Image('luther.jpg')
    sepiaToneImage = convertToSepiaTone(img)
    sepiaToneImage.draw(wn)
示例#20
0
import image


def double_photo(
        filename
):  #doubles side length of photo, enlarges area by a factor of 4
    img = image.Image(filename)
    newimg = image.EmptyImage(2 * img.getWidth(), 2 * img.getHeight())
    img.setDelay(0)

    for row in range(img.getHeight()):
        for col in range(img.getWidth()):
            p = img.getPixel(col, row)
            newimg.setPixel(2 * col, 2 * row, p)
            newimg.setPixel(2 * col, 2 * row + 1, p)
            newimg.setPixel(2 * col + 1, 2 * row, p)
            newimg.setPixel(2 * col + 1, 2 * row + 1, p)
    return newimg


img = image.Image('luther.jpg')
win = image.ImageWin(2 * img.getWidth(), 2 * img.getHeight())
newimg = double_photo("luther.jpg")
newimg.draw(win)
win.exitonclick()
示例#21
0
import image

img = image.Image("luther.jpg")
new_img = image.EmptyImage(img.getWidth(), img.getHeight())
win = image.ImageWin(img.getWidth(), img.getHeight())

for i in range(0, img.getWidth()):
    for j in range(0, img.getHeight()):
        old_p = img.getPixel(i, j)
        red = old_p.getRed()
        new_p = image.Pixel(red, 0, 0)
        new_img.setPixel(i, j, new_p)

new_img.draw(win)
win.exitonclick()
    
示例#22
0
import image

fg = image.Image('secret.png')
newIm = image.EmptyImage(fg.getWidth(), fg.getHeight())

for row in range(fg.getHeight()):
    for col in range(fg.getWidth()):
        fgpix = fg.getPixel(col, row)
        fgr = fgpix.getRed()

        if fgr % 2 == 0:
            newPix = image.Pixel(255, 255, 255)
        else:
            newPix = image.Pixel(0, 0, 0)
        newIm.setPixel(col, row, newPix)

win = image.ImageWin(500, 400)
newIm.draw(win)
win.exitonclick()
示例#23
0
import image    #module to handle image object
import math

img = image.Image("luther.jpg")  #initialize image to a jpg file
newimg = image.EmptyImage(img.getWidth(),img.getHeight())  #Blank image
win = image.ImageWin()  #Image window creation

for col in range(img.getWidth()):  #columns
    for row in range(img.getHeight()):  #rows
       p = img.getPixel(col, row)  #pixel in row, colum grid coordinate

       newred = p.getRed()  #Get the red value to 
       green = p.getGreen()  #Get the green from the picture's pixel
       blue = p.getBlue()  #Get the blue from the picture's pixel
       gscale = int((newred + green + blue) / 3.0)  #Gray scale
       
       newpixel = image.Pixel(gscale, gscale, gscale)  #replace old red with new red

       newimg.setPixel(col, row, newpixel)  #replace old pixel with new pixel

newimg.draw(win)
win.exitonclick()
示例#24
0
import image

img = image.Image("adn.jpg")
width = img.getWidth()
height = img.getHeight()
win = image.ImageWin(width * 2, height * 2)
img.draw(win)
avgRed = 0
avgGreen = 0
avgBlue = 0

newimg = image.EmptyImage(width * 2, height * 2)

for row in range(height):
    for col in range(width):
        p = img.getPixel(col, row)

        # start at 1 and stop 1 short so border pixels are not evalutated
        while row > 0 and row < height - 1:
            while col > 0 and col < width - 1:
                p1 = img.getPixel(col - 1, row - 1)
                p2 = img.getPixel(col, row - 1)
                p3 = img.getPixel(col + 1, row - 1)
                p4 = img.getPixel(col - 1, row)
                p5 = img.getPixel(col, row)
                p6 = img.getPixel(col + 1, row)
                p7 = img.getPixel(col - 1, row + 1)
                p8 = img.getPixel(col, row + 1)
                p9 = img.getPixel(col + 1, row + 1)

                avgRed = (p1.getRed() + p2.getRed() + p3.getRed() +
示例#25
0
import image

pika =  image.Image("pikachu.jpg")
win = image.ImageWin(pika.getWidth(), pika.getHeight(), "greyscale shock")

pika.draw(win)
for x in range(pika.getWidth()):
	for y in range(pika.getHeight()):
		orig = pika.getPixel(x,y)
		r = orig.getRed()
		g = orig.getGreen()
		b = orig.getBlue()
		
		grey = (r+g+b)//3
		pika.setPixel(x,y,image.Pixel(g,g,g))
	pika.draw(win)
示例#26
0
import image


pika = image.Image("pikachu.jpg")

win = image.ImageWin(pika.getWidth(), pika.getHeight(), "shock")


pika.draw(win)


for x in range(pika.getWidth()):
	for y in range(pika.getHeight()):
		orig = pika.getPixel(x,y)
		pika.setPixel(x,y,image.Pixel(255- orig.getRed(),255- orig.getGreen(),255- orig.getBlue()))
	pika.draw(win)




win.exit_on_click()
示例#27
0
import image
img = image.Image("luther.jpg")
newimg = image.EmptyImage(img.getWidth(), img.getHeight())
win = image.ImageWin()
for col in range(img.getWidth()):
    for row in range(img.getHeight()):
        p = img.getPixel(col, row)

        red = int(p.getRed() * 0.299)
        green = int(p.getGreen() * 0.587)
        blue = int(p.getBlue() * 0.114)
        lum = red + green + blue

        newpixel = image.Pixel(lum, lum, lum)
        newimg.setPixel(col, row, newpixel)

newimg.draw(win)
win.exitonclick()
            #   set pixel to new properties
            new_pixel = image.Pixel(new_red, new_green, new_blue)
            newimg.setPixel(col, row, new_pixel)  # setter method
    return newimg.draw(win)


# ----------------------------------------------------------------------------------------------------------------------
# VARIABLES
# ----------------------------------------------------------------------------------------------------------------------

# Creates an Image object from the filename
img = image.Image("colors.png")

# ImageWin makes a frame to display image(s)
orig = image.ImageWin(img.getWidth(), img.getHeight(), "Original")
# new = image.ImageWin(img.getWidth(), img.getHeight(), "Negative")
sep = image.ImageWin(img.getWidth(), img.getHeight(), "Sepia")
red = image.ImageWin(img.getWidth(), img.getHeight(), "Remove All Red")
gray = image.ImageWin(img.getWidth(), img.getHeight(), "Gray Scale")

# ----------------------------------------------------------------------------------------------------------------------
# BEGIN PROGRAM"
# ----------------------------------------------------------------------------------------------------------------------

# draw the image on "orig" window frame
img.draw(orig)

# process and draw the image on "new" window frame
# negative(img, new)
sepia(img, sep)
import image

win = image.ImageWin(480, 640, "Image Processing")
original_image = image.Image('cy.png')
original_image.set_delay(1, 10)

width = original_image.get_width()
height = original_image.get_height()
print(width, height)

original_image.draw(win)
my_image = original_image.copy()

for row in range(height):
    for col in range(width):
        v = my_image.get_pixel(col, row)
        v.red = 255 - v.red
        v.green = 255 - v.green
        v.blue = 255 - v.blue
        my_image.set_pixel(col, row, v)

my_image.draw(win)
print(win.get_mouse())
my_image.save('lcastle-inverted.gif')
print(my_image.to_list())
win.exit_on_click()
示例#30
0
 def show(self):
     win = _image_module.ImageWin(*self.size)
     self._image.draw(win)