The Minimum/Maximum Location algorithm performs a 2D search operation on the input image. The algorithm looks for the minimum and maximum values of the pixels, which results in two sets of pixel locations for the minimum and maximum values. The locations are the \((x,y)\) coordinates of the pixels matching exactly the global minimum or maximum value. This operation is useful to locate peaks on an image, either highest or lowest or both.
This example shows an input image on the left with its corresponding minimum (blue) and maximum (red) locations on the right.
Input
Output
Implementation
The algorithm searches for the minimum and maximum values in the input image. Each pixel matching the minimum value has its location stored in an output array. The same is done for the maximum value in a second output array. Multiple locations of the same value, either minimum or maximum, may be found.
The location in the image is a keypoint with \((x, y)\) coordinates, corresponding to the \((j, i)\) matrix-based coordinates, respectively. The locations are stored in the user-provided output array up to the array capacity, which is defined upon array creation. This is done for both minimum and maximum output arrays. The maximum number of locations returned may be different for each array, as their corresponding capacity might differ. The user may choose not to provide an output array (by passing NULL in the argument) in which case the corresponding locations will not be searched for.
C API functions
For list of limitations, constraints and backends that implements the algorithm, consult reference documentation of the following functions:
Optionally, retrieve the minimum and maximum values.
Lock the input image and the minimum/maximum output arrays to efficiently access their contents.
with input.rlock_cpu() as in_data, min_coords.rlock_cpu() as min_data, max_coords.rlock_cpu() as max_data:
Retrieve the coordinates of the first pixels with minimum and maximum values. The (x,y) coordinates are being swapped to (y,x) and converted into a tuple, suitable for 2D numpy array indexing.
min_loc = tuple(min_data[0].astype(int)[::-1])
max_loc = tuple(max_data[0].astype(int)[::-1])
Use the first of these coordinates to retrieve the minimum/maximum pixel value.
min_value = in_data[min_loc]
max_value = in_data[max_loc]
Initialization phase
Include the header that defines the needed functions.
Create the output arrays for coordinates with minimum and maximum values. In this example, their capacity it set to 10,000, which limits the number of locations to be found.
Use these coordinates as a 2D index to the input image contents to retrieve the minimum/maximum pixel value. Here it's assumed that the input image format is VPI_IMAGE_FORMAT_U8. Different indexing must be employed for other formats.
// Assuming that the input image is grayscale (only one plane).