Contrast Limited Adaptive Histogram Equalization - Printable Version +- Gimp-Forum.net (https://www.gimp-forum.net) +-- Forum: GIMP (https://www.gimp-forum.net/Forum-GIMP) +--- Forum: Extending the GIMP (https://www.gimp-forum.net/Forum-Extending-the-GIMP) +--- Thread: Contrast Limited Adaptive Histogram Equalization (/Thread-Contrast-Limited-Adaptive-Histogram-Equalization) |
Contrast Limited Adaptive Histogram Equalization - remico - 05-16-2019 Hello, There is a page on wikipeda on contrast limited adaptative histogram equalization : https://en.wikipedia.org/wiki/Adaptive_histogram_equalization There is an implementation of contrast limited adaptative histogram equalization on Imagej (Plugins =>Filter => Enhance Local Contrast) with settings for blocksize, histogram bins, max slope. Imagemagick also can do contrast limited adaptative histogram equalization, i have also found it on github : https://imagemagick.org/script/clahe.php https://github.com/erich666/GraphicsGems/blob/master/gemsiv/clahe.c I don't know equivalent action in Gimp, similar but not the same are tone mapping algorithm like Mantiuk, Reinhard, fattal. Maybe this algorithm can be ported to Gimp as plugin, filter or Gegl action. On some picture it can be useful to have a better contrast with blocksize to match length of picture and smaller or to get drawing effect with very smaller blocksize and histogram bins. Here for instance a 387x259 photo with Imagej and different settings : First row Original - settings blocksize 387, histogram bins 256, max slope 3 Second row 60/60/3 30/30/3 RE: Contrast Limited Adaptive Histogram Equalization - rich2005 - 05-16-2019 You might find something in the g'mic_gimp plugin or even the g'mic standalone. http://www.gmic.eu Lots of filters for various effects. example: https://i.imgur.com/DjswDVh.jpg and various settings https://i.imgur.com/baRgdtI.jpg Still using Gimp 2.8? What linux distro is that? You might have to look for a copy in the distro repo (or use Windows) RE: Contrast Limited Adaptive Histogram Equalization - remico - 05-16-2019 Thanks for answer. I know how to do with Imagej whatever old pc and os I use, that's enough for me. With "good quality" settings (large blocksize and sufficient histogram bins)) this algorithm rescue very well some picture, especially those which have bad lighting conditions. With very smaller blocksize and histogram bins number, i can get what i call drawing effect or watercolor painting efect. I tought it woud be interesting to have this code in Gimp and do not have enough knowledge in programming to know if it is even possible from the c code of 1985 on github. This code is also mentionned on this pdf Graphic Gems 4 at page 474 : http://ftp.ftp.borg.moe/yarr/Gentoomen%20Library/Game%20Development/Programming/Graphics%20Gems%204.pdf Gmic filter seems interesting but settings do not match with those of Imagej. Also sky is not so blue and there is not what i call drawing effect when lowering blocksize and histograms bins. I mentionned above Imagemagick can also do, but with same settings, results are little different and need further adjustment on contrast-luminosity-saturation to match results of Imagej. Another try with bigger picture, i add an artistic effect from Gimp RE: Contrast Limited Adaptive Histogram Equalization - remico - 05-31-2019 Gimp 2.8 come with Python 2.7, and there is Opencv which can do this histogram eqaulzation with Python. On XP, I have manually installed, the 2.4.9 version of Opencv, added bin folder to windows environment path, added pip to python with get-pip (2.6 version ) => https://bootstrap.pypa.io Newer versions of python have pip, and newer versions of windows may run last Opencv, to install : pip install opencv in python shell or python -m pip install opencv from command line. Then I can run this script from Opencv documentation : https://docs.opencv.org/3.1.0/d5/daf/tutorial_py_histogram_equalization.html import numpy as np import cv2 img = cv2.imread('tsukuba_l.png',0) # create a CLAHE object (Arguments are optional). clahe = cv2.createCLAHE(clipLimit=3.0, tileGridSize=(16,16)) cl1 = clahe.apply(img) cv2.imwrite('clahe2.jpg',cl1) It is for grayscaled image, color image don't make errors but processed are grayscaled. I founnd another one for color image in Lab mode but can be translated to lot opencv can process : https://github.com/Umity/python-clahe/blob/master/clahe.py Those two scripts work well and are a lot faster than Imagej for images with length or width > 400 pix, some seconds for a 10Mpix image on my old computer. I can run these instructions in Gimp Python console : ( i didn't find he way to process directly image loaded in gimp, so i save it and reload with opencv command.) GIMP 2.8.20 Python Console Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)] ➤> from gimpfu import * ➤> image = gimp.image_list()[0] ➤> layer = image.active_layer ➤> pdb.gimp_file_save(image, layer, 'image.bmp', '?') ➤> import numpy as np ➤> import cv2 ➤> bgr = cv2.imread('image.bmp') ➤> hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV) ➤> hsv_planes = cv2.split(hsv) ➤> clahe = cv2.createCLAHE(clipLimit=3.0,tileGridSize=(8,8)) ➤> hsv_planes[2] = clahe.apply(hsv_planes[2]) ➤> hsv = cv2.merge(hsv_planes) ➤> bgr = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR) ➤> cv2.imwrite('img-output.jpg',bgr) True ➤> It write processed image in my "Documents and settings/user" folder. I've tried to learn howto translate it on a plugin for Gimp, with settings for clipLimit, tileGridsize, channel to process without success. RE: Contrast Limited Adaptive Histogram Equalization - Ofnuts - 05-31-2019 (05-31-2019, 05:24 PM)remico Wrote: I've tried to learn howto translate it on a plugin for Gimp, with settings for clipLimit, tileGridsize, channel to process without success. If you want a real plugin, then the plugin should work in RAM without requiring temp files. See here for an example plugin that moves layer data to a numpy array, processes it, and rebuilds a result layer from the numpy array. My full collection of python plugins: http://sourceforge.net/projects/gimp-tools/files/scripts/ Hop over in Scripting questions if you have more questions. |