1
edit
Changes
→Assignment 3
This removed the edge checks from the convolution kernel allowing for a dramatic increase in Gaussian.
<pre>
//old
for (int i = -kXRad; i <= kXRad; i++){
for (int j = -kYRad; j <= kYRad; j++){
//wrap image
outPixel.Red += kernelElement * imageElement.Red;
outPixel.Green += kernelElement * imageElement.Green;
outPixel.Blue += kernelElement * imageElement.Blue;
}
}
</pre>
<pre>
//new
for (int i = -kXRad; i <= kXRad; i++) { for (int j = -kYRad; j <= kYRad; j++) { const float kernelElement = convolutionKernel[kernelIndex(i, j, kernelXSize, kernelYSize)]; const GPU_RGBApixel imageElement = img[imageIndex(xCorr + i, yCorr + j, height + kernelYSize - 1)]; outPixel.Red += kernelElement * imageElement.Red; outPixel.Green += kernelElement * imageElement.Green; outPixel.Blue += kernelElement * imageElement.Blue; }
const float kernelElement = convolutionKernel[kernelIndex(i, j, kernelXSize, kernelYSize)];
const GPU_RGBApixel imageElement = img[imageIndex(xCorr + i, yCorr + j, height + kernelYSize - 1)];
outPixel.Red += kernelElement * imageElement.Red;
outPixel.Green += kernelElement * imageElement.Green;
outPixel.Blue += kernelElement * imageElement.Blue;
}
}
</pre>
<b><font style="font-size:140%"> Canny </font></b>
notMaxSuppression used to have a large if block in the middle of the kernel that could potentially split into 4 threads. It was rewritten using a pre-computed table of outcomes and a little “mathemagic” to eliminate the if statements. It has reduced it reduces it from four paths to two.
<pre>
//changed the angle finding logic
//old
int index = imageIndex(x, y, height);
const float& gM = gradMagnitude[index];
result[index] = gM;
//don't touch the edges
if (x < 1 || y < 1 || x >= width - 1 || y >= height - 1) { return;
}
const float& gA = gradAngle[index];
int i;
int j;
result[index] = gradMagnitude[index];
if (((gA >= -M_PId8) && (gA <= M_PId8)) || (gA >= 7 * M_PId8) || (gA <= -7 * M_PId8)) { i = 0; j = -1; } else if (((gA <= 3 * M_PId8) && (gA > M_PId8)) || ((gA <= -5 * M_PId8) && (gA > -7 * M_PId8))){ i = -1; j = 1;}else if (((gA >= 5 * M_PId8) && (gA < 7 * M_PId8)) || ((gA < -M_PId8) && (gA >= -3 * M_PId8))){ i = -1;i j = -1;}else{j i = -1; j = 0;
}
}
//new
int xCorr = x + 1;
int yCorr = y + 1;
int heightCorr = height + 2;
int index = imageIndex(xCorr, yCorr, heightCorr);
const float gM = gradMagnitude[index];
const int sectorConvertX[9] = { 0, -1, -1, -1, -1, -1, -1, 0 , 0 };
const int sectorConvertY[9] = { -1, 1, 1, -1, -1, 0, 0, -1 , -1 };
const float gA = fabsf(gradAngle[imageIndex(x, y, height)]);
const int sector = int(gA / M_PI) * 8;
int i = sectorConvertX[sector];
int j = sectorConvertY[sector];
if (!((gM <= gradMagnitude[imageIndex(xCorr + i, yCorr + j, heightCorr)]) || (gM <= gradMagnitude[imageIndex(xCorr - 1, yCorr - j, heightCorr)]))){ result[index] = gM;}else{ result[index] = gM0.0;
}
</pre>
//old
if (pixel >= lowerThreshold && pixel < upperThreshold) { int iLower = (x == 0) ? 0 : -1; int iUpper = (x == width - 1) ? 0 : 1; int jLower = (height == 0) ? 0 : -1; int jUpper = (x == width - 1) ? 0 : 1;
for (int i = iLower; i <= iUpper; i++){
for (int j = jLower; j <= jUpper; j++){
if (image[imageIndex(x + i, y + j, height)]){
ret = upperThreshold + 1;
}
}
}
}
//new
if (level >= lowerThreshold && level < upperThreshold){
<b><font style="font-size:140%"> Grey world </font></b>