Skip to content
Advertisement

Why is this image method returning a black image?

I am running the code below. What it is supposed to do is equalize an image passed into it. All the methods and variables run fine except for newPixelVal which is always zero. This then makes my image all black. I cannot figure out why this is returning 0.

JavaScript

Advertisement

Answer

Got it! The division carried out at newPixelVal is between two int types. It will go to zero since the number of pixels less than is always less than total pixels. The decimal answer is truncated to 0. As soon as I replaced that with the line:

JavaScript

The calculation worked perfectly!

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement