How to find gradient of Tiff file pixels?

Hello all,

I am working with some propagating, gaseous, waves. I want to measure wave speed on the normal direction of it’s wave front.

I would like to be able to find a gradient field of a given tiff file, then find the pixels with the highest gradient values (Wave Front). Then with these points in xy space, I would potentially fit a curve on this wave front which would be updated for each consecutive slice. It would probably require a good deal of code in Python or any other software (Suggestions would be appreciated) but I would like to know how to start with getting the gradient of my tiff files first!

Here are some examples of two kinds of waves, montaged:
image
image

Thank you for any and all input!
~Vasko

Hi Vasko,
Edge detectors are actually based on gradient detection.
So you could try something like the sobel edge detector using high kernel size (like 5 or 7)
In Fiji its at Process>Find edges

From the edge you could try to fit a line indeed.
Because you have a timelapse, you could also try to subtract images like Next-Previous and run the edge detection on the subtracted image.

If you post some separate pictures maybe we can try stuff, also what do you want to measure in the end exactly ?

I would strongly consider @LThomas’s suggestion. Edge detectors incorporate both the prerequisite smoothing operation to attenuate noise in your image.

If you really want to do exactly what you say, you could probably do this in several lines of python.

Use this to read in your image:
https://scikit-image.org/docs/stable/api/skimage.external.tifffile.html#skimage.external.tifffile.imread

This function will calculate the gradient:
https://docs.scipy.org/doc/numpy/reference/generated/numpy.gradient.html

Hi Thomas,
I attempted the Process>Find edges method and got the following results. My images are already have the background subtracted, and the contrast is bumped up a good bit. This causes quite a bit of constant noise so the “Find edges” seems to pick out a lot of extra edges.
image

How would I go about fitting a line? My end goal is to get the speed of the wave, as it propagates frame by frame.

Dear Vasko,
do you have some literature from where we can see how they measure the wave front speed?

Could you please also upload some original tiff images where we can try some approach?

thanks,
Emanuele Martini

That link is perfect! I will consider both options for sure. At the moment it does not seem like the “edge finding” command has much customization so I believe I might have to move towards making my own smoothing and edge finding operations.

~Vasko

This is expected indeed, either you use a larger kernel (which is not possible in ImageJ/Fiji but in Python/OpenCV yes) and/or you reduce the noise by applying some smoothing on the image (gaussian, mean or median filter) BEFORE running the edge detector.

I am thinking that you could alternatively use registration of one frame to the next to find the amplitude of the translation. If you expect a linear translation.

Like in Plugins>Registration in Fiji


The save transforms will contain the x and y displacement.
Feel free to try other registration method.

Not even sure you need to fit a line, if you threshold the edge map to get the strongest edge, then connected component analysis to pick the biggest object and use the coordinates of the center of mass as a reference point to calculate the speed.

maybe it could be also interesting try to implement this method:
http://www.arts-pi.org.tn/rfmi2017/papers/13_CameraReadySubmission_RFMI2017_Cameraready.pdf

The simplest thing to do to suppress the edges in the background is to apply some Gaussian smoothing.

https://imagej.nih.gov/ij/docs/menus/process.html#smooth

https://imagejdocu.tudor.lu/gui/process/filters#gaussian_blur

This little macro should get you the numbers you need to calculate delta pixels/slice. You’ll need to calibrate the image to get a numerical velocity. I noticed that the double quotes are not the right kind, so you’ll need to replace them in ImageJ if you copy and paste the code…This is new.

run(“Close All”);
close(“Log”);
showMessage(“DIRECTION”, “Select OK and then select a strip of frames”);
open("");
originaltitle =getTitle();
getDateAndTime(year, month, dayOfWeek, dayOfMonth, hour, minute, second, msec)
colls = getNumber(“Enter the # of columns in the strip”,5);
run(“Montage to Stack…”, “columns=”+colls+" rows=1 border=0");
rename(“wavesStack”);
setTool(“point”);
print("--------------New Data--------------\n"+originaltitle+"\n"+month+"/"+dayOfMonth+"/"+year+" “+hour+”:"+minute);
for(i=1;i<=nSlices;i++){
waitForUser(“click on the wave’s peak…then OK”);
getSelectionBounds(x, y, width, height);
print("Frame “+i+”\n x = “+x+”\n y = "+y);
selectImage(“wavesStack”);
run(“Next Slice [>]”);
}
print(“You will be able to calculate delta pixels/frame with these #s”);
exit();

Ron DeSpain

Here’s the macro as an upload…I’ve never tried this before, so I don’t know if it will work.
Looks like I can’t upload the macro file.

it’s output is this:

--------------New Data--------------
waves2.png
8/25/2019 11:42
Frame 1
x = 39.5
y = 39.1667
Frame 2
x = 31
y = 47.6667
Frame 3
x = 24.3333
y = 54
Frame 4
x = 19.1667
y = 59.1667
Frame 5
x = 15.3333
y = 62.8333
You will be able to calculate delta pixels/frame with these #s

This is the image:
image

Ron DeSpain

Here are some interesting edges

Orig edges w circles.tif (471.1 KB) Orig edges.tif (470.4 KB)

It looks like the center of your flame front may be moving.

Ron DeSpain