38 lines
No EOL
2.2 KiB
C++
38 lines
No EOL
2.2 KiB
C++
#include <algorithm>
|
|
#include "filters.h"
|
|
#include <utils-lib/utils.h>
|
|
|
|
uint8_t medianFilter(std::array<int, 9> &pixels) {
|
|
std::sort(pixels.begin(), pixels.end());
|
|
return ui8_clamp(pixels[5]);
|
|
}
|
|
|
|
uint8_t averageFilter(std::array<int, 9> &pixels) {
|
|
return ui8_clamp((pixels[0] * AVERAGE_MASK[0] + pixels[1] * AVERAGE_MASK[1] + pixels[2] * AVERAGE_MASK[2] +
|
|
pixels[3] * AVERAGE_MASK[3] + pixels[4] * AVERAGE_MASK[4] + pixels[5] * AVERAGE_MASK[5] +
|
|
pixels[6] * AVERAGE_MASK[6] + pixels[7] * AVERAGE_MASK[7] + pixels[8] * AVERAGE_MASK[8]) / 9);
|
|
}
|
|
|
|
uint8_t prewittDXFilter(std::array<int, 9> &pixels) {
|
|
return ui8_clamp(pixels[0] * PREWITT_MASK_DX[0] + pixels[1] * PREWITT_MASK_DX[1] + pixels[2] * PREWITT_MASK_DX[2] +
|
|
pixels[3] * PREWITT_MASK_DX[3] + pixels[4] * PREWITT_MASK_DX[4] + pixels[5] * PREWITT_MASK_DX[5] +
|
|
pixels[6] * PREWITT_MASK_DX[6] + pixels[7] * PREWITT_MASK_DX[7] + pixels[8] * PREWITT_MASK_DX[8]);
|
|
}
|
|
|
|
uint8_t prewittDYFilter(std::array<int, 9> &pixels) {
|
|
return ui8_clamp(pixels[0] * PREWITT_MASK_DY[0] + pixels[1] * PREWITT_MASK_DY[1] + pixels[2] * PREWITT_MASK_DY[2] +
|
|
pixels[3] * PREWITT_MASK_DY[3] + pixels[4] * PREWITT_MASK_DY[4] + pixels[5] * PREWITT_MASK_DY[5] +
|
|
pixels[6] * PREWITT_MASK_DY[6] + pixels[7] * PREWITT_MASK_DY[7] + pixels[8] * PREWITT_MASK_DY[8]);
|
|
}
|
|
|
|
uint8_t sobelDXFilter(std::array<int, 9> &pixels) {
|
|
return ui8_clamp(pixels[0] * SOBEL_MASK_DX[0] + pixels[1] * SOBEL_MASK_DX[1] + pixels[2] * SOBEL_MASK_DX[2] +
|
|
pixels[3] * SOBEL_MASK_DX[3] + pixels[4] * SOBEL_MASK_DX[4] + pixels[5] * SOBEL_MASK_DX[5] +
|
|
pixels[6] * SOBEL_MASK_DX[6] + pixels[7] * SOBEL_MASK_DX[7] + pixels[8] * SOBEL_MASK_DX[8]);
|
|
}
|
|
|
|
uint8_t sobelDYFilter(std::array<int, 9> &pixels) {
|
|
return ui8_clamp(pixels[0] * SOBEL_MASK_DY[0] + pixels[1] * SOBEL_MASK_DY[1] + pixels[2] * SOBEL_MASK_DY[2] +
|
|
pixels[3] * SOBEL_MASK_DY[3] + pixels[4] * SOBEL_MASK_DY[4] + pixels[5] * SOBEL_MASK_DY[5] +
|
|
pixels[6] * SOBEL_MASK_DY[6] + pixels[7] * SOBEL_MASK_DY[7] + pixels[8] * SOBEL_MASK_DY[8]);
|
|
} |