ZEISS Microscopy Knowledge Base
Help
ZEISS Microscopy Knowledge Base

Performing contrast limited adaptive histogram equalization (CLAHE)»

This guide explains how to apply the contrast limited adaptive histogram equalization (CLAHE) algorithm. The CLAHE algorithm partitions the images into contextual regions and applies the histogram equalization to each one. This evens out the distribution of used grey values and thus makes hidden features of the image more visible. The full grey spectrum is used to express the image. CLAHE is an improved version of AHE, or Adaptive Histogram Equalization. Both overcome the limitations of standard histogram equalization.

Opening the working dataset

  1. Select Open... from the file menu.
    File menu showing Open... option highlighted with CTRL+O shortcut
  2. Select the dataset from the file browser.
    The dataset is a multi dimensional, discrete, representation of your real sample volume. It can be structured as a Z series of planes (Optical sectioning) of multiple channels (dyes) in a temporal sequence of time points (located in several spatial positions).​
    Usually, the dataset shows a single experimental situation (a complete experiment can be composed by several datasets). The datasets are available as graphic files saved in plenty of file formats (standard formats as well as proprietary formats)​.
    Note: The dataset is visualized according to the current rendering setting parameters. Refer to the arivis Vision4D Help for more details.
    Red fluorescence microscopy image with punctate and curved bright structures on black background

Loading the Python script

  1. Open Python Script Editor. From the Extra menu, select Script Editor.
    Extras menu dropdown listing Preferences..., Plug-in Manager, Task Monitor, Run Script..., Script Editor
  2. Load the Clahe_Rev5 (3_4).py Python Script.
    Script Editor - Script1 title bar showing menus File, Edit, View, Script
  3. Browse the folder on which the file has been saved.
    File menu with 'Open...  Ctrl+O' highlighted, 'New  Ctrl+N' above, 'Open Sample' and 'Close  Ctrl+F4' below

Python script code usage rights:The user has the permission to use, modify and distribute this code, as long as this copyright notice remains part of the code itself: Copyright(c) 2021 arivis AG, Germany. All Rights Reserved.

Python script header comments showing NAME: Clahe - Automatic Histogram enhancement and FILE: Clahe_Rev5 (3_4).py

Setting the script features

Some Clahe algorithm options can be set to optimize the results:

Code screenshot of CLAHE options showing INPUT_CHANNEL=0, OUTPUT_CH_NAME='Clahe_', CLAHE_CV2=True, CLIP_LIMIT_CV2=30

  • INPUT_CHANNEL : Set the source channel to be equalized. NOTE: Only one channel can be processed.
  • OUTPUT_CH_CHANNEL : Set the output channel name.

The size used to compute the Clahe can be freely set.

  • CLAHE_CV2 = True : Set the OpenCV2 algorithm – False the Skimage one.
  • HISTO_STRETCH : With the CLAHE_CV2 = False sets the result stretching.
  • BLOCK_NUMBER_X : Sets the number of horizontal patches (tiles) used to compute the local equlization.
  • BLOCK_NUMBER_Y : Sets the number of vertical patches (tiles) used to compute the local equalization.
  • CLIP_LIMIT_CV2 : Sets the clipping limit, normalized between 0 and 100 (higher values give more contrast). It is applied to the OpenCv2 algorithm.
  • CLIP_LIMIT_SKIMAGE : Sets the clipping limit, normalized between 0 and 1 (higher values give more contrast). It is applied to the Skimage algorithm.
  • ACTIVE_FRAME : If True, the Clahe is applied only to the active time point.
  • ACTIVE_PLANE : If True, the Clahe is applied only to the active Z plane.

Code lines: ACTIVE_PLANE = False  # True == active plane; ACTIVE_FRAME = True  # True == active time point

Installing the Anaconda3 package and the OpenCV module

The Anaconda3 Package and the OpenCV module are required to run the script. Please refer to the Application Note #20 for more details.

  1. Once the Anaconda3 package has been correctly installed, the OpenCV module can be installed too.
  1. From the Window menu, select the Anaconda Prompt.
    White Windows logo tile on dark background
    Start menu listing Anaconda3 (64-bit) with Anaconda Prompt (anaconda3) outlined in red
  2. Type pip install opencv-python and press return.
    Anaconda Prompt showing (base) C:\Users\utente>pip install opencv-python
  3. A message confirms the correct OpenCv installation.
    Anaconda PowerShell Prompt showing conda env list and pip install opencv-python output with Successfully installed opencv-python-4.5.2.52
Impressum
Carl-Zeiss-Strasse 22
73447 Oberkochen
Germany
Legal