Commit 3ab037e2 authored by Stephen Thompson's avatar Stephen Thompson

Issue #38 added weiss logo class

parent e5f6c554
Pipeline #3163 failed with stages
in 6 minutes and 56 seconds
......@@ -22,3 +22,13 @@ def prepare_cv2_text_overlay(overlay_text, frame, text_scale=1):
text, text_location, cv2.FONT_HERSHEY_COMPLEX, text_scale, text_colour)
return text_overlay_properties
def noisy_image(image, mean=0, stddev=(50, 5, 5)):
"""
Creates a noise image, based on the dimensions of the
passed image.
param: the image to define size and channels of output
returns: a noisy image
"""
cv2.randn(image, (mean), (stddev))
return image
"""A class for making a natty WEISS logo"""
from math import cos, pi
from numpy import full, int32, uint8
from cv2 import fillConvexPoly, circle
from sksurgeryimage.utilities.utilities import noisy_image
class WeissLogo():
"""Creates a WEISS logo and passes a copy on request"""
def __init__(self, image_size=331.0):
"""
Creates a WEISS logo and passes a copy on request
param: the image size in pixels
"""
thickness = image_size/8.5
lblength = image_size/1.4
sblength = image_size/1.9
lhlength = image_size/5.5
shlength = image_size/3.1
qtr_pi_cos = cos(-pi/4)
self._background = full((int32(image_size), int32(image_size), 3),
[125, 98, 0], dtype=uint8)
#the ends of each bar, going clockwise from top centre
end_points = []
end_points.append(((image_size/2), (image_size-lblength)/2))
end_points.append((((sblength * qtr_pi_cos + image_size)/2),
((-sblength * qtr_pi_cos + image_size)/2)))
end_points.append((((image_size+lblength)/2), (image_size/2)))
end_points.append(((shlength * qtr_pi_cos + image_size/2),
(shlength * qtr_pi_cos + image_size/2)))
end_points.append(((image_size/2), (image_size+lblength)/2))
end_points.append((((-sblength * qtr_pi_cos + image_size)/2),
((sblength * qtr_pi_cos + image_size)/2)))
end_points.append((((image_size-lblength)/2), (image_size/2)))
end_points.append(((-lhlength * qtr_pi_cos + image_size/2),
(-lhlength * qtr_pi_cos + image_size/2)))
vertices = []
vertices.append((end_points[0][0] - thickness/2, end_points[0][1]))
vertices.append((end_points[0][0] + thickness/2, end_points[0][1]))
vertices.append((end_points[4][0] + thickness/2, end_points[4][1]))
vertices.append((end_points[4][0] - thickness/2, end_points[4][1]))
fillConvexPoly(self._background, int32(vertices), color=[255, 255, 255])
vertices = []
vertices.append(((image_size-lblength)/2,
(image_size-thickness)/2))
vertices.append(((image_size+lblength)/2,
(image_size-thickness)/2))
vertices.append(((image_size+lblength)/2,
(image_size+thickness)/2))
vertices.append(((image_size-lblength)/2,
(image_size+thickness)/2))
fillConvexPoly(self._background, int32(vertices), color=[255, 255, 255])
vertices = []
vertices.append((
(sblength * qtr_pi_cos - thickness * qtr_pi_cos + image_size)/2,
(-sblength * qtr_pi_cos - thickness * qtr_pi_cos + image_size)/2))
vertices.append((
(sblength * qtr_pi_cos + thickness * qtr_pi_cos + image_size)/2,
(-sblength * qtr_pi_cos + thickness * qtr_pi_cos + image_size)/2))
vertices.append((
(-sblength * qtr_pi_cos + thickness * qtr_pi_cos + image_size)/2,
(sblength * qtr_pi_cos + thickness * qtr_pi_cos + image_size)/2))
vertices.append((
(-sblength * qtr_pi_cos - thickness * qtr_pi_cos + image_size)/2,
(sblength * qtr_pi_cos - thickness * qtr_pi_cos + image_size)/2))
fillConvexPoly(self._background, int32(vertices), color=[255, 255, 255])
vertices = []
vertices.append(
(-lhlength * qtr_pi_cos + (-thickness * qtr_pi_cos + image_size)/2,
-lhlength * qtr_pi_cos + (thickness * qtr_pi_cos + image_size)/2))
vertices.append(
(-lhlength * qtr_pi_cos + (thickness * qtr_pi_cos + image_size)/2,
-lhlength * qtr_pi_cos + (-thickness * qtr_pi_cos + image_size)/2))
vertices.append(
(shlength * qtr_pi_cos + (thickness * qtr_pi_cos + image_size)/2,
shlength * qtr_pi_cos + (-thickness * qtr_pi_cos + image_size)/2))
vertices.append(
(shlength * qtr_pi_cos + (-thickness * qtr_pi_cos + image_size)/2,
shlength * qtr_pi_cos + (thickness * qtr_pi_cos + image_size)/2))
fillConvexPoly(self._background, int32(vertices), color=[255, 255, 255])
for point in end_points:
circle(self._background, (int32(point[0]), int32(point[1])),
radius=int32(thickness/2 + 1), color=[255, 255, 255],
thickness=-1)
def get_logo(self):
"""
Returns the WEISS Logo
:return: The WEISS Logo as a Numpy array
"""
return self._background
def get_noisy_logo(self):
"""
Returns the WEISS Logo with some noise added
:return: A noisy WEISS Logo as Numpy Array
"""
noise = noisy_image(self._background.copy())
return self._background + noise
# coding=utf-8
"""snappysonic tests"""
from numpy import uint8
from sksurgeryimage.utilities.weisslogo import WeissLogo
def test_logo():
"""
Test that we can make a nice looking logo
"""
logo = WeissLogo()
image = logo.get_logo()
assert image.shape == (331, 331, 3)
assert image.dtype == uint8
logo = WeissLogo(400)
image = logo.get_noisy_logo()
assert image.shape == (400, 400, 3)
assert image.dtype == uint8
......@@ -30,3 +30,12 @@ def test_prepare_text_overlay():
assert expected_large == large_text_overlay_properties
def test_noisy():
"""
tests function to add noise to a colour image.
"""
timage = np.zeros((10, 10, 1), np.uint8)
image = utilities.noisy_image(timage)
assert image.shape == (10, 10, 1)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment