Пример #1
0
#

from ezgraphics import GraphicsImage, GraphicsWindow

filename = input("Enter the name of the image file: ")

# Load the image from the file.
image = GraphicsImage(filename)

# Process the image.
width = image.width()
height = image.height()
for row in range(height):
    for col in range(width):
        # Get the current pixel color.
        red = image.getRed(row, col)
        green = image.getGreen(row, col)
        blue = image.getBlue(row, col)

        # Filter the pixel.
        newRed = 255 - red
        newGreen = 255 - green
        newBlue = 255 - blue

        # Set the pixel to the new color.
        image.setPixel(row, col, newRed, newGreen, newBlue)

# Display the image on screen.
win = GraphicsWindow()
canvas = win.canvas()
canvas.drawImage(image)
Пример #2
0
else:
    HEIGHT = picture.height()
    WIDTH = picture.width()
#Find middle point
HeightRow = HEIGHT // 2
WidthCol = WIDTH // 2
newimage = GraphicsImage(WIDTH, HEIGHT)

#For future use
#To do : make a square pic
'''
Main function
'''

print("Processing Images....Please Wait...")
#Find pixel
for row in range(HEIGHT):
    for col in range(WIDTH):
        if sqrt((row - HeightRow)**2 + (col - WidthCol)**2) <= HEIGHT // 2:
            red = round(picture.getRed(row, col) * 0.2126)
            green = round(picture.getGreen(row, col) * 0.07152)
            blue = round(picture.getGreen(row, col) * 0.0722)
            gray = red + green + blue
            newimage.setPixel(row, col, gray, gray, gray)
        else:
            newimage.setPixel(row, col, 255, 255, 255)
newimage.save(os.path.join(
    __location__, 'queen-mary_lab3.gif'))  #Change if you want another pic
print("Done")
print("Output image has been put into same folder name:'queen-mary_lab3.gif'")
Пример #3
0
else:
    radius = width // 2
#set up the effect color to white(255,255,255)
newRed = 255
newBlue = 255
newGreen = 255
# newRow is row number of new image
newRow = 0
for row in range(height):  #go through every row
    # outer loop is top-down
    for col in range(width):  #go through column
        #inner loop is left-to-right
        newCol = col
        if sqrt((width / 2 - col)**2 + (height / 2 - row)**2) <= radius:
            green = int(0.7152 * origImage.getGreen(row, col))
            red = int(0.2126 * origImage.getRed(row, col))
            blue = int(0.0722 * origImage.getBlue(row, col))
            gray = green + red + blue
            newImage.setPixel(newRow, newCol, gray, gray,
                              gray)  #paste to new image
        else:
            newImage.setPixel(newRow, newCol, newRed, newGreen,
                              newBlue)  # paste to new image
    newRow = newRow + 1
# Save the new image with "Black".
newImage.save("black-" + filename)

# Draw the telescoped image
win = GraphicsWindow()
canvas = win.canvas()
canvas.drawImage(newImage)
win = GraphicsWindow()
canvas = win.canvas()
imageWidth = origImage.width()
imageHeight = origImage.height()

# define new image dimensions
newImage = GraphicsImage(imageWidth, imageHeight)

# output the size of image
print(imageWidth)
print(imageHeight)

# edit the image
for row in range(imageHeight):
    for col in range(imageWidth):
        red = origImage.getRed(row, col)
        newRed = int(red * 1.3)
        # if the red exceed the RGB range, it will set to the maximum
        if newRed > 255:
            newRed = 255
        green = origImage.getGreen(row, col)
        blue = origImage.getBlue(row, col)
        # set the colors of the image
        newImage.setPixel(row, col, newRed, green, blue)

# display image
canvas.drawImage(origImage)
canvas.drawImage(newImage)
win.wait()

# output image file