Posted by
dscho on
Jan 20, 2009; 9:54am
URL: http://imagej.273.s1.nabble.com/entering-an-equation-tp3694011p3694015.html
Hi,
[really re-adding the list, as this might be useful for others, too.]
On Tue, 20 Jan 2009, shay ros wrote:
> Yes you are right, I use the calculator plus to divide two images. The
> values (ratio) that I get are changed according to the concentration of
> a specific chemical.
>
> Since the real concentration is in correlation to the ration values I
> would like two produce images that the value will be the concentration
> (in % from control ).
>
> For that purpose I have two enter an equation. For example: if X is the
> ratio value
>
> Concentarion = x-0.6/(0.5*x+0.3)
So you want this for every pixel, right?
The easiest way to do that is IMHO to use the macro language:
-- snip --
// make sure that the values are floating point (high precision)
run("32-bit");
// iterate over all pixels
for (y = 0; y < getHeight(); y++)
for (x = 0; x < getWidth(); x++) {
value = getPixel(x, y);
// evaluate the formula
newValue = value - 0.5 / (0.5 * x + 0.3);
setPixel(x, y, newValue);
}
-- snap --
Note that I talk about a formula here. A free-form equation -- something
like "cos(newValue) = sin(value)" -- would require third-party libraries
to solve the equation (such as Yacas or Jasymca, or SymPy via Jython), and
therefore you'd need to use another scripting language, such as
Javascript, Jython, JRuby or Clojure (see
http://pacific.mpi-cbg.de/wiki/index.php/Category:Scripting).
Hth,
Dscho