Hot answers tagged

2

if (j < height - 1) Something's wrong with that line.


1

Your k-- and p-- don't match the c++ and r++. For example, you have int r = 0, c = 0; for (int k = i; k >= i - 1; k--) which starts at the upper left in your matrix (r=0), but in the middle row for the 3x3 window. I would assume that you could set your r to k - i + 1 and c to p - j + 1, this should remove that problem.


1

Your algorithm looks fine, just a couple typos. RGBTRIPLE edged_pixel(int i, int j, int height, int width, RGBTRIPLE image[width][height]) should specify height before width, like the other instances. int g[3][3] = {{-1, 0, 1}, {-2, 0, 2}, {-1, 0, -1}} should use have a positive 1 in the last triple.


1

It might be an issue to do with having height and width the wrong way round. I think this could be causing the issue with the right hand third of the image. i think iteration starts in top left with [0][0] for i and j. The largest values of i and j would therefore be associated with the bottom and right hand side of the image. You therefore need to check ...


1

//Detect upper right corner if(!(i+1 > width-1 || j+1 > height-11)) maybe because of this it is happening.. typo in if statement


1

int gx[3][3] = {{-1, 0, -1}, {-2, 0, 2}, {-1, 0, 1}}; The third number in this (-1) should be 1. Which makes sense with the first row and last column being right, since that value wouldn't be used when calculating those pixels.


1

There is a little misspell in your gx array in the 'gXY_grid' function. There would be some improvements to optimize your code, but by fixing the array, your program will do the job.


1

May be some more issues but, a big one, is that you are not processing the edge and border pixels at all: Here: if (x - 1 < 0 || x + 1 > width - 1 || y - 1 < 0 || y + 1 > height - 1) { continue; } you jump to the next pixel without taking in consideration the ones that are not out of ...


1

So, now it is a lot shorter (thanks to the inspiration by Ayam Chan) and works fine. Am I allowed to publish the complete code? Or is that not appreciated? Greetz


1

First of all, you should consider revise your code in order to group some of those for loops and reduce the number of lines. It will be more readable for you and for others. You have two separate group of loops for getting the values in gxsum.... and gysum... when it would be easier to get them in one group. In fact the conditions of the 3x3 matrix around ...


1

I've found 3 problems in your code: 1. You're making a copy of the image but you're not using it? 2. Revise the arrays Gx-Gy something is wrong. 3. Pay attention where you declare the group of long variables rx-ry-gx-gy-etc.


1

Found. RGBTRIPBLE doesn't support Float.


1

I found the solution, it turns out I was supposed to create a copy of the original image to work on.


Only top voted, non community-wiki answers of a minimum length are eligible