Re: math functions' point of view
Posted by dscho on Feb 14, 2006; 5:19pm
URL: http://imagej.273.s1.nabble.com/math-functions-point-of-view-tp3703556p3703562.html
Hi,
On Tue, 14 Feb 2006, Jarek wrote:
> 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.
You mean a new image, right? How about this macro:
-- snip --
xMin = -5; xMax = 5; yMin = -5; yMax = 5;
width = 400; height = 400;
function f(x) {
return 2 * x * x - 3;
}
newImage("Math", "8-bit White", width, height 1);
for (i = 0; i < width; i++) {
x = xMin + i * (xMax - xMin) / (width - 1);
y = f(x);
j = height - 1 - (y- yMin) * (height - 1) / (yMax - yMin);
if (j >= 0 && j < height)
setPixel(i, j, 0);
}
-- snap --
> If there is a chance to do it, is it possible to re-construct real image into
> artificial one?
You want to fit data to a function? That probably requires more knowledge
about the function, but should be feasible.
Ciao,
Dscho