Image enhancement based on "local standard deviation" (principle, algorithm, code)First, the theoryThe basic principle of image enhancement algorithm is to "reduce the low frequency region and highlight the high frequency region", so as to strengthen the edge and achieve the purpose of enhancement. The simplest example is the ability to strengthen the edges by subtracting the Gaussian blur from the original image. histogram equalization is also a very common enhancement method. But in order to avoid background interference, it is more inclined to use "local" method to deal with. We focus on the relevant content of adaptive contrast Enhancement (ACE) here. The definition and principle of aces (TODO)the relevant content of the ACE algorithm:Calculate Low-frequency components: For specific pixels, it is generally possible to calculate the pixel mean of the local area centered on the pixel.and the local variance is:
The ACE algorithm can be expressed as:
It seems to be quite simple. And all of this can be calculated from the image itself. Instead, it needs to be calculated separately.
Can be used as a separate constant, or as a substitute. The d here is a global value, such as an average.
Second, the realizationWhen it comes to local operations, it's natural to think of the convolution approach. Better yet, OPENCV provides specialized functions to do this work-blurThe document reads:So that's the result we want.Study on Adaptive Contrast equalization of//ace
//by Jsxyhelu
//Thank Imageshop
#
include"StdAfx.h"
#
include<iostream>
#
include"OPENCV2/CORE/CORE.HPP"
#
include "OPENCV2/HIGHGUI/HIGHGUI.HPP"
#
include"OPENCV2/IMGPROC/IMGPROC.HPP"
using
namespaceStd
using
namespaceCv
//Point multiplication elementwisemultiplication
Cv::Mat EWM (CV::Mat M1,CV::Mat m2) {
Mat DST=M1.mul (m2);
returnDst
}
voidMain ()
{
Mat SRC=Imread ("Hand.jpg",0);
Mat Meanmask;
Mat Varmask;
Mat Meanglobal;
Mat Varglobal;
Mat DST;
Mat tmp;
Mat TMP2;
intC= -;
intD=133;
//global mean and mean variance
Blur (Src.clone (), meanglobal,src.size ());
Varglobal=Src-Meanglobal;
Varglobal=EWM (Varglobal,varglobal);
Blur (Src.clone (), Meanmask,size ( -, -));//meanmask is the local mean value
Tmp=Src-Meanmask;
Varmask=EWM (TMP,TMP);
Blur (Varmask,varmask,size ( -, -));//varmask as local variance
Dst=Meanmask+C*tmp
Imshow ("src", SRC);
Imshow ("DST", DST);
Waitkey ();
}Next, in order to achievethen you need to calculate the local standard deviation and global mean or varianceThe local mean has been calculated before, soTmp=Src-Meanmask;
Varmask=EWM (TMP,TMP);
Blur (Varmask,varmask,size ( -, -));//varmask as local varianceCalculate the local variance//conversion into local standard deviation
Varmask.convertto (varmask,cv_32f);
for(
intI=0; I<Varmask.rows;i++){
for(
intJ=0; j<Varmask.cols;j++){
varmask.at<
float>(I,J)=(
float) sqrt (varmask.at<
float>(I,J));
}
} converted to local standard deviation meanstddev (Src,meanglobal,varglobal);//meanglobal global mean varglobal to global standard deviationis the global mean and standard deviation calculation function provided by OPENCV. after all the code is refactored, the followingStudy on Adaptive Contrast equalization of//ace
//by Jsxyhelu
//Thank Imageshop
#
include"StdAfx.h"
#
include<iostream>
#
include"OPENCV2/CORE/CORE.HPP"
#
include"OPENCV2/HIGHGUI/HIGHGUI.HPP"
#
include"OPENCV2/IMGPROC/IMGPROC.HPP"
using
namespaceStd
using
namespaceCv
//Point multiplication elementwisemultiplication
Cv::Mat EWM (CV::Mat M1,CV::Mat m2) {
Mat DST=M1.mul (m2);
returnDst
}
//image local contrast enhancement algorithm
Cv::Mat ACE (CV::Mat SRC,
intC=4,
intN= -,
intMaxcg= 5){
Mat Meanmask;
Mat Varmask;
Mat Meanglobal;
Mat Varglobal;
Mat DST;
Mat tmp;
Mat TMP2;
Blur (Src.clone (), Meanmask,size ( -, -));//meanmask is the local mean value
Tmp=Src-Meanmask;
Varmask=EWM (TMP,TMP);
Blur (Varmask,varmask,size ( -, -));//varmask as local variance
//conversion into local standard deviation
Varmask.convertto (varmask,cv_32f);
for(
intI=0; I<Varmask.rows;i++){
for(
intJ=0; j<Varmask.cols;j++){
varmask.at<
float>(I,J)=(
float) sqrt (varmask.at<
float>(I,J));
}
}
Meanstddev (Src,meanglobal,varglobal);//meanglobal global mean varglobal to global standard deviation
Tmp2=Varglobal/Varmask;
for(
intI=0; I<Tmp2.rows;i++){
for(
intJ=0; j<Tmp2.cols;j++){
if(tmp2.at<
float>(I,J)>MAXCG) {
tmp2.at<
float>(I,J)=MAXCG;
}
}
}
Tmp2.convertto (tmp2,cv_8u);
Tmp2=EWM (TMP2,TMP);
Dst=Meanmask+TMP2;
Imshow ("D method", DST);
Dst=Meanmask+C*tmp
Imshow ("C Method", DST);
returnDst
}
voidMain ()
{
Mat SRC=Imread ("Plant.bmp",0);
Imshow ("src", SRC);
ACE (SRC);
Waitkey ();
}Third, summary In terms of results, the ACE algorithm is significant for image detail enhancement in specific situations, but not for all situations, and its parameters need to be manually adjusted. By understanding its characteristics, we can solve a series of problems and effectively enhance reality.
From for notes (Wiz)
[Blogs Algorithm principle] local standard deviation to achieve contrast enhancement