Peak detection in a 2D array

| | | | | | | | | | | | | | | | | | | | | |

👻 Check our latest review to choose the best laptop for Machine Learning engineers and Deep learning tasks!

I"m helping a veterinary clinic measuring pressure under a dogs paw. I use Python for my data analysis and now I"m stuck trying to divide the paws into (anatomical) subregions.

I made a 2D array of each paw, that consists of the maximal values for each sensor that has been loaded by the paw over time. Here"s an example of one paw, where I used Excel to draw the areas I want to "detect". These are 2 by 2 boxes around the sensor with local maxima"s, that together have the largest sum.

alt text

So I tried some experimenting and decide to simply look for the maximums of each column and row (can"t look in one direction due to the shape of the paw). This seems to "detect" the location of the separate toes fairly well, but it also marks neighboring sensors.

alt text

So what would be the best way to tell Python which of these maximums are the ones I want?

Note: The 2x2 squares can"t overlap, since they have to be separate toes!

Also I took 2x2 as a convenience, any more advanced solution is welcome, but I"m simply a human movement scientist, so I"m neither a real programmer or a mathematician, so please keep it "simple".

Here"s a version that can be loaded with np.loadtxt


Results

So I tried @jextee"s solution (see the results below). As you can see, it works very on the front paws, but it works less well for the hind legs.

More specifically, it can"t recognize the small peak that"s the fourth toe. This is obviously inherent to the fact that the loop looks top down towards the lowest value, without taking into account where this is.

Would anyone know how to tweak @jextee"s algorithm, so that it might be able to find the 4th toe too?

alt text

Since I haven"t processed any other trials yet, I can"t supply any other samples. But the data I gave before were the averages of each paw. This file is an array with the maximal data of 9 paws in the order they made contact with the plate.

This image shows how they were spatially spread out over the plate.

alt text

Update:

I have set up a blog for anyone interested and I have setup a SkyDrive with all the raw measurements. So to anyone requesting more data: more power to you!


New update:

So after the help I got with my questions regarding paw detection and paw sorting, I was finally able to check the toe detection for every paw! Turns out, it doesn"t work so well in anything but paws sized like the one in my own example. Off course in hindsight, it"s my own fault for choosing the 2x2 so arbitrarily.

Here"s a nice example of where it goes wrong: a nail is being recognized as a toe and the "heel" is so wide, it gets recognized twice!

alt text

The paw is too large, so taking a 2x2 size with no overlap, causes some toes to be detected twice. The other way around, in small dogs it often fails to find a 5th toe, which I suspect is being caused by the 2x2 area being too large.

After trying the current solution on all my measurements I came to the staggering conclusion that for nearly all my small dogs it didn"t find a 5th toe and that in over 50% of the impacts for the large dogs it would find more!

So clearly I need to change it. My own guess was changing the size of the neighborhood to something smaller for small dogs and larger for large dogs. But generate_binary_structure wouldn"t let me change the size of the array.

Therefore, I"m hoping that anyone else has a better suggestion for locating the toes, perhaps having the toe area scale with the paw size?

👻 Read also: what is the best laptop for engineering students?

We hope this article has helped you to resolve the problem. Apart from Peak detection in a 2D array, check other array Python module-related topics.

Want to excel in Python? See our review of the best Python online courses 2023. If you are interested in Data Science, check also how to learn programming in R.

By the way, this material is also available in other languages:



Julia Innsbruck

Prague | 2023-01-27

Maybe there are another answers? What Peak detection in a 2D array exactly means?. I am just not quite sure it is the best method

Chen Gonzalez

London | 2023-01-27

array Python module is always a bit confusing 😭 Peak detection in a 2D array is not the only problem I encountered. I am just not quite sure it is the best method

Javier Zelotti

Massachussetts | 2023-01-27

Maybe there are another answers? What Peak detection in a 2D array exactly means?. Checked yesterday, it works!

Shop

Gifts for programmers

Learn programming in R: courses

$FREE
Gifts for programmers

Best Python online courses for 2022

$FREE
Gifts for programmers

Best laptop for Fortnite

$399+
Gifts for programmers

Best laptop for Excel

$
Gifts for programmers

Best laptop for Solidworks

$399+
Gifts for programmers

Best laptop for Roblox

$399+
Gifts for programmers

Best computer for crypto mining

$499+
Gifts for programmers

Best laptop for Sims 4

$

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

1947 answers

PythonStackOverflow

Check if one list is a subset of another in Python

1173 answers

PythonStackOverflow

How to specify multiple return types using type-hints

1002 answers

PythonStackOverflow

Printing words vertically in Python

909 answers

PythonStackOverflow

Python Extract words from a given string

798 answers

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

606 answers

PythonStackOverflow

Python os.path.join () method

384 answers

PythonStackOverflow

Flake8: Ignore specific warning for entire file

360 answers

News


Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries

Python add suffix / add prefix to strings in a list

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

Python - Move item to the end of the list

Python - Print list vertically