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.
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 ...
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 ...
So you have an issue with even width only. In the example of a width of 2,
round((width - 1) / 2)
round((2 - 1) / 2)
round(1 / 2)
and since that's integer division (both operands are integer, integer division produces an integer again),
Your <= would work correctly here, your < wouldn't. For odd width, the <= would ...
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. ...
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 ...
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. ...
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 ...
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 *...
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 ...
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;
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 ...
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 ...
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)
you jump to the next pixel without taking in consideration the ones that are not out of ...
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] and here: int adj_j = j + adjacent_positions[k]. Fixing those, by substracting 'i' and 'j' in the conditions, for example: if (adj_j -j ...
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.
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 ...
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.
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?
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 ...
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.
At the end fo your check50 messages, there should be a line that says
To see the results in your browser go to
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.