Retinex, correction to last commit, code cleaned
This commit is contained in:
parent
0120bcd836
commit
6dbb1af4c9
1
astylert.bat
Normal file
1
astylert.bat
Normal file
@ -0,0 +1 @@
|
|||||||
|
astyle --options=rawtherapee.astylerc -n %1
|
@ -129,13 +129,14 @@ template<class T, class A> void boxblur (T** src, A** dst, int radx, int rady, i
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<class T, class A> void boxblurnew (T** src, A** dst, T* buffer, int radx, int rady, int W, int H)
|
template<class T, class A> void boxblur (T** src, A** dst, T* buffer, int radx, int rady, int W, int H)
|
||||||
{
|
{
|
||||||
|
|
||||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
//box blur image; box range = (radx,rady)
|
//box blur image; box range = (radx,rady)
|
||||||
|
|
||||||
float* temp = buffer;
|
float* temp = buffer;
|
||||||
|
|
||||||
if (radx == 0) {
|
if (radx == 0) {
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
#pragma omp for
|
#pragma omp for
|
||||||
@ -152,24 +153,27 @@ template<class T, class A> void boxblurnew (T** src, A** dst, T* buffer, int rad
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int row = 0; row < H; row++) {
|
for (int row = 0; row < H; row++) {
|
||||||
int len = radx + 1;
|
float len = radx + 1;
|
||||||
temp[row * W + 0] = (float)src[row][0] / len;
|
float tempval = (float)src[row][0];
|
||||||
|
|
||||||
for (int j = 1; j <= radx; j++) {
|
for (int j = 1; j <= radx; j++) {
|
||||||
temp[row * W + 0] += (float)src[row][j] / len;
|
tempval += (float)src[row][j];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
tempval /= len;
|
||||||
|
temp[row * W + 0] = tempval;
|
||||||
|
|
||||||
for (int col = 1; col <= radx; col++) {
|
for (int col = 1; col <= radx; col++) {
|
||||||
temp[row * W + col] = (temp[row * W + col - 1] * len + (float)src[row][col + radx]) / (len + 1);
|
temp[row * W + col] = tempval = (tempval * len + (float)src[row][col + radx]) / (len + 1);
|
||||||
len ++;
|
len ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int col = radx + 1; col < W - radx; col++) {
|
for (int col = radx + 1; col < W - radx; col++) {
|
||||||
temp[row * W + col] = temp[row * W + col - 1] + ((float)(src[row][col + radx] - src[row][col - radx - 1])) / len;
|
temp[row * W + col] = tempval = tempval + ((float)(src[row][col + radx] - src[row][col - radx - 1])) / len;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int col = W - radx; col < W; col++) {
|
for (int col = W - radx; col < W; col++) {
|
||||||
temp[row * W + col] = (temp[row * W + col - 1] * len - src[row][col - radx - 1]) / (len - 1);
|
temp[row * W + col] = tempval = (tempval * len - src[row][col - radx - 1]) / (len - 1);
|
||||||
len --;
|
len --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -192,35 +196,51 @@ template<class T, class A> void boxblurnew (T** src, A** dst, T* buffer, int rad
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
for (int col = 0; col < W - numCols + 1; col += 8) {
|
for (int col = 0; col < W - numCols + 1; col += 8) {
|
||||||
int len = rady + 1;
|
float len = rady + 1;
|
||||||
for(int k=0;k<numCols;k++)
|
|
||||||
dst[0][col + k] = temp[0 * W + col + k] / len;
|
for(int k = 0; k < numCols; k++) {
|
||||||
|
dst[0][col + k] = temp[0 * W + col + k];
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 1; i <= rady; i++) {
|
for (int i = 1; i <= rady; i++) {
|
||||||
for(int k=0;k<numCols;k++)
|
for(int k = 0; k < numCols; k++) {
|
||||||
dst[0][col + k] += temp[i * W + col + k] / len;
|
dst[0][col + k] += temp[i * W + col + k];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int k = 0; k < numCols; k++) {
|
||||||
|
dst[0][col + k] /= len;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int row = 1; row <= rady; row++) {
|
for (int row = 1; row <= rady; row++) {
|
||||||
for(int k=0;k<numCols;k++)
|
for(int k = 0; k < numCols; k++) {
|
||||||
dst[row][col + k] = (dst[(row - 1)][col + k] * len + temp[(row + rady) * W + col + k]) / (len + 1);
|
dst[row][col + k] = (dst[(row - 1)][col + k] * len + temp[(row + rady) * W + col + k]) / (len + 1);
|
||||||
|
}
|
||||||
|
|
||||||
len ++;
|
len ++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int row = rady + 1; row < H - rady; row++) {
|
for (int row = rady + 1; row < H - rady; row++) {
|
||||||
for(int k=0;k<numCols;k++)
|
for(int k = 0; k < numCols; k++) {
|
||||||
dst[row][col + k] = dst[(row - 1)][col + k] + (temp[(row + rady) * W + col + k] - temp[(row - rady - 1) * W + col + k]) / len;
|
dst[row][col + k] = dst[(row - 1)][col + k] + (temp[(row + rady) * W + col + k] - temp[(row - rady - 1) * W + col + k]) / len;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (int row = H - rady; row < H; row++) {
|
for (int row = H - rady; row < H; row++) {
|
||||||
for(int k=0;k<numCols;k++)
|
for(int k = 0; k < numCols; k++) {
|
||||||
dst[row][col + k] = (dst[(row - 1)][col + k] * len - temp[(row - rady - 1) * W + col + k]) / (len - 1);
|
dst[row][col + k] = (dst[(row - 1)][col + k] * len - temp[(row - rady - 1) * W + col + k]) / (len - 1);
|
||||||
|
}
|
||||||
|
|
||||||
len --;
|
len --;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef _OPENMP
|
||||||
#pragma omp single
|
#pragma omp single
|
||||||
|
#endif
|
||||||
|
|
||||||
for (int col = W - (W % numCols); col < W; col++) {
|
for (int col = W - (W % numCols); col < W; col++) {
|
||||||
int len = rady + 1;
|
float len = rady + 1;
|
||||||
dst[0][col] = temp[0 * W + col] / len;
|
dst[0][col] = temp[0 * W + col] / len;
|
||||||
|
|
||||||
for (int i = 1; i <= rady; i++) {
|
for (int i = 1; i <= rady; i++) {
|
||||||
|
@ -769,7 +769,7 @@ template<class T> void gaussianBlur(T** src, T** dst, const int W, const int H,
|
|||||||
// Compute ideal averaging filter width and number of iterations
|
// Compute ideal averaging filter width and number of iterations
|
||||||
int n = 1;
|
int n = 1;
|
||||||
double wIdeal = sqrt((12*sigma*sigma)+1);
|
double wIdeal = sqrt((12*sigma*sigma)+1);
|
||||||
while(wIdeal >= (W/2-1) || wIdeal >= (H/2-1)) {
|
while(wIdeal > W || wIdeal > H) {
|
||||||
n++;
|
n++;
|
||||||
wIdeal = sqrt((12*sigma*sigma/n)+1);
|
wIdeal = sqrt((12*sigma*sigma/n)+1);
|
||||||
}
|
}
|
||||||
@ -789,13 +789,11 @@ template<class T> void gaussianBlur(T** src, T** dst, const int W, const int H,
|
|||||||
|
|
||||||
int sizes[n];
|
int sizes[n];
|
||||||
for(int i=0; i<n; i++) {
|
for(int i=0; i<n; i++) {
|
||||||
sizes[i] = i<m?wl:wu;
|
sizes[i] = ((i<m?wl:wu)-1)/2;
|
||||||
}
|
}
|
||||||
//#pragma omp critical
|
rtengine::boxblur(src,dst,buffer,sizes[0],sizes[0],W,H);
|
||||||
// printf("sigma : %f\tsizes[0] : %d\tsizes[3] : %f\titerations : %d\n",sigma,sizes[0],sqrt((12*sigma*sigma/3)+1),n);
|
|
||||||
rtengine::boxblurnew(src,dst,buffer,sizes[0],sizes[0],W,H);
|
|
||||||
for(int i=1; i<n; i++) {
|
for(int i=1; i<n; i++) {
|
||||||
rtengine::boxblurnew(dst,dst,buffer, sizes[i],sizes[i],W,H);
|
rtengine::boxblur(dst,dst,buffer, sizes[i],sizes[i],W,H);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,9 +100,6 @@ void retinex_scales( float* scales, int nscales, int mode, int s, float high)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < nscales; ++i )
|
|
||||||
printf("sigma[%d] : %f\n",i,scales[i]);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
void mean_stddv2( float **dst, float &mean, float &stddv, int W_L, int H_L, float &maxtr, float &mintr)
|
void mean_stddv2( float **dst, float &mean, float &stddv, int W_L, int H_L, float &maxtr, float &mintr)
|
||||||
{
|
{
|
||||||
@ -210,7 +207,6 @@ void mean_stddv( float **dst, float &mean, float &stddv, int W_L, int H_L, const
|
|||||||
|
|
||||||
void RawImageSource::MSR(float** luminance, float** originalLuminance, float **exLuminance, int width, int height, RetinexParams deh, const RetinextransmissionCurve & dehatransmissionCurve, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax)
|
void RawImageSource::MSR(float** luminance, float** originalLuminance, float **exLuminance, int width, int height, RetinexParams deh, const RetinextransmissionCurve & dehatransmissionCurve, float &minCD, float &maxCD, float &mini, float &maxi, float &Tmean, float &Tsigma, float &Tmin, float &Tmax)
|
||||||
{
|
{
|
||||||
StopWatch Stop1("MSR");
|
|
||||||
if (deh.enabled) {//enabled
|
if (deh.enabled) {//enabled
|
||||||
float mean, stddv, maxtr, mintr;
|
float mean, stddv, maxtr, mintr;
|
||||||
// float mini, delta, maxi;
|
// float mini, delta, maxi;
|
||||||
@ -310,7 +306,12 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e
|
|||||||
}
|
}
|
||||||
|
|
||||||
const float logBetaGain = xlogf(16384.f);
|
const float logBetaGain = xlogf(16384.f);
|
||||||
const float pond = logBetaGain / (float) scal;
|
float pond = logBetaGain / (float) scal;
|
||||||
|
|
||||||
|
if(!useHslLin) {
|
||||||
|
pond /= log(elogt);
|
||||||
|
}
|
||||||
|
|
||||||
float *buffer = new float[W_L * H_L];;
|
float *buffer = new float[W_L * H_L];;
|
||||||
|
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
@ -328,7 +329,6 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e
|
|||||||
vfloat pondv = F2V(pond);
|
vfloat pondv = F2V(pond);
|
||||||
vfloat limMinv = F2V(ilimD);
|
vfloat limMinv = F2V(ilimD);
|
||||||
vfloat limMaxv = F2V(limD);
|
vfloat limMaxv = F2V(limD);
|
||||||
vfloat elogtv = F2V(elogt);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
#ifdef _OPENMP
|
#ifdef _OPENMP
|
||||||
@ -346,7 +346,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (; j < W_L - 3; j += 4) {
|
for (; j < W_L - 3; j += 4) {
|
||||||
_mm_storeu_ps(&luminance[i][j], LVFU(luminance[i][j]) + pondv * xlogf(LIMV(LVFU(src[i][j]) / LVFU(out[i][j]), limMinv, limMaxv) ) / xlogf(elogtv));
|
_mm_storeu_ps(&luminance[i][j], LVFU(luminance[i][j]) + pondv * xlogf(LIMV(LVFU(src[i][j]) / LVFU(out[i][j]), limMinv, limMaxv) ));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -358,7 +358,7 @@ void RawImageSource::MSR(float** luminance, float** originalLuminance, float **e
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (; j < W_L; j++) {
|
for (; j < W_L; j++) {
|
||||||
luminance[i][j] += pond * xlogf(LIM(src[i][j] / out[i][j], ilimD, limD)) / log(elogt); // /logt ?
|
luminance[i][j] += pond * xlogf(LIM(src[i][j] / out[i][j], ilimD, limD)); // /logt ?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,7 @@ void RetinexParams::setDefaults()
|
|||||||
offs = 0;
|
offs = 0;
|
||||||
vart = 200;
|
vart = 200;
|
||||||
limd = 8;
|
limd = 8;
|
||||||
highl = 10;
|
highl = 4;
|
||||||
baselog = 2.71828;
|
baselog = 2.71828;
|
||||||
// grbl = 50;
|
// grbl = 50;
|
||||||
retinexMethod = "high";
|
retinexMethod = "high";
|
||||||
|
@ -117,7 +117,7 @@ Retinex::Retinex () : FoldableToolPanel(this, "retinex", M("TP_RETINEX_LABEL"),
|
|||||||
|
|
||||||
str = Gtk::manage (new Adjuster (M("TP_RETINEX_STRENGTH"), 0, 100., 1., 20.));
|
str = Gtk::manage (new Adjuster (M("TP_RETINEX_STRENGTH"), 0, 100., 1., 20.));
|
||||||
neigh = Gtk::manage (new Adjuster (M("TP_RETINEX_NEIGHBOR"), 6, 100., 1., 80.));
|
neigh = Gtk::manage (new Adjuster (M("TP_RETINEX_NEIGHBOR"), 6, 100., 1., 80.));
|
||||||
highl = Gtk::manage (new Adjuster (M("TP_RETINEX_HIGHLIGHT"), 1, 100, 1, 10));
|
highl = Gtk::manage (new Adjuster (M("TP_RETINEX_HIGHLIGHT"), 1, 20, 1, 4));
|
||||||
highl->set_tooltip_markup (M("TP_RETINEX_HIGHLIGHT_TOOLTIP"));
|
highl->set_tooltip_markup (M("TP_RETINEX_HIGHLIGHT_TOOLTIP"));
|
||||||
vart = Gtk::manage (new Adjuster (M("TP_RETINEX_VARIANCE"), 50, 500, 1, 200));
|
vart = Gtk::manage (new Adjuster (M("TP_RETINEX_VARIANCE"), 50, 500, 1, 200));
|
||||||
vart->set_tooltip_markup (M("TP_RETINEX_VARIANCE_TOOLTIP"));
|
vart->set_tooltip_markup (M("TP_RETINEX_VARIANCE_TOOLTIP"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user