# LabVIEW

cancel
Showing results for
Did you mean:

## 2D data peak/valley detection

Hi,

I need to point out all pixels that are peaks and valleys in my 2D array. I thought that I would point them out by building imaginary part of my array and changing corresponding values to 0 and 1 (valley, peak). My question is how to do it quickly and softly. I tried peak detector vi's but they all seem to work with 1D signal only (I cannot change my array to 1D, cause the only condition for peak is that the pixel must have higher value than all 8 closest pixels and 2D - 1D conversion will take it line by line).

Help 🙂

Message 1 of 14
(3,057 Views)

## Re: 2D data peak/valley detection

Hi,

I don't think there is an VI already implemented for that.

Can you give more specific information, how big is your array and which are your timming constrains? The first step would be to implement by yourself a very simple alghorithm as taking by the rows from that array and comparing the data to the neighbours (A[i][j] compared to A[i-1][j], A[i+1][j], A[i][j-1] ... and so on)

Can you post a text file with your values?

Best regards,

I.R.

Message 2 of 14
(3,021 Views)

## Re: 2D data peak/valley detection

Ok, I didn't describe the problem properly. My 2D array represents 3D surface topography.I need to calculate specific surface parameter. The array is 256x256 and values are generally somwhere between -50 and 50. Now I need to determine how many peaks/pits there are in each interval <-50;-49), <-49; -48), <-48; -47) and so on up to <49; 50). I tried to make double FOR loop so it would check each point separately, and then a while loop inside, but it went out of memory.

Vi attached. I replaced my array with one filled with random numbers but it didn't make any difference. What is wrong?

Message 3 of 14
(2,984 Views)

## Re: 2D data peak/valley detection

Hi Ofic,

do you need a simple histogram? Why not use the histogram functions?

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 4 of 14
(2,980 Views)

Histogram won't tell me about peaks and pits, only about amplitude distribution. I need something like... a histogram, that takes only peaks, and another that takes only pits. Maybe remove other points from the array somehow?

Message 5 of 14
(2,974 Views)

## Re: Histogram won't tell me about peaks and pits, only about...

Hi Ofic,

Now I need to determine how many peaks/pits there are in each interval <-50;-49), <-49; -48), <-48; -47) and so on up to <49; 50).

Sounds like you need a histogram over your data with an interval width of 1. Easily to get with the histogram function as shown above...

Best regards,
GerdW

using LV2011SP1 + LV2017 (+LV2020 sometimes) on Win10+cRIO
Message 6 of 14
(2,971 Views)

## Ok I get it. I will use histograms later. First I need to...

Ok I get it. I will use histograms later.

First I need to get rid of all non-peak and non-pit points by replacing them with zeros. My vi. doesn't work and I'm not sure if I know why. I want to receive an array with zeros and (if the point is a peak) values of the points.

Vi. attached.

I thought that the problem is maybe that the program doesn't know next rows until it gets there, but I don't know how to avoid it.

Message 7 of 14
(2,949 Views)

## Re: Ok I get it. I will use histograms later. First I need to...

Hi,

Basically it searches in the 2D arrays for peaks, and returns back an array of cluster, each cluster contains two integer value (row and column number) where there was a peak detected.

Best regards,

I.R.

Message 8 of 14
(2,943 Views)

## Re: Ok I get it. I will use histograms later. First I need to...

I need the value of the peak too.

Message 9 of 14
(2,934 Views)

## Re: Ok I get it. I will use histograms later. First I need to...

well, you can parse one more time and extract the values, now that you know the coordinates, it is easy to read the peak values.

Best Regards,

I.R.

Message 10 of 14
(2,920 Views)