Currently struggling to vectorize a function as shown below. It's a function used in image processing and I cannot for the life of me figure out how to vectorize it. I assume I have to optimize the for loop where the Gx and Gy variables are being updated on the //Calculate the sum of the Sobel mask times the nine surrounding pixels in the x and y section.
I was recommended to use __SMLAD() from the arm intrinsics as linked here: https://developer.arm.com/docs/dui0472/j/armv6-simd-instruction-intrinsics/__smlad-intrinsic However, I just can't figure out how to use it..any help on how to use __SMLAD() would be much appreciated, as it seems there just aren't any examples of it being used on the internet anywhere.
Here's the function:
void Sobel(){
int row, col, rowOffset, colOffset,Gx,Gy;
float thisAngle;
uint8_t newAngle;
/*---------------------- Sobel ---------------------------------*/
for (row = 1; row < N-1; row++) {
for (col = 1; col < M-1; col++) {
Gx = 0;
Gy = 0;
//Calculate the sum of the Sobel mask times the nine surrounding pixels in the x and y direction
for (rowOffset=-1; rowOffset<=1; rowOffset++) {
for (colOffset=-1; colOffset<=1; colOffset++) {
Gx += out_img[row+rowOffset][col+colOffset] * GxMask[rowOffset + 1][colOffset + 1];
Gy += out_img[row+rowOffset][col+colOffset] * GyMask[rowOffset + 1][colOffset + 1];
}
}
gradient[row][col] = abs(Gx) + abs(Gy); // Calculate gradient strength
thisAngle = (atan2((float) Gx, (float) Gy)/3.14159f) * 180.0f; // Calculate actual direction of edge [-180, +180]
// Convert actual edge direction to approximate value
if ( ( (thisAngle >= -22.5f) && (thisAngle <= 22.5f) ) || (thisAngle >= 157.5f) || (thisAngle <= -157.5f) )
newAngle = 0;
if ( ( (thisAngle > 22.5f) && (thisAngle < 67.5f) ) || ( (thisAngle > -157.5f) && (thisAngle < -112.5f) ) )
newAngle = 45;
if ( ( (thisAngle >= 67.5f) && (thisAngle <= 112.5f) ) || ( (thisAngle >= -112.5f) && (thisAngle <= -67.5f) ) )
newAngle = 90;
if ( ( (thisAngle > 112.5f) && (thisAngle < 157.5f) ) || ( (thisAngle > -67.5f) && (thisAngle < -22.5f) ) )
newAngle = 135;
edge_Dir[row][col] = newAngle;
}
}
}