dilevin / computer-graphics-raster-images

Computer Graphics Assignment about Raster Images
1 stars 7 forks source link

Getting strange spots on shifted/desaturated images #46

Closed NPTP closed 4 years ago

NPTP commented 4 years ago

Overall my shifted.ppm and desaturated.ppm images look good (most of the pixel colours match the (corrected) references) but for some reason, I'm getting spotty artifacts. They are especially noticeable around the dog's nose in each image.

Here is the example from my desaturated.ppm. You can see lots of gray spotting. desatch

I'm following the conversions to the letter, or so I think. Currently going over everything and trying modifications to all relevant functions. Any ideas why this might be happening?

Thank you!

songfeil commented 4 years ago

Not sure what exactly the bug is, but if it happens in both images then I suspect the hsv/rgb conversion is buggy. I checked the gray spots and it seems that the H and S value are all set to zero. For example pixel (78, 261) have rgb (41, 41, 41) and hsv (0, 0, 16) where h and s should not be zero.

koichishi commented 4 years ago

I guess the value of H may be out of range ( 0 - 360 ) in either rgb2hsv or hsv2rgb.

NPTP commented 4 years ago

I guess the value of H may be out of range ( 0 - 360 ) in either rgb2hsv or hsv2rgb.

I am accounting for the periodicity of H by adding 360 when h < 0 or doing h = h mod 360 (using fmod) when h >= 360*, in rgb2hsv. (In hsv2rgb, H cannot be modified.) So I don't think it's that. Looking into how H and S get set to zero.

*using >= on 360 because the header file specifies the right-open interval [0, 360) for h.

NPTP commented 4 years ago

Something with the way I was using max & mins in rgb->hsv was broken. Fixed now. But this discussion helped me look in the right places and trace the problem accurately so I knew what to fix. songfeil you have been incredibly helpful for this assignment and I have to thank you big time!