isRAW flag on behalf of Olli and Emil
This commit is contained in:
parent
c2d16bf2e5
commit
8ad75d0ff7
@ -81,7 +81,7 @@ namespace rtengine {
|
||||
|
||||
|
||||
|
||||
void ImProcFunctions::RGB_denoise(Imagefloat * src, Imagefloat * dst, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe)
|
||||
void ImProcFunctions::RGB_denoise(Imagefloat * src, Imagefloat * dst, bool isRAW, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe)
|
||||
{
|
||||
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
@ -192,7 +192,7 @@ namespace rtengine {
|
||||
//now we have tile dimensions, overlaps
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
//adding omp here slows it down
|
||||
//adding omp here slows it down
|
||||
for (int tiletop=0; tiletop<imheight; tiletop+=tileHskip) {
|
||||
for (int tileleft=0; tileleft<imwidth; tileleft+=tileWskip) {
|
||||
|
||||
@ -210,19 +210,20 @@ namespace rtengine {
|
||||
//pixel weight
|
||||
array2D<float> totwt(width,height,ARRAY2D_CLEAR_DATA);//weight for combining DCT blocks
|
||||
|
||||
//#ifdef _OPENMP
|
||||
//#pragma omp parallel for
|
||||
//#endif
|
||||
//TODO: implement using AlignedBufferMP
|
||||
//#ifdef _OPENMP
|
||||
//#pragma omp parallel for
|
||||
//#endif
|
||||
//TODO: implement using AlignedBufferMP
|
||||
//fill tile from image; convert RGB to "luma/chroma"
|
||||
if (isRAW) {//image is raw; use channel differences for chroma channels
|
||||
for (int i=tiletop/*, i1=0*/; i<tilebottom; i++/*, i1++*/) {
|
||||
int i1 = i - tiletop;
|
||||
for (int j=tileleft/*, j1=0*/; j<tileright; j++/*, j1++*/) {
|
||||
int j1 = j - tileleft;
|
||||
|
||||
float X = gain*src->r[i][j];//xyz_prophoto[0][0]*src->r[i][j] + xyz_prophoto[0][1]*src->g[i][j] + xyz_prophoto[0][2]*src->b[i][j];
|
||||
float Y = gain*src->g[i][j];//xyz_prophoto[1][0]*src->r[i][j] + xyz_prophoto[1][1]*src->g[i][j] + xyz_prophoto[1][2]*src->b[i][j];
|
||||
float Z = gain*src->b[i][j];//xyz_prophoto[2][0]*src->r[i][j] + xyz_prophoto[2][1]*src->g[i][j] + xyz_prophoto[2][2]*src->b[i][j];
|
||||
float X = gain*src->r[i][j];
|
||||
float Y = gain*src->g[i][j];
|
||||
float Z = gain*src->b[i][j];
|
||||
|
||||
X = X<65535.0f ? gamcurve[X] : (Color::gamma((double)X/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f);
|
||||
Y = Y<65535.0f ? gamcurve[Y] : (Color::gamma((double)Y/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f);
|
||||
@ -237,6 +238,37 @@ namespace rtengine {
|
||||
totwt[i1][j1] = 0;
|
||||
}
|
||||
}
|
||||
} else {//image is not raw; use Lab parametrization
|
||||
for (int i=tiletop/*, i1=0*/; i<tilebottom; i++/*, i1++*/) {
|
||||
int i1 = i - tiletop;
|
||||
for (int j=tileleft/*, j1=0*/; j<tileright; j++/*, j1++*/) {
|
||||
int j1 = j - tileleft;
|
||||
|
||||
//TODO: use embedded profile if present, instead of assuming sRGB
|
||||
float rtmp = Color::igammatab_srgb[ src->r[i][j] ];
|
||||
float gtmp = Color::igammatab_srgb[ src->g[i][j] ];
|
||||
float btmp = Color::igammatab_srgb[ src->b[i][j] ];
|
||||
|
||||
//perhaps use LCH or YCrCb ???
|
||||
float X = xyz_sRGB[0][0]*rtmp + xyz_sRGB[0][1]*gtmp + xyz_sRGB[0][2]*btmp;
|
||||
float Y = xyz_sRGB[1][0]*rtmp + xyz_sRGB[1][1]*gtmp + xyz_sRGB[1][2]*btmp;
|
||||
float Z = xyz_sRGB[2][0]*rtmp + xyz_sRGB[2][1]*gtmp + xyz_sRGB[2][2]*btmp;
|
||||
|
||||
X = X<65535.0f ? gamcurve[X] : (Color::gamma((double)X/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f);
|
||||
Y = Y<65535.0f ? gamcurve[Y] : (Color::gamma((double)Y/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f);
|
||||
Z = Z<65535.0f ? gamcurve[Z] : (Color::gamma((double)Z/65535.0, gam, gamthresh, gamslope, 1.0, 0.0)*32768.0f);
|
||||
|
||||
labdn->L[i1][j1] = Y;
|
||||
labdn->a[i1][j1] = (X-Y);
|
||||
labdn->b[i1][j1] = (Y-Z);
|
||||
|
||||
Ldetail[i1][j1] = 0;
|
||||
Lin[i1][j1] = Y;
|
||||
totwt[i1][j1] = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//initial impulse denoise
|
||||
if (dnparams.luma>0.01) {
|
||||
@ -312,8 +344,8 @@ namespace rtengine {
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
// Main detail recovery algorithm: Block loop
|
||||
//OpenMP here
|
||||
//adding omp here leads to artifacts
|
||||
//OpenMP here
|
||||
//adding omp here leads to artifacts
|
||||
for (int vblk=0; vblk<numblox_H; vblk++) {
|
||||
//printf("vblock=%d",vblk);
|
||||
int vblkmod = vblk%8;
|
||||
@ -323,10 +355,10 @@ namespace rtengine {
|
||||
float * buffer = new float [width + TS + 2*blkrad*offset];
|
||||
float * datarow = buffer+blkrad*offset;
|
||||
|
||||
//#ifdef _OPENMP
|
||||
//#pragma omp parallel for
|
||||
//#endif
|
||||
//TODO: implement using AlignedBufferMP
|
||||
//#ifdef _OPENMP
|
||||
//#pragma omp parallel for
|
||||
//#endif
|
||||
//TODO: implement using AlignedBufferMP
|
||||
for (int i=0/*, row=top*/; i<TS; i++/*, row++*/) {
|
||||
int row = top + i;
|
||||
int rr = row;
|
||||
@ -348,7 +380,7 @@ namespace rtengine {
|
||||
}//now we have a padded data row
|
||||
|
||||
//now fill this row of the blocks with Lab high pass data
|
||||
//OMP here does not add speed, better handled on the outside loop
|
||||
//OMP here does not add speed, better handled on the outside loop
|
||||
for (int hblk=0; hblk<numblox_W; hblk++) {
|
||||
int left = (hblk-blkrad)*offset;
|
||||
int indx = (hblk)*TS;//index of block in malloc
|
||||
@ -435,14 +467,15 @@ namespace rtengine {
|
||||
if (tileright<imwidth) Hmask[width-1-i] = mask;
|
||||
}
|
||||
|
||||
//convert back to RGB and write to destination array
|
||||
if (isRAW) {
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
//convert back to RGB and write to destination array
|
||||
for (int i=tiletop/* i1=0*/; i<tilebottom; i++/*, i1++*/){
|
||||
for (int i=tiletop; i<tilebottom; i++){
|
||||
int i1 = i-tiletop;
|
||||
float X,Y,Z;
|
||||
for (int j=tileleft/*, j1=0*/; j<tileright; j++/*, j1++*/) {
|
||||
for (int j=tileleft; j<tileright; j++) {
|
||||
int j1=j-tileleft;
|
||||
|
||||
Y = labdn->L[i1][j1];
|
||||
@ -453,16 +486,45 @@ namespace rtengine {
|
||||
Y = Y<32768.0f ? igamcurve[Y] : (Color::gamma((float)Y/32768.0f, igam, igamthresh, igamslope, 1.0, 0.0) * 65535.0f);
|
||||
Z = Z<32768.0f ? igamcurve[Z] : (Color::gamma((float)Z/32768.0f, igam, igamthresh, igamslope, 1.0, 0.0) * 65535.0f);
|
||||
|
||||
//Y = 65535.0f*(0.05+0.1*((float)rand()/(float)RAND_MAX));//test with random data
|
||||
|
||||
float factor = Vmask[i1]*Hmask[j1]/gain;
|
||||
|
||||
dsttmp->r[i][j] += factor*X;//prophoto_xyz[0][0]*X + prophoto_xyz[0][1]*Y + prophoto_xyz[0][2]*Z;
|
||||
dsttmp->g[i][j] += factor*Y;//prophoto_xyz[1][0]*X + prophoto_xyz[1][1]*Y + prophoto_xyz[1][2]*Z;
|
||||
dsttmp->b[i][j] += factor*Z;//prophoto_xyz[2][0]*X + prophoto_xyz[2][1]*Y + prophoto_xyz[2][2]*Z;
|
||||
dsttmp->r[i][j] += factor*X;
|
||||
dsttmp->g[i][j] += factor*Y;
|
||||
dsttmp->b[i][j] += factor*Z;
|
||||
|
||||
}
|
||||
}
|
||||
} else {
|
||||
#ifdef _OPENMP
|
||||
#pragma omp parallel for
|
||||
#endif
|
||||
for (int i=tiletop; i<tilebottom; i++){
|
||||
int i1 = i-tiletop;
|
||||
float X,Y,Z;
|
||||
for (int j=tileleft; j<tileright; j++) {
|
||||
int j1=j-tileleft;
|
||||
|
||||
Y = labdn->L[i1][j1];
|
||||
X = (labdn->a[i1][j1]) + Y;
|
||||
Z = Y - (labdn->b[i1][j1]);
|
||||
|
||||
X = X<32768.0f ? igamcurve[X] : (Color::gamma((float)X/32768.0f, igam, igamthresh, igamslope, 1.0, 0.0) * 65535.0f);
|
||||
Y = Y<32768.0f ? igamcurve[Y] : (Color::gamma((float)Y/32768.0f, igam, igamthresh, igamslope, 1.0, 0.0) * 65535.0f);
|
||||
Z = Z<32768.0f ? igamcurve[Z] : (Color::gamma((float)Z/32768.0f, igam, igamthresh, igamslope, 1.0, 0.0) * 65535.0f);
|
||||
|
||||
float factor = Vmask[i1]*Hmask[j1];
|
||||
|
||||
float rtmp = sRGB_xyz[0][0]*X + sRGB_xyz[0][1]*Y + sRGB_xyz[0][2]*Z;
|
||||
float gtmp = sRGB_xyz[1][0]*X + sRGB_xyz[1][1]*Y + sRGB_xyz[1][2]*Z;
|
||||
float btmp = sRGB_xyz[2][0]*X + sRGB_xyz[2][1]*Y + sRGB_xyz[2][2]*Z;
|
||||
|
||||
dsttmp->r[i][j] += factor*rtmp;
|
||||
dsttmp->g[i][j] += factor*gtmp;
|
||||
dsttmp->b[i][j] += factor*btmp;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
||||
@ -476,9 +538,18 @@ namespace rtengine {
|
||||
//copy denoised image to output
|
||||
memcpy (dst->data, dsttmp->data, 3*dst->width*dst->height*sizeof(float));
|
||||
|
||||
if (!isRAW) {//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] ];
|
||||
}
|
||||
}
|
||||
|
||||
delete dsttmp;
|
||||
|
||||
}//end of main RGB_denoise
|
||||
}//end of main RGB_denoise
|
||||
|
||||
|
||||
//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||
|
@ -106,7 +106,7 @@ void Crop::update (int todo) {
|
||||
|
||||
if (todo & M_LINDENOISE) {
|
||||
if (skip==1 && params.dirpyrDenoise.enabled) {
|
||||
parent->ipf.RGB_denoise(origCrop, origCrop, /*Roffset,*/ params.dirpyrDenoise, params.defringe);
|
||||
parent->ipf.RGB_denoise(origCrop, origCrop, parent->imgsrc->isRAW(), /*Roffset,*/ params.dirpyrDenoise, params.defringe);
|
||||
}
|
||||
}
|
||||
parent->imgsrc->convertColorSpace(origCrop, params.icm, params.raw);
|
||||
|
@ -107,6 +107,7 @@ class ImageSource : public InitialImage {
|
||||
|
||||
virtual ImageData* getImageData () =0;
|
||||
virtual ImageMatrices* getImageMatrices () =0;
|
||||
virtual bool isRAW() const =0;
|
||||
|
||||
virtual void setProgressListener (ProgressListener* pl) {}
|
||||
|
||||
|
@ -223,7 +223,7 @@ void ImProcCoordinator::updatePreviewImage (int todo, Crop* cropCall) {
|
||||
if (todo & M_LINDENOISE) {
|
||||
//printf("denoising!\n");
|
||||
if (scale==1 && params.dirpyrDenoise.enabled) {
|
||||
ipf.RGB_denoise(orig_prev, orig_prev, params.dirpyrDenoise, params.defringe);
|
||||
ipf.RGB_denoise(orig_prev, orig_prev, imgsrc->isRAW(), params.dirpyrDenoise, params.defringe);
|
||||
}
|
||||
ImageMatrices* imatrices = imgsrc->getImageMatrices ();
|
||||
}
|
||||
|
@ -122,7 +122,7 @@ class ImProcFunctions {
|
||||
//void RGB_InputTransf(Imagefloat * src, LabImage * dst, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe);
|
||||
//void RGB_OutputTransf(LabImage * src, Imagefloat * dst, const procparams::DirPyrDenoiseParams & dnparams);
|
||||
//void output_tile_row (float *Lbloxrow, float ** Lhipassdn, float ** tilemask, int height, int width, int top, int blkrad );
|
||||
void RGB_denoise(Imagefloat * src, Imagefloat * dst, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe);
|
||||
void RGB_denoise(Imagefloat * src, Imagefloat * dst, bool isRAW, const procparams::DirPyrDenoiseParams & dnparams, const procparams::DefringeParams & defringe);
|
||||
void RGBtile_denoise (float * fLblox, int vblproc, int hblproc, int numblox_H, int numblox_W, float noisevar_L ); //for DCT
|
||||
void RGBoutput_tile_row (float *Lbloxrow, float ** Ldetail, float ** tilemask_out, int height, int width, int top );
|
||||
//void WaveletDenoise(cplx_wavelet_decomposition &DualTreeCoeffs, float noisevar );
|
||||
|
@ -164,6 +164,8 @@ class RawImageSource : public ImageSource {
|
||||
|
||||
ImageData* getImageData () { return idata; }
|
||||
ImageMatrices* getImageMatrices () { return &imatrices; }
|
||||
bool isRAW() const { return true; }
|
||||
|
||||
void setProgressListener (ProgressListener* pl) { plistener = pl; }
|
||||
void getAutoExpHistogram (LUTu & histogram, int& histcompr);
|
||||
void getRAWHistogram (LUTu & histRedRaw, LUTu & histGreenRaw, LUTu & histBlueRaw);
|
||||
|
@ -110,7 +110,7 @@ IImage16* processImage (ProcessingJob* pjob, int& errorCode, ProgressListener* p
|
||||
// perform luma/chroma denoise
|
||||
LabImage* labView = new LabImage (fw,fh);
|
||||
if (params.dirpyrDenoise.enabled) {
|
||||
ipf.RGB_denoise(baseImg, baseImg, params.dirpyrDenoise, params.defringe);
|
||||
ipf.RGB_denoise(baseImg, baseImg, imgsrc->isRAW(), params.dirpyrDenoise, params.defringe);
|
||||
}
|
||||
imgsrc->convertColorSpace(baseImg, params.icm, params.raw);
|
||||
|
||||
|
@ -58,6 +58,8 @@ class StdImageSource : public ImageSource {
|
||||
|
||||
ImageData* getImageData () { return idata; }
|
||||
ImageMatrices* getImageMatrices () { return (ImageMatrices*)NULL; }
|
||||
bool isRAW() const { return false; }
|
||||
|
||||
void setProgressListener (ProgressListener* pl) { plistener = pl; }
|
||||
|
||||
void convertColorSpace(Imagefloat* image, ColorManagementParams cmp, RAWParams raw);// RAWParams raw will not be used for non-raw files (see imagesource.h)
|
||||
|
Loading…
x
Reference in New Issue
Block a user