Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <math_constants>
- param float th = 0 : range(-PI, PI); // orientation
- param float psi = 0 : range(-PI, PI); // phase
- param float lam = 1 : range(0.1, 10); // wavelength
- param float sig = 1 : range(0.1, 10); // envelope standard deviation
- param float gam = 1 : range(0.1, 10); // aspect ratio
- param int convSize = 11 : range(3, 101); // convolutional filter size
- image Input = file() : map(clamp);
- glsl vec4 gabor(vec2 position) {
- vec2 coords = position * 2.0 - 1.0;
- vec2 c_s = vec2(coords.x * cos(th) + coords.y * sin(th),
- -coords.x * sin(th) + coords.y * cos(th));
- float num = pow(c_s.x, 2.0) + pow(gam, 2.0) * pow(c_s.y, 2.0);
- float den = 2 * pow(sig, 2.0);
- float exp_term = exp(-num / den);
- float sin_term = sin(2.0 * PI * c_s.x / lam + psi);
- float gabor = exp_term * sin_term;
- return vec4(gabor, gabor, gabor, 1.0);
- }
- image Gabor = glsl(gabor, 301, 301);
- glsl vec4 convolve(vec2 position) {
- vec4 sum = vec4(0.0, 0.0, 0.0, 0.0);
- float filt_val = 0.0;
- for(int i = 0; i < convSize; ++i) {
- for(int j = 0; j < convSize; ++j) {
- float offx = (j - floor(convSize / 2.0)) * shadron_PixelSize.x;
- float offy = (i - floor(convSize / 2.0)) * shadron_PixelSize.y;
- float xpos = position.x + offx;
- float ypos = position.y + offy;
- vec4 currentPixel = texture(Input, vec2(xpos, ypos));
- float filtX = j / (convSize - 1.0);
- float filtY = i / (convSize - 1.0);
- vec4 filterPixel = texture(Gabor, vec2(filtX, filtY));
- filt_val += filterPixel.r;
- sum += currentPixel * filterPixel;
- }
- }
- return sum / filt_val;
- }
- image Output = glsl(convolve, sizeof(Input));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement