22

You are dividing an integer by an integer. This is integer division, and will produce an integer again, ignoring the fractional part. You could make it a floating point division by making at least one operand floating point, like replacing 3 with 3.0.


6

That's simple because infile.bmp does not exist, that is just a placeholder it means that, that the path you put in there should contain a file. The folder images has images where you could process or filter. Try doing ./filter -g images/tower.bmp images/greytower.bmp. This basically means ./filter will run your program, -g will state that you want to use ...


3

This is an interesting one! It took me a bit to realize what was happening. As you probably did, I spent a lot of time, looking for an error in the math, in the logic, in something that was in the code. Only after I stepped through the code watching every value change, was I able to find the issue. (Mostly because yesterday was the first day that I did this ...


3

So you have an issue with even width only. In the example of a width of 2, round((width - 1) / 2) would be round((2 - 1) / 2) or round(1 / 2) and since that's integer division (both operands are integer, integer division produces an integer again), round(0) Your <= would work correctly here, your < wouldn't. For odd width, the <= would ...


3

>= 0, not > 0. 0 is a valid index. Also, you might have rounding issues because you are doing integer division.


2

First you have to think that when taking the values from the surroundings pixels, some of them will be already changed so the result will be diferent than with the original ones. Think in how you could solve that. On the other hand, when going around each pixel you have to check for each single one that you're not reaching out of limits of the arrays i.e. ...


2

Um, your code seems pretty hardcoded. It is good to improve the ability to think by trying to implement a new algorithm. I'm really sorry, I couldn't read it because its a lot. :( Anyways here's my code. I think it might help you. What I've basically done is I started from the top row then the relevant row and the row below. For i being the row and j being ...


2

You are not meant to compile helpers.c to its own programme. Just make filter. The Makefile will make sure that helpers.c gets compiled as well, and that it gets linked into filter.


2

This is interesting! ;-) I'll bet that the code works perfectly with any image that has an odd number of rows and produces the original image when there's an even number of rows! The reversal code, the inner for loop, is working perfectly. The problem is that there is an outer for loop. All it is doing is re-executing the mirroring code on every pass. ...


2

This is happening because your loop is summing values from neighbors to the left and up of the current pixel that have already been blurred by previous iterations of the same loop. You need to modify a copy of image[][], not image[][] itself. memcpy can help you copy the data from image[][] into another two dimensional array. Otherwise, your function seems ...


2

just fixed it. so the code was wrote in wrong order and the Ternary Operator was missing a () void sepia(int height, int width, RGBTRIPLE image[height][width]) { for (int i = 0; i < height; i++) { for (int j = 0; j < width; j++) { int sepiaBlue = round(.272 * image[i][j].rgbtRed + .534 * image[i][j].rgbtGreen + .131 *...


1

What's up. Think what happens once you change RGB pixel values... The first one will be totally fine (which is why check50 works for the corner pixel). The next pixels, however, will calculate their average based on the changed pixel values. You might wanna create a temp image and transfer the temp image to the real one in the end.


1

For the change of pixels, you have to write on the image at some point, and right now, you're not doing it. You don't need all those variables and pointers to do the swap of the pixels. You can do something like this: Copy the first pixel on the left into a temp variable. Copy the first pixel on the right into the first on the left. Copy the temp variable ...


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

In the pset we have several files, if you look closely at the specifications, there is a special file called makefile, and what we have to write to the compiler is: make filter


1

Remember, Not Everytime multiplying a point notation will yield a perfect integer, so directly assigning a point notation to the single channel of a pixel won't work. You have to store the value in a float and then round it off and store it in an integer. float new_value = (formula); int new_channel = round(new_value); image[i][j].rgbt = new_channel;


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

Go to the link given at end. It opens check50 website and you can look at actual errors that are happening.


1

As you're experiencing, finding a misspelling in your code, is very dificult. When you are more comfortable with your coding, I suggest you give a try to reduce the lines of code. When I was about to give up, I got lucky and find your misspell: In the code following this line: //Special case: First row middle, something with your indexes is not right. can ...


1

For grayscale you should take a look to operator precedence in C (google). The result 'a + b / c' is not the same than '(a + b) / c' For reflect a question: How many swaps do you need to do to flip the image horizontaly? Think about it. For blur you've found a way to go over the 3x3 pixels around the current pixel with your loops 'k' and 'l', and then ...


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

When checking the values of adj_i and adj_j in your 'if' conditions, you are not checking against your adjacent_positions arrays, since you added the values of i an j to them here: int adj_i = i + adjacent_positions[k][0] and here: int adj_j = j + adjacent_positions[k][1]. Fixing those, by substracting 'i' and 'j' in the conditions, for example: if (adj_j -j ...


1

You're doing integer division it disregards the remainder, simple fix would be to just divide by 9.0 as it will become a float division, integer division is like 11 / 2 = 5.5, oh the data type is int so let's just throw away the .5 so 11 / 2 = 5. so when it reaches your round function it does nothing since it's already a whole number.


1

I realised that in line 4 i am assigning values to float only once. So when I loop it in the following lines, avg_of_9_blue, avg_of_9_red and avg_of_9_green just keep increasing past 255. Corrected this an place the assignment of float values into the if statement. Afterwards, realised that i am changing all the original RBGT values when assigning new ...


1

You solved grayscale. Maybe you should check how you did the rounding there, and if you can apply that to blur. Edit: Totally missed that you do typecasts in most of the averages. But there are some where you don't.


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

I missed a += on the rgbtGreen :S


1

Conditional loops is really the way to go on this one. If the pixel is along the left edge and time there is an image[j - 1] it would cause an index error. Think of all conditions that would cause an index error, when image[i +/- 1][j +/- 1] is along the edges. So a corner pixel would have to be divided by 4 no 9. And edges would be 6 respectively. Again ...


1

I was facing this exact problem for a while. It's something you can solve by taking a step back and thinking in what you're doing. You take a pixel and you transform it using the information of the pixels around it. Next you take a pixel next to it ....... If the answer doesn´t come up message me and I´ll try to help you a little more.


1

At the end fo your check50 messages, there should be a line that says To see the results in your browser go to https://submit.cs50.io/check50/... If you click on the link, you will notice your code doesn't give the correct output for some pixels (I tried running your code). Fix your code and you should be good.


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