Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find local maxima in grayscale image using OpenCV

Tags:

Does anybody know how to find the local maxima in a grayscale IPL_DEPTH_8U image using OpenCV? HarrisCorner mentions something like that but I'm actually not interested in corners ... Thanks!

like image 228
Durin Avatar asked Apr 05 '11 10:04

Durin


People also ask

How do I open an image in grayscale in OpenCV?

Step 1: Import OpenCV. Step 2: Read the original image using imread(). Step 3: Convert to grayscale using cv2. cvtcolor() function.

What is local maxima in image processing?

In image processing, the usual definition of a local maximum is that a pixel is considered to be a local maximum if and only if it is greater than or equal to all of its immediate neighbors. There is a convenient and efficient way to find all the local maxima pixels by using image dilation.

How do I convert an image to grayscale in Python cv2?

Method 1: Using the cv2.Import the OpenCV and read the original image using imread() than convert to grayscale using cv2. cvtcolor() function. destroyAllWindows() function allows users to destroy or close all windows at any time after exiting the script.


1 Answers

A pixel is considered a local maximum if it is equal to the maximum value in a 'local' neighborhood. The function below captures this property in two lines of code.

To deal with pixels on 'plateaus' (value equal to their neighborhood) one can use the local minimum property, since plateaus pixels are equal to their local minimum. The rest of the code filters out those pixels.

void non_maxima_suppression(const cv::Mat& image, cv::Mat& mask, bool remove_plateaus) {     // find pixels that are equal to the local neighborhood not maximum (including 'plateaus')     cv::dilate(image, mask, cv::Mat());     cv::compare(image, mask, mask, cv::CMP_GE);      // optionally filter out pixels that are equal to the local minimum ('plateaus')     if (remove_plateaus) {         cv::Mat non_plateau_mask;         cv::erode(image, non_plateau_mask, cv::Mat());         cv::compare(image, non_plateau_mask, non_plateau_mask, cv::CMP_GT);         cv::bitwise_and(mask, non_plateau_mask, mask);     } } 
like image 157
killogre Avatar answered Sep 17 '22 13:09

killogre