Apply a formula on each pixel of 2D image

Hi !

I want to develop a plugin who create a raw image and change each value of thé image by applying a formula I(x,y).

Do you have any clues to create an image that I will have access to each pixel value and modify them in a double for loop ?

At the end I search to be able to display that new Image and save it.

Thank You very much and have a nice day !

Hi @Cpl-042,

You probably don’t have to address each pixel individually, at least if the formula is solely based on the grey value of the image. Or do you take a region of the central pixel into account?

Two tricks if you only use the grey value of pixel at (x,y); use changeValues(gv,gv,ngv) where gv is the grey value and ngv = formula(gv), or create a lookup table, fill entry gv with ngv for every grey value, the apply lut.

If you need to access the environment of the pixels, start Plugins>Macros>Record, then perform your steps to get to a new pixel value (you can select one single pixel if you zoom in far enough), then in a Plugins>New>Macro create a for loop around what you just recorded.
Loops are common in the forum, just search for setPixel( together with for in the magnifier glass top right of this forum and you’ll find plenty of examples.

Check this
https://imagej.nih.gov/ij/macros/ApplyFunctionToImage.txt

Hello !

Thank You both very much it helped me !

Phaub, it was exactly what I needed ! Can I ask You if You have an other plugin to Help me to do the same Work but with a third dimension z ?

The next step is to transform my formula into x,y,z Dimensions .

Have a great day !

The 3rd dimension is usually represented in a ImageStack by individual slices. So, search macro examples for stack processing.
The relevant command is

setSlice(n)
(https://imagej.nih.gov/ij/developer/macro/functions.html#S)

See if you find some helpful information here:

Getting started with ImageJ1 macros