Tag Archives: image

CLAHE shading correction

Applying CLAHE to medical images may going to some shaded on each edge side of object. So I have to correct this problem with fast processing in real time.

To make up a prototype correction, I have used same source RAW image, here is a source image in down scaled from 16bit gray scale RAW.

Applied CLAHE with 16×16 in clip limit of 100.0f. And I could recognized shaded areas at each edge of object. Shaded area marked as red boxes in below.

To correct shaded area, generate gaussian blur mask with big radials, but it really heavy to processing in fast time as realtime. So I made it fastest way with my ‘Resize engine’ that made with OpenMP and AVX instructions. To generate fastest blurred mask, down scale with bi-linear filter to 2.5% size. Then doing up scale again with B-Spline filter to original size. And Invert it.

Then calculate to do shade correction with generated shade mask, ins fastest math functions with original image.

To complete image processing, need to fill background areas.

It simply corrected but little bit lacks on details of bone level. But definitely better than hard shaded levels after window leveling. Expect for next will find more improved processing algorithm, and it will be a function of librawprocessor.

Correcting shaded illumination on medical image.

By using CLAHE algorithm, there’s some problem occurs by object shapes like this:

Each edge side of object going too darken by window leveling. It is defecting issue of CLAHE. So I tried to make it corrected with shading correction.

Here is source raw image, 14bit gray.

First, I need make a background mask to overriding changed level after CLAHE.

It can generate simply by using my librawprocessor. Then I applied CLAHE, 10×10, 30.0f.

Shadowed or shaded areas occurs after applying CLAHE, it must be corrected. So I made shaded map with my fast resize engine. Down scale to 10% of original image size with Bi-Linear filter, then up scale again with B-Spline filter with inverse.

It is much effective than Gaussian blur. Very fast but similar to Gaussian blurred. almost realtime in 3000×3000 array with floating point¬† levels in AVX and OpenMP optimization.

Now I am just add masked shade map level with exponential to original image.

Result is :

Shaded object areas seems to enhanced than before. So I continued to applying background mask.

Ok, then I made it to window leveled.

Each edge sides are not seems to much shaded than before. It should be better than applying single CLAHE. I will continue to write more effective image processing with CLAHE.

An open source graphical help tool library, fl_imgtk.

Here is an open source library helps many Fl_RGB_Image processing to make some featured GUI.  You can clone or download source code in free on GitHub page.

It designed to work with any type of gcc ( llvm-gcc and MinGW-W64 ) with just a copy and type ‘make’, or modify Makefile.{your compiler} and copy to it as Makefile, then it could be compiled and writes libfl_imgtk.a into “lib” directory includes fl_imgtk.h.

What you can do ?

It provides some features to processing Fl_RGB_Image as like Photoshop.

  • Flip image in vertical or horizental.
  • Rotate image in any degree with smoothen pixels.
  • Adjusting contrast, bright and gamma.
  • Drawing image to blurred ( by using fl_smimg rescaling ).
  • Rescale with muliple filters ( nearest, bilinear, bicubic, lanczos, b-spline )
  • Tone mapping ( HDRi ) with two different algorithms : Drago and Reinhard ( refered to FreeImage3 )
  • Kernel matrix filtering ( basically supports blur, blur more, sharpen, sharpen more filters)
    Specially any user can make a new kernel filter easily.
  • Draw Fl_Widget to Fl_RGB_Image
  • Draw Fl_Widget to blurred Fl_RGB_Image as it could be used in cool background.
  • Cropping image to a part of new image.


Before you start with this open source library, prepare what FLTK library compiled or installed in your system. I amd working my clone version of FLTK 1.3.4-1.

First you need to do, download or cloen with your git into your working directoy. Then, copy Makefile.{your compiler} to Makefle. ( ex, cp Makefile.gcc Makefile )

Now just proceeding make.

If you faced to unknown reference of FLTK libraries, you may need edit Makefile.

You can changes FLTK_xxx configuration to your right place. It will works well any platform that availed to compile FLTK library.

Any question ?

You can make a new issue on my GitHub page, or my Guest book on my blog.



  • MIT License


External Licenses

  • FLTK license
  • FreeImage (3) license.

RAW scale process speed at Intel AVX instruction.



My medical RAW image scale processor benchmarked for Intel AVX instruction set. It was fully reprogrammed for be affected by optimization algorithm by compiler option.

Specification of benchmark

  • CPU: Intel Core i7-6700 @ 4GHz (Skylake-S)
  • Memory: DDR4-1066 16GB (Single channel)
  • OS: Windows 7 professional 64bit


  • MinGW-W64 64bit version 4.8.0

Compiler options

  • -fomit-frame-pointer
  • -fexpensive-optimizations
  • -O3
  • -s
  • -m64
  • -march=corei7-avx

RAW image source

  • 3072×3072, 16bit grayscale X-Ray image


Benchmark rule

  • Scale each different filter for double size.



  • Nearest (box) scale : 0.597 seconds.


  • Bilinear scale : 0.597 seconds.
  • Bicubic scale : 0.693 seconds.
  • Lanzcos 3 taps : 0.884 seconds.

Specially lanzcos 3 scale took 30% more speed at under 1 second. So I looking fore more faster way how it make faster than now. And it is almost same with B-Spline filter, or sometimes B-Spline faster than lanczos3, Hmmm …

Download test console program

Blackview Alife S1 rear camera samples.

Here I uploads some sample pictures from Blackview Alife S1 rear camera.

Blackview Alife S1 rear camera samples.


Image quality is good for well in white balance, so most users may not worry about need retouching. But smoothing is too rough, and it goes picture being damaged in pixels. It is similar like Qualcom ISP. But I like these pictures for my snapshots and it will be resized to half or quad.