4 public static class Figures
\r
7 public static void drawGrating(out Image img, int width , int height, double frequency, double contrast, double orientation, double phase)
\r
9 if(img.width != width || img.height != height) img = new Image(width, height);
\r
10 double xp, yp, r, freq = frequency*2*PI;
\r
11 for(int y=0; y<height; y++) {
\r
13 for(int x=0; x<width; x++) {
\r
15 r = sqrt(xp*xp+yp*yp);
\r
18 0.5+0.5 * contrast* cos(freq* (sin(orientation)*xp-cos(orientation)*yp) + phase)
\r
25 public static void drawGaussian(out Image img, double sigma, double factor)
\r
27 const int width = (int)(sigma * 8), height = (int)(sigma * 8);
\r
28 if (img.width != width || img.height != height) img = new Image(width, height);
\r
29 double xp, yp, r, r2;
\r
30 for(int y=0; y<height; y++) {
\r
32 for(int x=0; x<width; x++) {
\r
34 r = sqrt(xp*xp+yp*yp);
\r
35 r2 = -(r*r) / (2.0*sigma*sigma);
\r
36 img.pix_raw(x,y,Color(factor*(exp(r2))));
\r
42 public static void drawGabor(out Image img, double sigma, double wavelength, double contrast, double orientation, double phase)
\r
44 int width = (int)(sigma * 8), height = (int)(sigma * 8);
\r
45 //if (img.width != width || img.height != height)
\r
46 img = new Image(width, height);
\r
47 double freq = 2 * Math.PI / wavelength;
\r
49 (x, y) => new Color(.5 + Math.gaussian(Math.radius(x - width, y - height), width / 8.0) * .5 * Math.sin(phase + x * freq))
\r