Fixed some bugs in Noise Reduction, Issue 2557 #254
This commit is contained in:
parent
b05fa5d6a1
commit
9e3ea2924c
@ -379,8 +379,8 @@ SSEFUNCTION void ImProcFunctions::RGB_denoise(int kall, Imagefloat * src, Imagef
|
||||
//#endif
|
||||
if (dnparams.luma==0 && dnparams.chroma==0 && !dnparams.median && !noiseLCurve && !noiseCCurve) {
|
||||
//nothing to do; copy src to dst or do nothing in case src == dst
|
||||
if(src != dst)
|
||||
memcpy(dst->data,src->data,dst->width*dst->height*3*sizeof(float));
|
||||
if(src != dst)
|
||||
src->copyData(dst);
|
||||
if(calclum) {
|
||||
delete calclum;
|
||||
calclum = NULL;
|
||||
@ -420,10 +420,10 @@ SSEFUNCTION void ImProcFunctions::RGB_denoise(int kall, Imagefloat * src, Imagef
|
||||
const float noiseluma=(float) dnparams.luma;
|
||||
const float noisevarL = (useNoiseLCurve && (denoiseMethodRgb || !isRAW)) ? (float) (SQR(((noiseluma+1.0)/125.0)*(10.+ (noiseluma+1.0)/25.0))) : (float) (SQR((noiseluma/125.0)*(1.0+ noiseluma/25.0)));
|
||||
const bool denoiseLuminance = (noisevarL > 0.00001f);
|
||||
|
||||
|
||||
if(useNoiseLCurve || useNoiseCCurve) {
|
||||
int hei=calclum->height;
|
||||
int wid=calclum->width;
|
||||
int wid=calclum->width;
|
||||
TMatrix wprofi = iccStore->workingSpaceMatrix (params->icm.working);
|
||||
|
||||
const float wpi[3][3] = {
|
||||
@ -479,7 +479,7 @@ SSEFUNCTION void ImProcFunctions::RGB_denoise(int kall, Imagefloat * src, Imagef
|
||||
}
|
||||
delete calclum;
|
||||
calclum = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
const short int imheight=src->height, imwidth=src->width;
|
||||
|
||||
@ -593,9 +593,16 @@ do {
|
||||
if(numtiles == 1)
|
||||
dsttmp = dst;
|
||||
else {
|
||||
dsttmp = new Imagefloat(imwidth,imheight);
|
||||
for (int n=0; n<3*imwidth*imheight; n++)
|
||||
dsttmp->data[n] = 0;
|
||||
dsttmp = new Imagefloat(imwidth,imheight);
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i=0;i<imheight;i++)
|
||||
for(int j=0;j<imwidth;j++) {
|
||||
dsttmp->r(i,j) = 0.f;
|
||||
dsttmp->g(i,j) = 0.f;
|
||||
dsttmp->b(i,j) = 0.f;
|
||||
}
|
||||
}
|
||||
|
||||
//now we have tile dimensions, overlaps
|
||||
@ -685,7 +692,7 @@ do {
|
||||
int pos;
|
||||
float* noisevarlum;
|
||||
float* noisevarchrom;
|
||||
if(numtiles == 1 && isRAW) {
|
||||
if(numtiles == 1 && isRAW && (useNoiseCCurve || useNoiseLCurve)) {
|
||||
noisevarlum = lumcalcBuffer;
|
||||
noisevarchrom = ccalcBuffer;
|
||||
} else {
|
||||
@ -705,7 +712,7 @@ do {
|
||||
int tilebottom = MIN(imheight,tiletop+tileheight);
|
||||
int width = tileright-tileleft;
|
||||
int height = tilebottom-tiletop;
|
||||
int width2 = (width+1)/2;
|
||||
int width2 = (width+1)/2;
|
||||
float realred, realblue;
|
||||
float interm_med =(float) dnparams.chroma/10.0;
|
||||
float intermred, intermblue;
|
||||
@ -904,7 +911,13 @@ do {
|
||||
else levwav=8;//maximum ==> I have increase Maxlevel in cplx_wavelet_dec.h from 8 to 9
|
||||
if(nrQuality == QUALITY_HIGH)
|
||||
levwav += settings->nrwavlevel;//increase level for enhanced mode
|
||||
if(levwav>8) levwav=8;
|
||||
if(levwav>8) levwav=8;
|
||||
int minsizetile=min(tilewidth, tileheight);
|
||||
int maxlev2=8;
|
||||
if(minsizetile < 256) maxlev2 = 7;
|
||||
if(minsizetile < 128) maxlev2 = 6;
|
||||
if(minsizetile < 64) maxlev2 = 5;
|
||||
levwav=min(maxlev2,levwav);
|
||||
|
||||
// if (settings->verbose) printf("levwavelet=%i noisevarA=%f noisevarB=%f \n",levwav, noisevarab_r, noisevarab_b );
|
||||
Ldecomp = new wavelet_decomposition (labdn->L[0], labdn->W, labdn->H, levwav, 1, 1, max(1,denoiseNestedLevels));
|
||||
@ -1400,7 +1413,7 @@ do {
|
||||
|
||||
}//end of tile row
|
||||
}//end of tile loop
|
||||
if(numtiles > 1 || !isRAW) {
|
||||
if(numtiles > 1 || !isRAW || (!useNoiseCCurve && !useNoiseLCurve)) {
|
||||
delete [] noisevarlum;
|
||||
delete [] noisevarchrom;
|
||||
}
|
||||
@ -1418,20 +1431,23 @@ omp_set_nested(oldNested);
|
||||
#endif
|
||||
//copy denoised image to output
|
||||
if(numtiles>1) {
|
||||
if(!memoryAllocationFailed)
|
||||
memcpy (dst->data, dsttmp->data, 3*dst->width*dst->height*sizeof(float));
|
||||
if(!memoryAllocationFailed)
|
||||
dsttmp->copyData(dst);
|
||||
else if(dst != src)
|
||||
memcpy (dst->data, src->data, 3*dst->width*dst->height*sizeof(float));
|
||||
src->copyData(dst);
|
||||
delete dsttmp;
|
||||
}
|
||||
if (!isRAW && !memoryAllocationFailed) {//restore original image gamma
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for (int i=0; i<3*dst->width*dst->height; i++) {
|
||||
dst->data[i] = Color::gammatab_srgb[ dst->data[i] ];
|
||||
}
|
||||
}
|
||||
if (!isRAW && !memoryAllocationFailed) {//restore original image gamma
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for(int i=0;i<dst->height;i++)
|
||||
for(int j=0;j<dst->width;j++) {
|
||||
dst->r(i,j) = Color::gammatab_srgb[ dst->r(i,j) ];
|
||||
dst->g(i,j) = Color::gammatab_srgb[ dst->g(i,j) ];
|
||||
dst->b(i,j) = Color::gammatab_srgb[ dst->b(i,j) ];
|
||||
}
|
||||
}
|
||||
|
||||
if(denoiseLuminance) {
|
||||
// destroy the plans
|
||||
@ -1749,7 +1765,7 @@ SSEFUNCTION void ImProcFunctions::RGBtile_denoise (float * fLblox, int hblproc,
|
||||
int histo[256] ALIGNED64 = {0};
|
||||
|
||||
//calculate histogram of absolute values of wavelet coeffs
|
||||
for (int i=0; i<datalen; i++) {
|
||||
for (int i=0; i<datalen; i++) {
|
||||
histo[min(255,abs((int)DataList[i]))]++;
|
||||
}
|
||||
|
||||
@ -2108,7 +2124,7 @@ SSEFUNCTION bool ImProcFunctions::WaveletDenoiseAll_BiShrinkAB(wavelet_decomposi
|
||||
maxWL = WaveletCoeffs_L.level_W(lvl);
|
||||
if(WaveletCoeffs_L.level_H(lvl) > maxHL)
|
||||
maxHL = WaveletCoeffs_L.level_H(lvl);
|
||||
}
|
||||
}
|
||||
bool memoryAllocationFailed = false;
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel num_threads(denoiseNestedLevels) if(denoiseNestedLevels>1)
|
||||
|
@ -519,9 +519,10 @@ namespace rtengine {
|
||||
|
||||
int rowstride; // Plan size, in bytes (all padding bytes included)
|
||||
int planestride; // Row length, in bytes (padding bytes included)
|
||||
|
||||
public:
|
||||
protected:
|
||||
T* data;
|
||||
|
||||
public:
|
||||
PlanarPtr<T> r;
|
||||
PlanarPtr<T> g;
|
||||
PlanarPtr<T> b;
|
||||
|
Loading…
x
Reference in New Issue
Block a user