local_min/local_max
Usage
Traverses all pixels based on a sliding window, and calculates the maximum or minimum value in the sliding window centered on the current pixel, and uses the value as the pixel of the output image at the current position.
Interface
1 2 | void kcv_LocalMax_acc(const double *_src, double *_dst, size_t src_rows, size_t src_cols, size_t window_rows, size_t window_cols); void kcv_LocalMin_acc(const double *_src, double *_dst, size_t src_rows, size_t src_cols, size_t window_rows, size_t window_cols); |
Parameters
Parameter |
Description |
Value Range |
Input/Output |
|---|---|---|---|
src |
Input image. |
Not null. The size of the allocated memory is src_rows*src_cols*sizeof(double). |
Input |
dst |
Output image. |
Not null. The size of the allocated memory is the same as that of src. |
Output |
src_rows |
Number of rows of the input image. |
(0, 16384] |
Input |
src_cols |
Number of columns of the input image. |
(0, 16384] |
Input |
window_rows |
Number of rows of the sliding window. The value must be an odd number. |
(0, src_rows] |
Input |
window_cols |
Number of columns of the sliding window. The value must be an odd number. |
(0, src_cols] |
Input |
Return Values
- Success: LITHO_IMG_STS_NO_ERR
- Failure: an error code
Error Codes
Error Code |
Description |
|---|---|
LITHO_IMG_STS_NULL_PTR_ERR |
The src or dst parameter has a null pointer. |
LITHO_IMG_STS_SIZE_ERR |
|
LITHO_IMG_STS_SIZE_WRN |
The value of window_rows or window_cols is not an odd number. |
Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | #include <stdio.h> #include <stdlib.h> #include <complex.h> #include <iostream> #include <vector> #include "kp_litho_img.h" void test_kcv_laplacian_acc() { const size_t src_rows = 8; // Adjustable const size_t src_cols = 8; // Adjustable const size_t window_rows = 3; // Adjustable const size_t window_cols = 3; // Adjustable const size_t length = src_rows * src_cols; // Declare and initialize the length. double *src = (double *)malloc(length * sizeof(double)); double *dst = (double *)malloc(length * sizeof(double)); // Initialize the input image (a simple 5x5 image is used as an example). double src_data[5][5] = { {0, 0, 0, 0, 0}, {0, 1, 1, 1, 0}, {0, 1, 0, 1, 0}, {0, 1, 1, 1, 0}, {0, 0, 0, 0, 0} }; for (size_t i = 0; i < src_rows; i++) { for (size_t j = 0; j < src_cols; j++) { src[i * src_cols + j] = src_data[i][j]; } } // Call the function. cv::kcv_LocalMax_acc(src, dst, src_rows, src_cols, window_rows, window_cols); // Print the result (only part of the result is printed here). printf("Upsampled Image:\n"); for (size_t i = 0; i < src_rows; i++) { // Change to src_rows. for (size_t j = 0; j < src_cols; j++) { // Change to src_cols. printf("%.2f ", dst[i * src_cols + j]); if (j == src_cols - 1) { // Change to src_cols. printf("\n"); } } } } int main() { test_kcv_laplacian_acc(); return 0; } |
Output:
1 2 3 4 5 6 7 8 9 | Upsampled Image: 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 |