Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Contrast Limited Adaptive Histogram Equalization
#4
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/tut...ation.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/bl...r/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.
Reply


Messages In This Thread
RE: Contrast Limited Adaptive Histogram Equalization - by remico - 05-31-2019, 05:24 PM

Forum Jump: