2022-12-19 10:38:30 +00:00
|
|
|
#include <cstring>
|
2022-12-18 23:00:31 +00:00
|
|
|
#include <math.h>
|
|
|
|
#include "sobel.h"
|
|
|
|
|
2022-12-19 11:01:15 +00:00
|
|
|
#define WIDTH 512
|
|
|
|
#define HEIGHT 512
|
|
|
|
|
|
|
|
void sobel(uint8_t *__restrict__ out, uint8_t *__restrict__ in)
|
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
|
|
|
|
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
|
|
|
|
2022-12-19 10:38:30 +00:00
|
|
|
// Carica le prime tre righe nel buffer
|
2022-12-19 11:16:55 +00:00
|
|
|
uint8_t inBuffer[3*WIDTH];
|
|
|
|
memcpy(inBuffer, in, 3*WIDTH*sizeof(uint8_t));
|
2022-12-19 10:38:30 +00:00
|
|
|
|
2022-12-19 09:32:00 +00:00
|
|
|
esternoY:
|
2022-12-19 11:01:15 +00:00
|
|
|
for (int y = 0; y < HEIGHT - 2; y++)
|
2022-12-18 23:00:31 +00:00
|
|
|
{
|
2022-12-19 09:43:10 +00:00
|
|
|
|
2022-12-19 09:32:00 +00:00
|
|
|
esternoX:
|
2022-12-19 11:01:15 +00:00
|
|
|
for (int x = 0; x < WIDTH - 2; x++)
|
2022-12-18 23:00:31 +00:00
|
|
|
{
|
2022-12-19 11:01:15 +00:00
|
|
|
#pragma HLS PIPELINE
|
|
|
|
|
2022-12-19 08:30:44 +00:00
|
|
|
int dx = 0;
|
|
|
|
int dy = 0;
|
|
|
|
|
2022-12-19 09:32:00 +00:00
|
|
|
internoY:
|
2022-12-18 23:00:31 +00:00
|
|
|
for (int k = 0; k < 3; k++)
|
|
|
|
{
|
2022-12-19 09:43:10 +00:00
|
|
|
#pragma HLS UNROLL
|
|
|
|
|
2022-12-19 11:16:55 +00:00
|
|
|
const int inYOffset = (y + k) * WIDTH;
|
2022-12-19 09:32:00 +00:00
|
|
|
|
|
|
|
internoX:
|
2022-12-18 23:00:31 +00:00
|
|
|
for (int z = 0; z < 3; z++)
|
|
|
|
{
|
2022-12-19 09:43:10 +00:00
|
|
|
#pragma HLS UNROLL
|
|
|
|
|
2022-12-19 11:16:55 +00:00
|
|
|
const int inXOffset = (x + z) % 3;
|
2022-12-19 09:32:00 +00:00
|
|
|
|
|
|
|
const int inOffset = inYOffset + inXOffset;
|
2022-12-19 10:38:30 +00:00
|
|
|
const int inElement = inBuffer[inOffset];
|
2022-12-19 09:17:14 +00:00
|
|
|
|
2022-12-19 09:32:00 +00:00
|
|
|
dx += sobelFilter[k][z] * inElement;
|
|
|
|
dy += sobelFilter[z][k] * inElement;
|
2022-12-18 23:00:31 +00:00
|
|
|
}
|
|
|
|
}
|
2022-12-19 08:30:44 +00:00
|
|
|
|
2022-12-19 11:01:15 +00:00
|
|
|
const int outYOffset = (y + 1) * WIDTH;
|
2022-12-19 09:32:00 +00:00
|
|
|
const int outXOffset = (x + 1);
|
|
|
|
const int outOffset = outYOffset + outXOffset;
|
2022-12-19 09:43:10 +00:00
|
|
|
|
2022-12-19 09:32:00 +00:00
|
|
|
out[outOffset] = sqrt((float)((dx * dx) + (dy * dy)));
|
2022-12-18 23:00:31 +00:00
|
|
|
}
|
2022-12-19 10:38:30 +00:00
|
|
|
|
2022-12-19 11:16:55 +00:00
|
|
|
memcpy(inBuffer, in + y * WIDTH, WIDTH*sizeof(uint8_t));
|
2022-12-18 23:00:31 +00:00
|
|
|
}
|
|
|
|
}
|