7
votes
Accepted
pset4 filter: reflect the image reflect half only
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
votes
Accepted
runtime error in filter: reflect
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 ...
4
votes
Accepted
pset4: filter reflect all check right except two of them
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 ...
3
votes
Accepted
pset4 filter: reflect produces "UndefinedBehaviorSanitizer:DEADLYSIGNAL" forever
for (int i = 0; i < width; i++)
Shouldn't it be height?
2
votes
Accepted
pset4 filter reflect. runtime error: index 601 out of bounds for type 'RGBTRIPLE [width]'
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 ...
2
votes
Accepted
PSET 4 Reflect help
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 ...
2
votes
Accepted
Logic for reflect function in pset4 filter
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 ...
2
votes
Accepted
Pset4 Reflect Filter Challenges - Not Reflecting
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 ...
1
vote
Pset4 (Filter-Less) Reflection: Not getting correct values on Check50
Let's look carefully at this code:
for (int j = 0; j < (width / 2); j++)
{
swap(&image[i][j], &image[i][width - j]);
}
Now, let's walk through what happens on the first ...
1
vote
Accepted
pset4 reflect half of the image
Look very carefully at what's happening:
RGBTRIPLE temp = *pixel1;
*pixel2 = *pixel1;
*pixel1 = temp;
The code saves pixel1 in temp, then copies it to pixel2, then copies temp back to pixel1. In ...
1
vote
Accepted
PSET filter reflect
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 ...
1
vote
Accepted
Pset4 reflect works but doesn't pass check50
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 ...
1
vote
Accepted
CS50 PSET 4 REFLECT FAILS CS50
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 ...
1
vote
Logic for reflect function in pset4 filter
when you are writing this 'int y = image[i][width - k].rgbtBlue;' think exactly what pixel is this thing swapping?..
1
vote
Accepted
PSET 4 BLUR and 2 of REFLECT
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
vote
Accepted
pset 4 reflect & blur work but don't test
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 ...
1
vote
Accepted
pset4 Filter Reflect could anyone check my code, I can't find the error as to why it does not output desirably
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 ...
1
vote
Accepted
Code divides image
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 ...
1
vote
Accepted
CS50 - Filter - Reflect Image
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 ...
1
vote
Accepted
valgrind on filter -r. No leaks but errors
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 ...
1
vote
pset4 filter: reflect produces "UndefinedBehaviorSanitizer:DEADLYSIGNAL" forever
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
reflect × 30pset4 × 24
filter × 15
cs50x × 7
pset4filter × 5
c × 2
blur × 2
runtimeerror × 2
pset4reflection × 2
segmentation-fault × 1
valgrind × 1
fails-check50-but-works × 1
compilation-error × 1
resize-less × 1
bubble-sort × 1
cs50x2020 × 1
filter-less × 1