def test_fill_image(self): "an image turns entirely yellow when the colour WHITE is filled with YELLOW" img = main.Image(10, 10) img.fill(0, 0, main.YELLOW) for row in img.data: for col in row: self.assertEqual(col, main.YELLOW)
def test_no_other_pixel_coloured(self): img = main.Image(10, 10) cx, cy = 1, 1 img.colour(cx, cy, main.YELLOW) for i, row in enumerate(img.data): for j, col in enumerate(row): if cx == i and cy == j: # ensure all EXCEPT these coords are white continue self.assertTrue(col, main.WHITE)
def test_colour_row(self): img = main.Image(10, 10) y, x1, x2 = 1, 3, 7 img.colour_row_segment(x1, x2, y, main.YELLOW) coord_list = [(x1 + i, y) for i in range(0, x2 - x1 + 1)] for y, row in enumerate(img.data): for x, col in enumerate(row): if (x, y) in coord_list: self.assertEqual(img.pixel(x, y), main.YELLOW) else: self.assertEqual(img.pixel(x, y), main.WHITE)
def test_colour_col(self): width, height = 10, 10 img = main.Image(width, height) x, y1, y2 = 1, 3, 7 img.colour_column_segment(x, y1, y2, main.YELLOW) coords = [(x, y1 + i) for i in range(0, y2 - y1 + 1)] for y, row in enumerate(img.data): for x, col in enumerate(row): if (x, y) in coords: self.assertEqual(img.pixel(x, y), main.YELLOW) else: self.assertEqual(img.pixel(x, y), main.WHITE)
def test_out_of_bounds_col_colouring(self): width, height = 10, 10 img = main.Image(width, height) x = 1 self.assertRaises(ValueError, img.colour_column_segment, x, 5, height + 1, main.YELLOW) self.assertRaises(ValueError, img.colour_column_segment, x, 5, -1, main.YELLOW) self.assertRaises(ValueError, img.colour_column_segment, x, -1, 5, main.YELLOW) self.assertRaises(ValueError, img.colour_column_segment, x, height + 1, 5, main.YELLOW) self.assertRaises(ValueError, img.colour_column_segment, x - 2, 5, 6, main.YELLOW) self.assertRaises(ValueError, img.colour_column_segment, width + 1, 5, 6, main.YELLOW)
def test_fill_image2(self): """an image with an inner border of black completely surrounding a single white pixel should have the outer border turn entirely YELLOW when the WHITE is filled EXCEPT the single inner white pixel""" img = main.Image(5, 5) inner_border = [(1, 1), (2, 1), (3, 1), (1, 2), (3, 2), (1, 3), (2, 3), (3, 3)] [img.colour(x, y, main.BLACK) for x, y in inner_border] img.fill(0, 0, main.YELLOW) for y, row in enumerate(img.data): for x, col in enumerate(row): if (x, y) in inner_border: self.assertEqual(img.pixel(x, y), main.BLACK) elif (x, y) == (2, 2): self.assertEqual(img.pixel(2, 2), main.WHITE) else: self.assertEqual(img.pixel(x, y), main.YELLOW)
import main import matplotlib.pyplot as plt from skimage.measure import compare_ssim as ssim from skimage.exposure import rescale_intensity as rescale import numpy as np s = main.Server() s.handler() i = main.Image() im = i.return_image(size=32) hadamard_samples = s.get_data() o = main.Single() res1 = o.reconstruction(hadamard_samples, 32, method='hadamard', mask='hadamard') s1 = ssim( rescale(res1, out_range=(0, 255)).astype("uint8"), im.astype("uint8")) print(s1) plt.imshow(res1)
def test_out_of_bounds_pixel_colouring(self): img = main.Image(10, 10) self.assertRaises(ValueError, img.colour, 1, 11, main.YELLOW) self.assertRaises(ValueError, img.colour, 11, 1, main.YELLOW) self.assertRaises(ValueError, img.colour, -1, 11, main.YELLOW) self.assertRaises(ValueError, img.colour, 1, -1, main.YELLOW)
def test_colour_pixel(self): c = main.YELLOW img = main.Image(10, 10) img.colour(1, 1, c) self.assertEqual(img.data[1][1], c)
def test_clear_image(self): img = main.Image(10, 10, main.BLACK) img.clear() for row in img.data: for col in row: self.assertEqual(col, main.WHITE)
def test_incorrect_default_colour(self): img = main.Image(10, 10) self.assertNotEqual(img.data[0][0], main.BLACK)
def test_default_colours(self): img = main.Image(10, 10) for row in img.data: for col in row: self.assertEqual(col, main.WHITE)
def test_create_image(self): x = 10 y = 10 img = main.Image(x, y) self.assertEqual(x, img.width) self.assertEqual(y, img.height)