예제 #1
0
    def __init__(self, TBA, t, image_name, edge_length_col):
        self.__t = np.copy(t)
        self.__TBA = np.copy(TBA)
        self.__in = image_name
        # cel means "column edge length"
        self.__cel = float(edge_length_col)
        self.__R, self.__C, self.__imgdat = bmp_io_c.input_bmp_c(self.__in)
        R = self.__R
        C = self.__C
        # rel means "row edge length"
        self.__rel = self.__cel * float(R) / C
        self.__wcl = np.zeros([R * C, 7], np.float32)
        self.__wcl[:, 4:7] = self.__imgdat.reshape(3, R * C, order='C').T
        self.__H = Hx.bw_build(TBA, t)

        # compute the range over which x and y vary
        x = np.arange(-self.__cel / 2., self.__cel / 2., self.__cel / C)
        y = np.arange(-self.__rel / 2., self.__rel / 2., self.__rel / R)

        # build picture-sized vector of x values
        tmp = np.ones(R, np.float32)
        x = np.outer(tmp, x).flatten()

        # build picture-sized vector of y values (note the Transpose)
        tmp = np.ones(C, np.float32)
        y = np.outer(tmp, y).T.flatten()

        # build picture-sized vector with z values and also a vector
        # filled with 1's
        z = np.zeros(R * C, np.float32)
        onez = np.ones(R * C, np.float32)

        # row stack the four vectors and multiply by H
        datvecs = self.__H.dot(np.asarray([x, y, z, onez]))
        self.__wcl[:, 0:4] = datvecs.T
예제 #2
0
import numpy as np
import bmp_io_c
import math
from numpy.linalg import inv

# reading the left phone camera image
rows_left_image, cols_left_image, pixels_left_image = bmp_io_c.input_bmp_c(
    "imageLeft.bmp")
print(rows_left_image, cols_left_image)
# print(pixels_left_image)

# reading the right phone camera image
rows_right_image, cols_right_image, pixels_right_image = bmp_io_c.input_bmp_c(
    "imageRight.bmp")
print(rows_right_image, cols_right_image)
# print(pixels_right_image)

# creating a 4096 by 2048 black images
black_left = np.zeros([3, 2048, 4096], np.uint8)
bmp_io_c.output_bmp_c("black_left.bmp", black_left)

black_right = np.zeros([3, 2048, 4096], np.uint8)
bmp_io_c.output_bmp_c("black_right.bmp", black_left)

# padding the left and right images with the black frame

padded_left1 = np.pad(pixels_left_image[0], ((513, 513), (1367, 1366)),
                      'constant')
padded_left2 = np.pad(pixels_left_image[1], ((513, 513), (1367, 1366)),
                      'constant')
padded_left3 = np.pad(pixels_left_image[2], ((513, 513), (1367, 1366)),
예제 #3
0
import numpy as np
import sys
import bmp_io_c

if len(sys.argv) != 4:
    print(
        "the usage is: python this_file_name input_image plane_to_edit output_file"
    )
    sys.exit()

color_planes = 3
constant_matrix = np.array([[0.299, 0.587, 0.114], [-0.147, -0.289, 0.436],
                            [0.615, -0.515, -0.100]])
# input the image
print(str(sys.argv[1]))
rows, cols, pixels = bmp_io_c.input_bmp_c(str(sys.argv[1]))
print("Input Image dimensions are: ", rows, cols)

# np array to hold newly edited pic
yuv = np.zeros((color_planes, rows, cols), np.uint8)
print("shape is =========", constant_matrix.shape)

for i in range(rows):
    for j in range(cols):
        yuv[:, i, j] = np.dot(constant_matrix, np.array(
            pixels[:, i, j])) + np.array([0, 128, 128])

# printing the max and min in RGB
print("The max and min of R plane are: respectively", pixels[0].max(),
      pixels[0].min())
print("The max and min of G plane are: respectively", pixels[1].max(),
예제 #4
0
def readImage(image):
    rows, cols, distorted_pixels = bmp_io_c.input_bmp_c(image)
    return rows, cols, distorted_pixels
예제 #5
0
import numpy as np
import bmp_io_c
import math
from numpy.linalg import inv

# read the sample image
rows, cols, pixels = bmp_io_c.input_bmp_c("image_test02.bmp")
print(rows, cols)
print(pixels)


def lininterp(lions_image, x, y):

    if x < 0 or x > (cols - 1):
        return 0, 0, 0

    if y < 0 or y > (rows - 1):
        return 0, 0, 0

    x1 = math.floor(x)
    x2 = math.ceil(x)
    y1 = math.floor(y)
    y2 = math.ceil(y)

    if x1 == x2 or y1 == y2:
        return lions_image[0, y1, x1]

    mat = np.asarray([[1, x1, y1, x1 * y1], [1, x1, y2, x1 * y2],
                      [1, x2, y1, x2 * y1], [1, x2, y2, x2 * y2]])

    mat = np.transpose(np.linalg.inv(mat))
예제 #6
0
print(" cols = ", cols, " mypic.shape [2] = ", mypic.shape[2])
print(" mypic.shape = ", mypic.shape)

print(mypic)

# create an image form ramp by looping over 3 image planes

for k in range(color_planes):
    for i in range(rows):
        for j in range(cols):
            mypic[k, i, j] = j

print(mypic)

# output the image
bmp_io_c.output_bmp_c("ramp.bmp", mypic)
rows, columns, mypic1 = bmp_io_c.input_bmp_c("ramp.bmp")

# change one pixel
for k in range(color_planes):
    mypic[k, 100, 25] = 0

for k in range(color_planes):
    for i in range(rows):
        for j in range(cols):
            if mypic[k, i, j] != mypic[k, i, j]:
                print("pixel values differ at location [%d, %d, %d ]" %
                      (k, i, j))

print(mypic)