Ask Your Question
0

How to find whether the position is a Peak position in a kernel window?

asked 2017-09-14 09:40:26 -0600

Karthikeyan gravatar image

updated 2017-09-27 05:08:17 -0600

I am searching for an OpenCV function that replicates the function of peak_local_max in scikit-image. What this function does is, It compares the values over a window of mentioned size whether the anchor point value is greater than or equal to the maximum of other positions or not. If the case satisfies, it considers it as a local peak.

Example of what I want,

image description

Consider my image is 5x5 and I want to find the local peaks in the window size of 3x3. If you could apply the criteria I explained in the question(It compares the values over a window of mentioned size whether the anchor point value is greater than or equal to the maximum of other positions or not), only one value satisfies 10.79. But in the case of minmaxloc it will find first 10.79 later after the mask is updated it will give 10.6 but 10.6 is definitely not the local peak and we wont know when to stop.

Is there a OpenCV function that could do this job? I know about minmaxLoc and minmaxIdx but it calculates for global frame which I am not interested. I am thinking of taking the filter2D function as reference and create my own functionality to do this. On the parallel side I want your suggestions to go about this problem?

Any help could be really appreciated. Thanks in advance!

edit retag flag offensive close merge delete

Comments

may this post will help you

LBerger gravatar imageLBerger ( 2017-09-14 09:59:19 -0600 )edit

I mentioned in the question itself, I know about the minMaxLoc but that is not what I expected. Thanks for your help

Karthikeyan gravatar imageKarthikeyan ( 2017-09-15 04:33:04 -0600 )edit

" but it calculates for global frame" no there is a mask. You have to adjust mask relative to the window size you need

LBerger gravatar imageLBerger ( 2017-09-15 04:41:22 -0600 )edit

Got your point! Firstly I don't wan to find the maximum in the window. I want to find the peak whether the anchor point contains the maximum value or not. Secondly My window size is 5x5. For the image of 1280x720 how efficient is this thing?

Karthikeyan gravatar imageKarthikeyan ( 2017-09-15 05:09:46 -0600 )edit

anchor ? filter2D is convolution so anchor is everywhere. I don't understand. A small example is welcome

LBerger gravatar imageLBerger ( 2017-09-15 05:56:59 -0600 )edit

@LBerger: updated my question and I got my answer as well thanks for your help

Karthikeyan gravatar imageKarthikeyan ( 2017-09-27 05:09:35 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2017-09-27 04:38:51 -0600

Karthikeyan gravatar image

Hey I found my answer. I used the logic behind dilate operation to find the peak local maximum. It would be very simple than minmaxloc.

Quick background of Dilate operation

As the kernel is scanned over the image, we compute the maximal pixel value overlapped by the kernel and replace the image pixel under the anchor point with that maximal value.

I used this to my advantage, so the maximum value around the window remains the same even when dilation operation is happening, which is our peak value. I did dilation followed by equality comparison to extract the peak positions alone.

//Threshold operation
threshold_frame(input_frame, threshold_frame, threshold_value, max_value, THRESH_BINARY)

//Finding the peak locals 
dilate(threshold_frame, dilate_frame, dilateKernel, Point(-1,-1), 1);
peak_local_frame = (dilate_frame == threshold_frame);
edit flag offensive delete link more

Comments

But as you can see, you are manually thresholding(threshold_value, max_value) the Image and you may need to find this value dynamically in many cases. Since your actual problem is to find the Local Maximum, I think this approach is not an optimum solution! What if the Maximum Value goes less than your threshold?

Balaji R gravatar imageBalaji R ( 2017-09-27 04:44:48 -0600 )edit

I quoted threshold image as a sample. In fact, I feel minmaxloc wont work for my case at all. Let me update my question with an example

Karthikeyan gravatar imageKarthikeyan ( 2017-09-27 04:57:15 -0600 )edit

Indeed this approach is a quite faster alternative! But this Threshold in your code is misleading! Anyway here is a similar question! http://answers.opencv.org/question/28...

Balaji R gravatar imageBalaji R ( 2017-09-27 08:57:28 -0600 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-09-14 09:40:26 -0600

Seen: 57 times

Last updated: Sep 27