New_image = (image - mean) * contrast_coeff + mean # change contrastĪlso you might want to convert result to int, so it would be better to cut values under 0 and over 1. Mean = np.mean(image, axis=-1) # compute mean values over each channel However, I didn't use it, because as you can notice, it doesn't make dark pixels darker and light pixels lighter simultaneously, if you want to change only contrast.Įarlier I used contrast adjustment from tensorflow, so I use formula from it: float_image = image / 255.0 # image must be float!! It says that you can adjust contrast and brightness this way: new_image = old_image * contrast_coeff + brightness_coeff I couldn't find OpenCV function for this, but I found that guide: (left is unprocessed, right is equalized) Outfile = os.path.splitext(fname) + '_eq.jpg' # change fname to tack on eqĬv2.imwrite(outfile, np.hstack((img,out))) # extension to jpg I used the mandrill and couple reference images from USC SIPI database For this post, I'll only do (1) equalization. The second technique comes into play if your images have some regions that are locally bright and you don't want them to be washed out. There are two major techniques available in OpenCV: (1) equalization (2) contrast limited equalization. The official docs for OpenCV have a great Python tutorial on histogram equalization. In this technique, you stretch the intensities to a wider range. It's a little surprising that no one has suggested histogram equalization.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |