Hot answers tagged

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.
user avatar
  • 20.7k
6 votes
Accepted

pset4 filter won't open file

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 ...
user avatar
  • 701
6 votes
Accepted

pset4 filter: blur seems to be working, but check50 reads errors

You overwrite pixels you still need later, for calculating the neighbouring pixels. What looks about right visually is still wrong. I made another array, wrote my blurred image to that, then later ...
user avatar
  • 20.7k
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 ...
user avatar
  • 20.7k
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 ...
user avatar
  • 20.7k
4 votes
Accepted

PSET4 filter (more) - edge

You are using 'RGBTRIPLE' structs along your code which is kind of neat but it comes with some issues: That struct only can store values from 0 to 255 with no decimal point. That means that when ...
user avatar
  • 1,541
4 votes
Accepted

pset4 filter blur problem

You're adding one pixel twice, and missing one pixel. The code, as you've written it, is really prone to tiny bugs like that, and they're hard to find. Once you've got it working, consider how you can ...
user avatar
  • 699
3 votes

Help with blur filter for pset4! Output image is significantly darker than input

Got the solution. Using the BYTE type to store the color values resulted in overflow. Solving by using int or double for redAvg, greenAvg, and blueAvg.
user avatar
3 votes
Accepted

pset4 filter: reflect produces "UndefinedBehaviorSanitizer:DEADLYSIGNAL" forever

for (int i = 0; i < width; i++) Shouldn't it be height?
user avatar
  • 20.7k
3 votes
Accepted

helpers.c not compiling for filter

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.
user avatar
  • 20.7k
3 votes
Accepted

What's my error?

Your problem lies with the / operator. Because the RGB values and the denominator are all integers, integer division is being performed and the fractional remainder is dropped instead of being passed ...
user avatar
  • 930
2 votes
Accepted

PSET4 Filter, edge detection process only works for square-like pictures. How to make it work for the whole picture?

if (j < height - 1) Something's wrong with that line.
user avatar
  • 20.7k
2 votes
Accepted

cs50 pset4 filter sepia

instead of using BYTE before sepiaRed, sepiaBlue, sepiaGreen, originalRed, originalBlue and originalGreen, use float Also, don't forget to round the values of sepia Red, Blue and Green using the ...
user avatar
  • 51
2 votes
Accepted

Filter (Less Comfortable) Seems to Work Perfectly, but only passes 7 of 22 checks

When doing operationns that could result in decimal point values it's not a good idea to work with 'int' values because the result's decimal point will be truncated. It's better to do the math with a ...
user avatar
  • 1,541
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 ...
user avatar
  • 1,541
2 votes
Accepted

pset4 - filter program,can't figure out what exactly is the problem with blur!

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 ...
user avatar
  • 165
2 votes
Accepted

cs50 Pset 4 filter:Greyscale. Cade is not averaging correctly?

Did you happen to notice that the incorrect results all happen to be 1 less than the correct answers? That's a big clue. The problem lies here. float average = total / 3; Since total is an int and &...
user avatar
  • 63.2k
2 votes

My blur function blurs every image, but fails every check50 check - please help!

Please note I haven't validated this with testing and have only glanced at your code, but one thing that stands out to me: round((float) (sum_blue / pixel_type)) Remember operator precedence here: ...
user avatar
  • 930
1 vote
Accepted

PSET4 FILTER(LESS) BLUR HELP!

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 ...
user avatar
  • 1,541
1 vote

Edge detection produces weird outputs

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) ...
user avatar
  • 1,541
1 vote
Accepted

PSET4 - Filter edge too yellow

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 + ...
user avatar
  • 1,541
1 vote
Accepted

Blur works visually, but check50 reads errors for every section

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 ...
user avatar
  • 701
1 vote
Accepted

Problem Set 4 - Filter (Blur)

for (int i = 0; i < height; i++) { for (int j = 1; j < width; j++) { Your j variable here shouldn't start at 1.
user avatar
  • 302
1 vote
Accepted

Miscalculating the Corner and Edge pixels in blur

There are some parentheses missing. You have like value1 + value2 + value3 / 3 instead of (value1 + value2 + value3) / 3. Edit: Also, check your condition for the last row.
user avatar
  • 20.7k
1 vote

PSET 4 filter less comfortable (blur filter) help

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 ...
user avatar
  • 23
1 vote

PSET 4 filter, check50 shows no errors but on submission it scores only 50%

You are so almost there!! I don't know why you get those results with check50 I checked it and it tells me that there are problems with reflect and blur. For reflect there is a problem with the rigth ...
user avatar
  • 1,541
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 ...
user avatar
  • 1,541
1 vote
Accepted

CS50 pset4, I have problems with getting the blur filter to work

When you divided here: image[i][j].rgbtRed = (sumRed / pixCount); you'll problably get a decimal point result. The problem is that working with int variables will result in a truncated result, the ...
user avatar
  • 1,541
1 vote

pset4 - Filter - blur error

Your code assumes that every pixel can be made the centre pixel in a 3x3 block of pixels. This is not true for corner pixels as well as pixels at the vertical and horizontal borders of the image. ...
user avatar
1 vote

pset4 - Filter - blur error

I was very intriged because looking through your code I couldn't find anything wrong. So I compared with my blur version and they were very similar except for one thing. For my average calculations I ...
user avatar
  • 1,541

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