Tag Info

6

If you swap the first pixel with the last, and then the last with the first, you are reflecting twice. Make your horizontal loop run width / 2 times instead of width.

5

For j being 0, your index would be width. But valid index is from 0 to width-1. Subtract one and it should be right. After fixing this, I see another issue: You first swap the left half with the right, and then the right with the left, returning the image to its old state. Stop at the right point. BTW, you can assign whole RGBTRIPLE type variables, like ...

4

Remove the -1 from HW. If the number of pixels per row is even, you need to swap half as many times. If the number of pixels per row is odd, no need to swap the middle one with itself, so swap that number divided by two, and rounded down. Integer division does exactly that, truncates the result. No -1 involved.

3

for (int i = 0; i < width; i++) Shouldn't it be height?

2

Reading your code I can see that you're worried about the number of width pixels been even or not. Should you be worried? If you look at your code you can see that you're answering yourself. When reached the middle point you do this: image[i][j] = image[i][j]; which is like do nothing. You have to flip the half part of the pixels in the left with the ones in ...

1

At first glance at the check50 results, it seems like the last line of the image isn't being processed. But that's not the case. In reality, the left half is being updated to look like the right, but the right half isn't. It's a complicated little problem, and I'll leave it to you to troubleshoot, but here are some hints. The short version is that the else ...

1

Notice what your for loops are doing. i = 0 will not switch with i = height-1 here. What you are doing is replacing i = height - 1 with i = 0. In this process you are overwriting the last pixel (in this example) and losing it forever. Recall that example from David sir's lecture where he called a student on stage to swap liquid in 2 glasses without mixing ...

1

First, why does k start at 1 and not 0? By starting at 1, the code completely ignores the first pixel on each row. Ignoring the missing bracket, let's say that k=0. Is image[i][width - k] valid? More specifically, is image[i][width] valid? Why or why not? If this answers your question, please click on the check mark to accept. Let's keep up on forum ...

1

Ah, it's always those simple cut and paste errors that get us. ;-) If you look at the extended results in the link posted with your check50 results, you can see the full raw data of the errors. It's always the last pixel on a line and always the red value, so let's look at that code: temp_3 = image[i][j].rgbtRed; image[i][j].rgbtRed = ...

1

There are two issues. First is the one that @Himanshi brought up - It's doing a great job of swapping x/y, g/h and i/j. But at what point is anything actually being changed in the image array? Did you notice that the output file contains the original image? Second, have you looked carefully at the maximum indexes that you're using for the array? Is [width -...

1

when you are writing this 'int y = image[i][width - k].rgbtBlue;' think exactly what pixel is this thing swapping?..

1

For reflect, you have to re-think this expresion: [width - (j + 1)]. For Blur, you need to reset your variables before every i/j iteration.

1

So my swap function was switching the values of my variables but the variables themselves did not get switched so I had to write out the code to swap the variables (from what i'm told the swap function is basically useless I guess) then make sure to initialize my s after because I originally added the variable swaps after the s and s was being incremented ...

1

For reflect a question: How many swaps do you need to do to flip the image horizontaly? Think about it. For blur you got it rigth, except for a little mispell in your 'if' line. Edited because I didn't realize that you could copy an entire struct by simply: RGBTRIPLE row = {}; row = image[i][j];

1

You only need two loops to go through all the pixels of the image. One for every row, and one for the horizontal switching. So think about this: How many switchings do you need to do for every row to flip an image horizontaly?

1

Let's see the very first switch being the first pixel on the left and the last pixel on the right. In your code: image [i][j] = image [i][(width -1) - j]; you copied the last pixel in the first position. Now you have the same pixel in the first and last position and no access to the one that was first. So How can you switch the two pixels without losing any ...

1

You are right, it is misaligned by one. Which index does the last pixel in the row have? And which index do you use for j of 0? Off-by-one. BTW, width / 2 would work as well (with 2.0, you would have an extra swap of the middle pixel with itself).

1

Off by one. If j is 0, you access image[i][width] (a valid index would be from 0 to width-1), which due to memory layout would refer to image[i+1][0]. For the last line, that's behind the allocated memory. Fix this by using width - 1 - j instead of width - j.

1

I had the exact same problem with filter in pset4 when applying the greyscale filter and this thread solved it for me. They set up the function definition they entered the size argument as: void grayscale(int height, int width, RGBTRIPLE image[height][width]) not void grayscale(int height, int width, RGBTRIPLE image[width][height]) so to iterate through ...

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