This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from math import sin, cos | |
struct Array[T: AnyRegType]: | |
var value: T | |
var rows: Int | |
var cols: Int | |
var total_items: Int | |
var data: Pointer[T] | |
fn __init__(inout self, value: T, rows: Int, cols: Int) -> None: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
n = 5 | |
alpha = 0.2 | |
p = 0.8 | |
summ = 0 | |
for i in range(n): | |
summ += p*(alpha**i) | |
prev_votes = np.floor(n_clusters*np.random.rand(4, n)-0.000001) | |
boundary = np.zeros(n) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# VGG16 is used as pretrained CNN model | |
vgg_model = VGG16(weights='imagenet', include_top=False, input_shape=(512, 512, 3)) | |
model = keras.Sequential() | |
for layer in vgg_model.layers: | |
model.add(layer) | |
model.add(Flatten()) | |
model.add(Dense(512, name='embeddings')) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Flattening the mesh | |
vertices = np.array(mesh.vertices) | |
vertices[:, 2] = vertices[:, 2].mean() # Replacing the depth value with the mean depth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Function to plot the mesh | |
def plot(triangles, vertices): | |
fig = go.Figure( | |
data=[ | |
go.Mesh3d( | |
x=vertices[:,0], | |
y=vertices[:,1], | |
z=vertices[:,2], | |
i=triangles[:,0], | |
j=triangles[:,1], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Loading the mesh | |
mesh = o3d.io.read_triangle_mesh("bunny.obj") | |
# All this is needed for plotting the mesh properly | |
if not mesh.has_vertex_normals(): mesh.compute_vertex_normals() | |
if not mesh.has_triangle_normals(): mesh.compute_triangle_normals() | |
triangles = np.asarray(mesh.triangles) | |
vertices = np.asarray(mesh.vertices) | |
colors = None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
generated_image = weights[0]*style1_image + weights[1]*style2_image + weights[2]*style3_image |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Final function to return some random crease from 8 different types | |
def custom_crease(): | |
spacing = random.uniform(1, 1.5) | |
scale = random.randint(100, 300) | |
corner = random.randint(1, 4) | |
# constant determines the type of crease and also is used to scale spacing in parabolic_crease | |
constant = random.randint(1, 10) | |
# Returning those creases which are based on parabolic |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def parabolic_crease(spacing, c, scale=100, corner=1, resolution = 1000): | |
""" | |
Parameters: | |
spacing = controls how close the intermediate values will be to lower value | |
c = higher the c more spread out the gradient will be | |
scale = lesser the scale more concentrated is gradient towards the corner | |
""" | |
img = np.zeros((resolution, resolution)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# cross = True if cross crease is wanted | |
def create_uneven_array(low, up, steps, spacing=1, cross=False): | |
span = up - low | |
dx = 1.0 / steps | |
if cross: | |
arr = np.array([low + (i*dx)**spacing*span for i in range(steps//2)]) | |
return np.append(arr, arr[::-1]) | |
else : | |
arr = np.array([low + (i*dx)**spacing*span for i in range(steps)]) | |
return arr |