Commit 2a0e2c10 authored by Stephen Thompson's avatar Stephen Thompson

Merge branch '6-logo-from-surgery-image'

parents d0e90fe8 9e48ab33
Pipeline #4198 canceled with stages
......@@ -52,6 +52,7 @@ setup(
install_requires=[
'opencv-contrib-python',
'scikit-surgeryimage>=0.6.0',
'scikit-surgeryutils',
'scikit-surgerynditracker',
'scikit-surgeryarucotracker',
......
"""Functions for snappysonic"""
from math import cos, pi
from numpy import full, int32, uint8
from cv2 import randn, fillConvexPoly, circle
def noisy(image):
"""
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
"""
mean = 0
stddev = (50, 5, 5)
randn(image, (mean), (stddev))
return 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(self._background.copy())
return self._background + noise
......@@ -5,12 +5,12 @@ from PySide2.QtWidgets import QLabel, QWidget
from cv2 import (rectangle, putText, circle, imread)
from numpy import zeros, uint8
from sksurgeryutils.common_overlay_apps import OverlayBaseApp
from sksurgeryimage.utilities.weisslogo import WeissLogo
from snappysonic.algorithms.algorithms import (configure_tracker,
lookupimage,
check_us_buffer,
get_bg_image_size,
numpy_to_qpixmap)
from snappysonic.algorithms.logo import WeissLogo
class OverlayApp(OverlayBaseApp):
"""Inherits from OverlayBaseApp,
......
# coding=utf-8
"""snappysonic tests"""
from numpy import uint8, zeros
from snappysonic.algorithms.logo import WeissLogo, noisy
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
def test_noisy():
"""
tests function to add noise to a colour image.
"""
timage = zeros((10, 10, 1), uint8)
_ = noisy(timage)
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