Re: math functions' point of view
Posted by
Jarek Grodek on
URL: http://imagej.273.s1.nabble.com/math-functions-point-of-view-tp3703556p3703564.html
Wayne Rasband napisaĆ(a):
>> I'm newbie to ImageJ and wondering is there a possibility to
>> make it to create an artificial image according to specified
>> mathematic function, e.g. y=2x^2+b.
>
> Here is a macro that uses a math function to generate an image.
>
> -wayne
>
> width = 500; height = 500;
> xc = width/2; yc = height/2;
> newImage("Math", "32-bit", width, height, 1);
> for (y= 0; y<height; y++) {
> for (x= 0; x<width; x++) {
> xx = sqrt ((x-xc)*(x-xc)+(y-yc)*(y-yc));
> setPixel(x, y, f1(xx));
> }
> if (y%20==0) showProgress(y, height);
> }
> resetMinAndMax();
> makeLine(0, 0, width, height);
> run("Plot Profile");
> exit;
>
> function f1(x) {return 2*x*x-3;}
> function f2(x) {return cos(x/10);}
> function f3(x) {return sqrt(x);}
> function f4(x) {if (x==0) return 0; else return log(x);}
> function f5(x) {return exp(x/100);}
>
>
>
WOW!
Wayne, thank you very much, i'm impressed of your help. This is exactly
what i was looking for: the example of macro construction.
Greetings
jarek