 # Applying a 4th order polynomial to each pixel of an image

Hi,

In summary, I conducted a camera calibration process to utilize my mirrorless camera as a luminance meter. This involves taking a series of images of a contrast panel at various levels of illumination. The contrast panel is then measured with a luminance meter to get known values of luminance. A relationship can then be determined between pixel intensity and luminance. Through this an equation is obtained that can be utilized to calculate a luminance value from grey scale intensity in the image.

Rather than draw regions of interest and then calculate the luminance value by hand, I would like to convert the entire image, adjusted by using the equation. I am interested in developing a macro that takes each pixel grey scale value intensity and applies a 4th order polynomial equation to that grey scale value. The result should return an image with the corresponding luminance value (new value).

new value = 2*(10^-8)(pixel grey scale value)^4 - 5(10^-6)(pixel grey scale value)^3 + 0.0005(pixel grey scale value)^2 +0.0063*(pixel grey scale value) + 0.0685

Let me know if anyone can provide some insight. Thanks!

Hi @dwolfe

Welcome to the forum.

Check out `Process > Math > Macro`.
You can type your equation in the code field like this

``````v=0.1*v*v*v*v + 0.1*v*v*v + 0.1*v*v + 0.1*v + 0.1
``````

but replace `0.1`'s with the coefficients of your polynomial.
The variable `v` here represents the pixel value (intensity).

using the imagej macro language, it would be this:

``````run("Macro...", "code=[v=0.1*v*v*v*v + 0.1*v*v*v + 0.1*v*v + 0.1*v + 0.1]");
``````

John

1 Like

Thank you! This is helpful.

However, the issue I am having is that the calculated pixel values are very small. Is there a way I can adjust the image intensity scale so I can my min value is say 0 to 10? Instead of 0 to 255. Also, is there a way to show the scale bar for intensity?

Thanks again, your help is greatly appreciated!

Before applying your polynomial, I’d recommend converting your image to 32bit if it’s not already ( you can do that with `Image > Type > 32-bit`).

you can show intensity scale with (`Analyze > Tools > Calibration bar`)

John