Ejemplo n.º 1
0
import sys
sys.path.append("..")
from ImageManipulation.Imgmanip import Imagemanip
from FourierApproximation.Class_fourierApproximation import FourierApprox
import unittest

url = 'https://www.seekpng.com/png/detail/116-1164659_line-drawing-bunny-rabbit-at-getdrawings-bunny-drawing.png'
Img = Imagemanip(url)
Img.single_color()
Img.convert_binary(scale=3, thresh_val=200)
Img.black_and_white()
Img.distance_matrix()
Img.contours_search()
Img.get_splines()


class TestFourierApprox(unittest.TestCase):
    def test_FourierApprox_is_instance_of_FourierApprox(self):
        """ Assert that the Fourier object is created """
        xFT = FourierApprox(Img.x_spl, (0, Img.length_pixels), num_circles=50)
        self.assertIsInstance(xFT, FourierApprox)

    def test_origin_offset_is_float(self):
        """ Assert that the attribute origin_offset of the FourierApprox object is a float """
        xFT = FourierApprox(Img.x_spl, (0, Img.length_pixels), num_circles=50)
        self.assertIsInstance(xFT.origin_offset, float)

    def test_circles_approximation_offset_is_float(self):
        """ Assert that the attribute circles_approximation_offset of the FourierApprox object is a float """
        xFT = FourierApprox(Img.x_spl, (0, Img.length_pixels), num_circles=50)
        self.assertIsInstance(xFT.circles_approximation_offset, float)
from scipy.interpolate import UnivariateSpline
from IPython.display import Image as DisplayImage
import sys
sys.path.append("..")
from ImageManipulation.Imgmanip import Imagemanip
from FourierApproximation.Class_fourierApproximation import FourierApprox
from Circles_radii_center.ComplexCircles import Circles

# %%
url = 'https://reussiralecole.fr/wp-content/uploads/2020/09/coloriage-pokemon-01.jpg'
img = Imagemanip(url)
img.single_color()
img.convert_binary(scale=2, thresh_val=200)
img.black_and_white()
img.distance_matrix()
img.contours_search(plot=False)
img.get_splines(plot=False)

x_spl = img.x_spl
y_spl = img.y_spl
num_pixels = img.length_pixels
# Number of circles to draw in animation
num_circles = 100
anim_length = 20  # in seconds
fps = 24  # frames per second
num_frames = anim_length * fps
interval = (1. / fps) * 1000

# Ensure that the approximation has at least 2000
# points to ensure smoothness
dt = (int(2000. / num_frames) + 1)