I'm trying to do some labs we were given to complete in Matlab for a video analysis module in python since I have already completed them in Matlab and I'm having an issue with brightening an image. I have got the image to read into a Numpy array with no problem but when I use the following code to try to brighten it then show it:
def imageProcessing(self, imageLocation):
image = numpy.array(Image.open(imageLocation))
imageGreyScale = numpy.array(Image.open(imageLocation).convert('L'))
imageReadable = Image.fromarray(imageGreyScale)
imageReadable.show()
matplotlib.pyplot.hist(imageGreyScale.ravel(), 256, [0, 256]);
matplotlib.pyplot.show()
imageGreyScale = imageGreyScale+50
imageReadableBrighter = Image.fromarray(imageGreyScale)
imageReadableBrighter.show()
matplotlib.pyplot.hist(imageGreyScale.ravel(), 256, [0, 256]);
matplotlib.pyplot.show()
For some reason instead of data within 50 of 255 (the max grey level) being clipped at 255, the pixel value seems to hit 255 then go back to 0 and increment by however much is left (see the graph attached, the bit in red was beside the bit in green before the processing, but instead of being clipped has been "looped back" so to speak) Graph of the histogram after adding 50 to every pixel value
Now I have tried adding conditional assignment statements like Numpy.where(), etc but can't seem to get them to work correctly. Can anyone explain what's going on or how to fix it? Thank you.
Using: Python version 3.5, Latest version of Numpy, Latest version of PIL, On latest version of MacOS