Exemplo n.º 1
0
def sine_modulate_R(xOffset, rvec, m):
    width = len(s2[0])
    w = [[
        add_pixel((rvec[(c - xOffset) % width], 0, 0, 0), s2[r][c])
        for c in range(width)
    ] for r in range(len(s2))]
    image2display(w)
Exemplo n.º 2
0
def cross_blend(min, max, base, steps, m1, m2):
    ext = 1
    for i in range(min, max, steps):
        alpha = i / base
        print(f'Cross blend alpha={alpha} beta={1-alpha}')
        w = add_image(scale_image(alpha, m1), scale_image(1 - alpha, m2))
        # image2file(w, f'cb-{ext}.png')
        image2display(w)
        ext = ext + 1
imgA = file2image("SourceImages/s1-256.png")
imgB = file2image("SourceImages/s2-256.png")

#   image[row][column]
#   len(image) says how many rows [y-size, or height]
#   len(image[0]) says how many column [x-size, or width]
# image2display(m)


# (A) Demonstrate the results of convex sum between the two images by varying
# alpha between 0 and 1.
# Convex sum = alpha * s1 + (1 - alpha) * s2 where 0 <= alpha <= 1
def convex_sum(imgOne, imgTwo):
    alpha = 0.0
    new_image = []
    for r in range(len[imgTwo]):
        for c in range(len(imgTwo[0])):
            new_image = tuple(apha * i + (1 - apha) * j
                              for i, j in zip(imgOne, imgTwo))
            alpha = alpha + 0.1
    return new_image


convex = convex_sum(imgA, imgB)
image2display(convex)

# (B) Demonstrate the results of affine sum between the two images by varying alpha
# between 1 and 2. Note, when alpha is 2, beta must be -1, in a very real sense, we are
# removing image-s2 from image-s1.
# Affine sum = aplha * s1 + beta * s2
Exemplo n.º 4
0
N = 2
amp = 100


def sine(x):
    return amp * sin(x * N * 2 * math.pi / ImageWidth)


def show_sine(s2):
    return [[add_pixel(s2[r][c], [sine(c), 0, 0]) for c in range(len(s2[r]))]
            for r in range(len(s2))]


##
##image2display(show_sine(image2))

print("")
input(
    "<CR> to see I: Sine function phase shift by PI (180-degree) in 20 steps:")


def show_shift_sine(s2, i):
    return [[
        add_pixel(s2[r][c], [sine(c - i), 0, 0]) for c in range(len(s2[r]))
    ] for r in range(len(s2))]


for i in range(9, 181, 9):
    print("Phase shift by:", i, "degrees")
    image2display(show_shift_sine(image2, i))
Exemplo n.º 5
0
print()
input("<CR> to see A: Convex sum, from 0 to 1, in steps of 0.1")
cross_blend(0, 11, 10, 1, s1, s2)

print()
input("<CR> to see B: Affine sum, from 1 to 2, in steps of 0.1")
cross_blend(10, 21, 10, 1, s1, s2)

print()
print("<CR> to see C: Brighten image to 500% in 10 steps")
a = scale_image(0.2, s2)
for i in range(0, 11, 1):
    alpha = 1 + 4 * i / 10
    print(f'Alpha={alpha}')
    w = scale_image(alpha, a)
    image2display(w)

print()
input("<CR> to see D: Shift image RGBA to 250 in 10 steps")
for i in range(25, 260, 25):
    alpha = (i, i, i, i)
    print(f'Shift alpha={alpha}')
    w = color_shift_image(alpha, s2)
    image2display(w)

print()
print("<CR> to see E: Shift image R-Channel to 5 in 10 steps")
for i in range(0, 250, 25):
    alpha = (-i, 0, 0, 0)
    print(f'Shift alpha={alpha}')
    w = color_shift_image(alpha, s2)
Exemplo n.º 6
0
# Author:
# Attempt at class exercise 10/26
#

# make sure to import math and the sin function
# pi is math.pi
import math
from math import sin

# setup importa path to include ./Lib
import sys
sys.path.append('./Lib')  # this is where all the library files are

# import reading of PNG image file into image structure
# After opening an image:
#   image[row][column]
#   len(image) says how many rows [y-size, or height]
#   len(image[0]) says how many column [x-size, or width]

# Here are the three utilities you can use, the last one is just in case
# I did not use the last function
from image_mat_util import file2image
from image_mat_util import image2display
from image_mat_util import image2file  # in case you want to save to a file

image = file2image("SourceImages/s3-256.png")
image2display(image)
    return [[m[r // 2][c // 2] for c in range(2 * len(m[0]))]
            for r in range(2 * len(m))]


def half_resolution(m):
    return [[
        scale_pixel(
            0.25,
            add_pixel(add_pixel(m[r - 1][c - 1], m[r - 1][c]),
                      add_pixel(m[r][c - 1], m[r][c])))
        for c in range(0, len(m[0]), 2)
    ] for r in range(0, len(m), 2)]


input("<CR> to see A: Display the entered image")
image2display(image)

print("")
input("<CR> to see B: Color Shift the image by (-255, 0, 0):")
image2display(color_shift_image((-255, 0, 0), image))

print("")
input("<CR> to see C: Scaling the image to 0.6 of oringal color values:")
print("This is original image")
image2display(image)
input("<CR> to continue to see 0.6 scale")
image2display(scale_image(0.6, image))

print("")
input("<CR> to see D: Double the image resolution")
print("This is original image")