Question: performance lab, optimize emboss image I am working on the performance lab for class where we have to get two functions to run faster/better, or
performance lab, optimize emboss image
I am working on the performance lab for class where we have to get two functions to run faster/better, or optimise them. We are to flip/rotate an image and also apply a filter to an image. I am struggling with applying the filter, I am to emboss the image. Below is the code of the convolve Naive baseline implementation
/* A struct used to compute a pixel value */ typedef struct { float red; float green; float blue; float weight; } pixel_sum;
/****************************************************** * Your different versions of the convolve kernel go here ******************************************************/
/* * naive_convolve - The naive baseline version of convolve */ char naive_convolve_descr[] = "naive_convolve: Naive baseline implementation"; void naive_convolve(int dim, pixel *src, pixel *dst) { int i, j, ii, jj, curI, curJ; pixel_sum ps; for (j = 0; j < dim; j++){ for (i = 0; i < dim; i++){ ps.red = 0.0; ps.green = 0.0; ps.blue = 0.0; ps.weight = 0.0; for (jj = -2; jj <= 2; jj++){ for (ii = -2; ii <= 2; ii++){ curJ = j+jj; if(curJ<0 || curj>=dim){ continue; } curI = i+ii; if(curI<0 || curi>=dim){ continue; } ps.red += src[RIDX(curI, curJ, dim)].red * kernel[ii+2][jj+2]; ps.green += src[RIDX(curI, curJ, dim)].green * kernel[ii+2][jj+2]; ps.blue += src[RIDX(curI, curJ, dim)].blue * kernel[ii+2][jj+2]; ps.weight += kernel[ii+2][jj+2]; } } dst[RIDX(i,j,dim)].red = (unsigned short)(ps.red/ps.weight); dst[RIDX(i,j,dim)].green = (unsigned short)(ps.green/ps.weight); dst[RIDX(i,j,dim)].blue = (unsigned short)(ps.blue/ps.weight); } } }
My convolve kernel is
{{0.000000, -1.000000, -1.000000, -1.000000, -1.000000}, {1.000000, 0.000000, -4.000000, -16.000000, -1.000000}, {1.000000, 4.000000, 1.000000, -4.000000, -1.000000}, {1.000000, 16.000000, 4.000000, 0.000000, -1.000000}, {1.000000, 1.000000, 1.000000, 1.000000, 0.000000}
From my TA, he gaave us a hint that the kernel does not need to be a float, what it is currently in, but can be an int to work slightly better.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
