2022-12-18 23:00:31 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include "sobel.h"
|
|
|
|
|
2022-12-19 08:35:20 +00:00
|
|
|
void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in, const int width, const int height)
|
2022-12-18 23:00:31 +00:00
|
|
|
{
|
2022-12-19 09:05:16 +00:00
|
|
|
#pragma HLS INTERFACE m_axi port=out offset=slave bundle=bout
|
|
|
|
#pragma HLS INTERFACE m_axi port=in offset=slave bundle=bin
|
2022-12-19 08:55:46 +00:00
|
|
|
#pragma HLS INTERFACE s_axilite port=width bundle=bwidth
|
|
|
|
#pragma HLS INTERFACE s_axilite port=height bundle=bheight
|
|
|
|
|
2022-12-19 08:35:20 +00:00
|
|
|
const int sobelFilter[3][3] = {
|
2022-12-19 08:30:44 +00:00
|
|
|
{-1, 0, 1},
|
|
|
|
{-2, 0, 2},
|
|
|
|
{-1, 0, 1}
|
|
|
|
};
|
2022-12-18 23:00:31 +00:00
|
|
|
|
|
|
|
for (int y = 1; y < height - 1; y++)
|
|
|
|
{
|
|
|
|
for (int x = 1; x < width - 1; x++)
|
|
|
|
{
|
2022-12-19 08:30:44 +00:00
|
|
|
int dx = 0;
|
|
|
|
int dy = 0;
|
|
|
|
|
2022-12-18 23:00:31 +00:00
|
|
|
for (int k = 0; k < 3; k++)
|
|
|
|
{
|
|
|
|
for (int z = 0; z < 3; z++)
|
|
|
|
{
|
2022-12-19 09:17:14 +00:00
|
|
|
const int address = (y + k - 1) * width + x + z - 1;
|
|
|
|
|
|
|
|
dx += sobelFilter[k][z] * in[address];
|
|
|
|
dy += sobelFilter[z][k] * in[address];
|
2022-12-18 23:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-19 08:30:44 +00:00
|
|
|
|
2022-12-18 23:00:31 +00:00
|
|
|
out[y * width + x] = sqrt((float)((dx * dx) + (dy * dy)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|