StyleTrans Houdini
1. Houdini + Python + Vex
2. Python style transfer
目标 goal
本次作业的目标是希望通过底层的语言(Python/Vex)和高层的软件(Houdini)混合使用,实现复杂艺术效果的创作。
The goal of this assignment is to achieve the creation of complex artistic effects through the mixed use of low-level language(Python/Vex) and high-level software(Houdini).
︎︎ 学习 Study
1. Houdini tutorial :
https://www.youtube.com/watch?v=emEux6cGOww
2. Houdini reference:
https://www.sidefx.com/docs/houdini/index.html
3.Houdini Python reference:
https://www.sidefx.com/docs/houdini/hom/index.html
4.Houdini Vex reference:
https://www.sidefx.com/docs/houdini/vex/lang.html
5.Python style transfer tutorial
https://www.youtube.com/watch?v=bFeltWvzZpQ&t=127s
https://www.youtube.com/watch?v=imX4kSKDY7s
https://www.youtube.com/watch?v=LoePx3QC5Js&t=12s
5. Tensorflow reference:
https://www.tensorflow.org/api_docs
6.OpenCV reference:
https://docs.opencv.org/master/
Some interesting works
Guest Tutorial: Dr. Jeroen Claus - Visualizing SARS-Cov-2 Spike Proteins (Rendering The Corona Virus):
https://vimeo.com/402495101
https://www.youtube.com/watch?v=emEux6cGOww
2. Houdini reference:
https://www.sidefx.com/docs/houdini/index.html
3.Houdini Python reference:
https://www.sidefx.com/docs/houdini/hom/index.html
4.Houdini Vex reference:
https://www.sidefx.com/docs/houdini/vex/lang.html
5.Python style transfer tutorial
https://www.youtube.com/watch?v=bFeltWvzZpQ&t=127s
https://www.youtube.com/watch?v=imX4kSKDY7s
https://www.youtube.com/watch?v=LoePx3QC5Js&t=12s
5. Tensorflow reference:
https://www.tensorflow.org/api_docs
6.OpenCV reference:
https://docs.opencv.org/master/
Some interesting works
Guest Tutorial: Dr. Jeroen Claus - Visualizing SARS-Cov-2 Spike Proteins (Rendering The Corona Virus):
https://vimeo.com/402495101
Python style transfer 风格迁移 :
content_image :
style_image :
Result :
Explanation 解释 :
︎︎︎GitHub
使用的库 libraris and packages:
import tensorflow_hub as hub |
import tensorflow as tf |
from matplotlib import pyplot as plt |
import numpy as np |
import cv2 |
#TF模型 TF Model model = hub.load('https://tfhub.dev/google/magenta/arbitrary-image-stylization-v1-256/2') |
#文件导入 File Load Fuction |
def load_image(img_path): |
img = tf.io.read_file(img_path) |
img = tf.image.decode_image(img, channels=3) |
img = tf.image.convert_image_dtype(img, tf.float32) |
img = img[tf.newaxis, :] |
return img |
#分别导入内容图片和风格图片 Load content and style image |
content_image = load_image('Example1.jpg') |
style_image = load_image('Example2.jpeg') |
content_image.shape |
plt.imshow(np.squeeze(style_image)) |
plt.show() |
#TF进行风格转换 TF style transfer |
stylized_image = model(tf.constant(content_image), tf.constant(style_image))[0] |
#生成图片的展示和储存 Generated pictures display and store plt.imshow(np.squeeze(stylized_image)) |
plt.show() cv2.imwrite('generated_img.jpg', cv2.cvtColor(np.squeeze(stylized_image)*255, cv2.COLOR_BGR2RGB)) |
Art work gallery:
Dog Pictures
Artist Works
Stryle Transfer
Houdini Work (Houdini + Python + Vex)
Houdini experiments
︎Mandelbrot set 2D(Python)
import numpy as np
import matplotlib.pyplot as plt
def mandelbrot(h,w,maxit=50):
y,x = np.ogrid[-1.4:1.4:h*1j,-2:0.8:w*1j]
c = x+y*1j
z = c
divtime = maxit + np.zeros(z.shape,dtype=int)
for i in range(maxit):
z = z**2 +c
diverge = z*np.conj(z) > 2**2
div_now = diverge & (divtime==maxit)
divtime[div_now] = i
z[diverge] = 2
return divtime
plt.imshow(mandelbrot(1000,1000))
plt.show()
import matplotlib.pyplot as plt
def mandelbrot(h,w,maxit=50):
y,x = np.ogrid[-1.4:1.4:h*1j,-2:0.8:w*1j]
c = x+y*1j
z = c
divtime = maxit + np.zeros(z.shape,dtype=int)
for i in range(maxit):
z = z**2 +c
diverge = z*np.conj(z) > 2**2
div_now = diverge & (divtime==maxit)
divtime[div_now] = i
z[diverge] = 2
return divtime
plt.imshow(mandelbrot(1000,1000))
plt.show()
︎Mandelbrot set 2D(VEX)
int ite = chi("../CONTROLLER/ite");
vector2 c = set(@P.x, @P.z);
vector2 v = set(0,0);
int isInf = 0;
int infIte = 0;
for(int i=0; i
float x = v.x * v.x - v.y * v.y + c.x;
float y = 2 * v.x * v.y + c.y;
v = set(x,y);
if(isInf != 1){
if(length(v) > 100){
isInf = 1;
infIte = i;
}
}
}
if(isInf == 1){
float col = fit(infIte, 0, ite-1, 0, 1);
f@col = col;
}else{
f@col = 0;
}
vector2 c = set(@P.x, @P.z);
vector2 v = set(0,0);
int isInf = 0;
int infIte = 0;
for(int i=0; i
float y = 2 * v.x * v.y + c.y;
v = set(x,y);
if(isInf != 1){
if(length(v) > 100){
isInf = 1;
infIte = i;
}
}
}
if(isInf == 1){
float col = fit(infIte, 0, ite-1, 0, 1);
f@col = col;
}else{
f@col = 0;
}
︎Mandelbrot set 3D
int iteration = chi("../CONTROLLER/iteration");
float n = chf("../CONTROLLER/n");
vector c = @P;
vector v = @P;
for(int i=0; i
float r = length(v);
float phi = atan2(v.y, v.x);
float theta = atan2(sqrt(v.x * v.x + v.y*v.y), v.z);
float vr = pow(r, n);
float vx = sin(n * theta) * cos(n * phi);
float vy = sin(n * theta) * sin(n * phi);
float vz = cos(n * theta);
v = set(vx, vy, vz) * vr + c;
if(length(v) > 100){
@density = 0;
}
}
float n = chf("../CONTROLLER/n");
vector c = @P;
vector v = @P;
for(int i=0; i
float phi = atan2(v.y, v.x);
float theta = atan2(sqrt(v.x * v.x + v.y*v.y), v.z);
float vr = pow(r, n);
float vx = sin(n * theta) * cos(n * phi);
float vy = sin(n * theta) * sin(n * phi);
float vz = cos(n * theta);
v = set(vx, vy, vz) * vr + c;
if(length(v) > 100){
@density = 0;
}
}
Rendered picture 渲染图片
Rendered picture style transfer
Other experiments