Find peaks, table manipulation in imageJ and missing values

Dear ImageJ experts,

I have an issue in writing a macro that I couldn’t solve for a while.
Here is my problem:

I have a plot profile with peaks. I use the BAR plugin for peak detection (“Find Peaks”) and then I get a result table with the detected peaks (columns “X1”, “Y1”, “X2”, Y2"). Then with my macro I usually retrieve the values from those columns. This works very fine but sometimes, there are no peaks to be detected in my profile. When this is the case, I have an empty table. Because the result table is empty, there are no values to retrieve and my macro ends with an error. :confused:

My question is, is there a way to directly get the number of detected peaks directly out of the BAR plugin (get “0” if no peaks detected)? Like that I could implement in my macro "if (peaks == 0) {don’t use this profile}.

Another way I was thinking, can imageJ know if the table is empty and retrieve a “0” or “NaN” ?
Cause I couldn’t get this to work either. For example if I write:

selectWindow(“Results”);
test = Table.get(“Y1”, 0);
print(test);

I have the message that “row(0) out of range”… of course because there are no value.

In more simple words, when there is a table with no value inside, is there a way for imageJ to detect it?

I hope I was clear but in case not, let me know and I’ll try to explain my problem better.
Thanks a lot in advance for the help.

Guillaume

Hi
@Guillaume1

You have a discussion on a “sentinel” test here:


Greetings

Hi Mathew,

Thanks for your answer. However I’m afraid I don’t fully understand the conversation you have linked with the “sentinel”. I tried the test from the other topic but it doesn’t work for me (even if I update FIJI).

I think for my problem, the easiest way would be to retrieve as “0” or “empty” or “NaN” if a table is empty but I couldn’t find a way to write that down in a macro.

EDIT: I tried few things, and I understand a bit more where is the problem.

It works if I create a table with an empty column " ", I can retrieve a “NaN”

Table.create(“table1”);
Table.set(“column”, 0, “”);

selectWindow(“table1”);
value = Table.get(“column”, 0);
print(value);

==> it prints “NaN”.

BUT, it doesn’t work if I create an empty array:

b = newArray(0);
Table.create(“table1”);
Table.setColumn(“column”, b);

selectWindow(“table1”);
value = Table.get(“column”, 0);
print(value);

==> error “Row(0) out of range in line 6”.
And the problem is that usually, with the find peak, I have an array to retrieve because there are several peaks (or none, haha).

Hi,

I finally got a solution to my problem so I’ll share it here.
So in my previous example,

b = newArray(0);
Table.create(“table1”);
Table.setColumn(“column”, b);

selectWindow(“table1”);
value = Table.get(“column”, 0);
print(value);

=> This doesn’t work because it’s an empty Array in the column and it’s not possible to print an empty array.
But I can get it if I ask the lengh of the array:

b = newArray(0);
Table.create(“table1”);
Table.setColumn(“column”, b);

selectWindow(“table1”);
value = Table.getColumn(“column”);
LenghValue = lengthOf(value);
print(LenghValue);

==> I get “0” in the print log.

To come back to the find peaks, the simplest way to get the number of peaks (maxima) and minima is then like that:

//Get number of maxima
selectWindow(“Plot Values”);
Maxima = Table.getColumn(“X1”);
NbMax = lengthOf(Maxima);
print(NbMax);

//Get number of minima
selectWindow(“Plot Values”);
Minima = Table.getColumn(“X2”);
NbMin = lengthOf(Minima);
print(NbMin);

Here are 2 example of the find peak windows (plugin from BAR), one with peaks and another without:

Hope this can help someone.

2 Likes

I am a bit puzzled by your comments above.
What is your definition of maxima and minima? The top graph above has a global maxima and a minima, several regional maxima and regional minima as well as lots of local maxima and local minima.
See: Vincent L. Morphological greyscale reconstruction in Image Analysis: Applications and efficient algorithms. IEEE Trans Image Proc 2(2) 176-201, 1993.

Hi Gabriel,

So the “Peak detection” from the BAR plugin gives the coordinates of the peaks found in a plot-profile (columns X1 and Y1) and it also gives the coordinates of the minimum values found (columns X2 and Y2).
My objective was to know how many peaks=maxima it could find and also how many minima. As written in the graph I showed in the example where there are peaks (4 maxima in red and 5 minima in blue).
Then by counting in the Plot Values windows how many entries are in the array (of X1/Y1 and X2/Y2), I can get the number of maxima and of minima.

Hi Guillaume1, my comment was about the top graph where you said “one without” (minima and maxima?). I wonder if you are meaning “without showing them” because the top graph has all of those I mentioned.
Haven’t used or know what the BAR plugin is, although the names being used have specific definitions.

Ok, I think I see what you mean.

So in the BAR peak detection plugin, you can define a minimum value for which you want to detect a peak (“min peak amplitude”). In my first example where I considered there is no peak to be detected, I put the threshold at 110 (Min amp.) so it can’t detect any peak. But indeed, if I would have put the threshold at 10, it would have detected many of the small peaks in the profile.

I usually define this threshold by taking the average of my whole signal and divided it by 10 because I found this accurate for my data, here it would be around 37 and it would have detected some small peaks. But because I wanted to show an example with no peak detected (which was my problem to write the macro for), I on purpose choose a high value of 110.

1 Like

Thanks for clarifying!