Skip to content

Commit

Permalink
Updated denoising
Browse files Browse the repository at this point in the history
  • Loading branch information
eszdman committed Dec 17, 2020
1 parent 158bbb0 commit 3aa2575
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,13 @@ public void Run() {
//Green Channel guided denoising
GLTexture outp = previousNode.WorkingTexture;

/*glProg.useProgram(R.raw.denoisebygreen);
glProg.useProgram(R.raw.denoisebygreen);
glProg.setTexture("RawBuffer",previousNode.WorkingTexture);
glProg.setTexture("GreenBuffer",basePipeline.main1);
//glProg.setVar("CfaPattern", params.cfaPattern);
GLTexture prev = previousNode.WorkingTexture;
outp = basePipeline.main2;
glProg.drawBlocks(outp);*/
glProg.drawBlocks(outp);

/*glProg.useProgram(R.raw.medianfilterhotpixel);
GLTexture t = prev;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public void Run() {

float denoiseLevel = (float) Math.sqrt((CameraFragment.mCaptureResult.get(CaptureResult.SENSOR_SENSITIVITY)) * IsoExpoSelector.getMPY() - 50.)*6400.f / (6.2f*IsoExpoSelector.getISOAnalog());
denoiseLevel += 0.25;
denoiseLevel*=(float)PhotonCamera.getSettings().noiseRstr;
float str = (float)PhotonCamera.getSettings().noiseRstr;
if(str > 1.0)
denoiseLevel*=str;
//Chroma NR
/*glProg.useProgram(R.raw.bilateralcolor);
Expand All @@ -71,17 +73,18 @@ public void Run() {
Log.d("PostNode:" + Name, "denoiseLevel:" + denoiseLevel + " iso:" + CameraFragment.mCaptureResult.get(CaptureResult.SENSOR_SENSITIVITY));
//glProg.useProgram(R.raw.nlmeans);
if (denoiseLevel > 2.0) {
glProg.useProgram(R.raw.nlmeans);
glProg.useProgram(R.raw.bilateralguide);
glProg.setVar("tpose",1,1);
glProg.setTexture("InputBuffer",previousNode.WorkingTexture);
glProg.setTexture("NoiseMap",detectblur2);
//glProg.setTexture("NoiseMap",detectblur2);
int kernelsize = (int)(denoiseLevel) + 1;
kernelsize = Math.max(kernelsize,2);
kernelsize = Math.min(kernelsize,8);
Log.d("PostNode:" + Name, "denoiseLevel:" + denoiseLevel + " windowSize:" + kernelsize);
glProg.setVar("kernel",kernelsize);
if(str > 1.f) str = 1.f;
if(denoiseLevel > 6.f)
glProg.setVar("isofactor",denoiseLevel/6.f);
glProg.setVar("isofactor",denoiseLevel*str/9.f);
else glProg.setVar("isofactor",1.f);
glProg.setVar("size",previousNode.WorkingTexture.mSize);
WorkingTexture = basePipeline.getMain();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public class CameraFragment extends Fragment implements ProcessingEventsListener
/**
* Timeout for the pre-capture sequence.
*/
private static final long PRECAPTURE_TIMEOUT_MS = 200;
private static final long PRECAPTURE_TIMEOUT_MS = 1500;
private static final String ACTIVE_FRONTCAM_ID = "ACTIVE_FRONTCAM_ID"; //key for savedInstanceState
public static CameraCharacteristics mCameraCharacteristics;
public static CaptureResult mCaptureResult;
Expand Down Expand Up @@ -1409,9 +1409,9 @@ private void captureStillPicture() {
PhotonCamera.getParameters().cameraRotation = PhotonCamera.getGravity().getCameraRotation();

//captureBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER,CaptureRequest.CONTROL_AF_TRIGGER_CANCEL);
//captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_OFF);
Log.d(TAG, "Focus:" + mFocus);
//captureBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE,mFocus);
captureBuilder.set(CaptureRequest.CONTROL_AF_MODE,CaptureRequest.CONTROL_AF_MODE_OFF);
Log.d(TAG, "Focus:" + focus);
captureBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE,focus);
captureBuilder.set(CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER, CaptureRequest.CONTROL_AE_PRECAPTURE_TRIGGER_CANCEL);
int[] stabilizationModes = CameraFragment.mCameraCharacteristics.get(CameraCharacteristics.LENS_INFO_AVAILABLE_OPTICAL_STABILIZATION);
if (stabilizationModes.length > 1) {
Expand All @@ -1437,7 +1437,7 @@ private void captureStillPicture() {

//mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
//mPreviewRequestBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, mFocus);
//rebuildPreviewBuilder();
rebuildPreviewBuilder();

IsoExpoSelector.useTripod = PhotonCamera.getSensors().getShakiness() < 2;
for (int i = 0; i < frameCount; i++) {
Expand Down
56 changes: 56 additions & 0 deletions app/src/main/res/raw/bilateralguide.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#version 300 es
precision highp float;
precision mediump sampler2D;
uniform sampler2D InputBuffer;
uniform sampler2D NoiseMap;
uniform int kernel;
uniform float isofactor;
uniform ivec2 size;
uniform ivec2 tpose;
#define M_PI 3.1415926535897932384626433832795

//#define sigma (0.05)
//const int kernel = 6;
const int window = 2;
#import interpolation
#define luminocity(x) ((((x.r+x.g+x.b)/3.0))+0.001)
/*float luminocity(vec3 color) {
return (color.r+color.g+color.b)/3.0;
}*/
#define distribute(x,dev,sigma) ((exp(-(x-dev) * (x-dev) / (2.0 * sigma * sigma)) / (sqrt(2.0 * M_PI) * sigma)))

float nlmeans(ivec2 coords) {
float processed = 0.0;
float weights = 0.0;
float noisefactor = clamp((textureBicubic(NoiseMap, vec2(coords)/vec2(size)).r)*0.55*isofactor,0.0005,1.0);
noisefactor*=noisefactor;
noisefactor*=0.6;
for(int i = -kernel; i < kernel; i++) {
for(int j = -kernel; j < kernel; j++) {
ivec2 patchCoord = coords + ivec2(i, j);
//float w = comparePatches(patchCoord, coords,0.01*0.5 + noisefactor*0.35);
float sigma = (0.01*0.5 + noisefactor*0.35);
float w = distribute(luminocity(texelFetch(InputBuffer, coords,0).rgb),
luminocity(texelFetch(InputBuffer,patchCoord,0).rgb),sigma);
w/=((2.0 * float(window) + 1.0) * (2.0 * float(window) + 1.0));
processed += w * luminocity(texelFetch(InputBuffer, patchCoord,0).rgb);
weights += w;
}
}
return processed / weights;
}

//////////////////////////////////////////////////////////////////////////////////
out vec3 Output;
uniform int yOffset;
void main() {
ivec2 xy = ivec2(gl_FragCoord.xy);
xy+=ivec2(0,yOffset);
vec3 xyz = (texelFetch(InputBuffer, xy,0).rgb)+0.001;
float br = (xyz.r+xyz.g+xyz.b)/3.0;
xyz/=br;
br = nlmeans(xy);
Output = clamp(xyz*br,0.0,1.0);
//float noisefactor = clamp(textureLinear(NoiseMap, vec2(xy)/vec2(size)).r,0.0005,0.6);
//Output = vec3(noisefactor*1.9);
}
2 changes: 1 addition & 1 deletion app/src/main/res/raw/denoisebygreen.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void main() {
break;
}
}
if((g[0]+g[1]+g[2]+g[3]+g[4])*0.9 > g[5]+g[6]+g[7]+g[8]){
if((g[0]+g[1]+g[2]+g[3]+g[4])*0.9 > g[5]+g[6]+g[7]+g[8] && right){
g[0]*=mainv;
g[5]*=sharpen;
g[6]*=sharpen;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion app/src/main/res/raw/sharpeningbilateral.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void main() {
{
for (int j=-kSize; j <= kSize; ++j)
{
cc = vec3(textureBicubic(InputBuffer, (gl_FragCoord.xy+vec2(i,j)*0.9)/vec2(insize)).rgb);
cc = vec3(textureBicubic(InputBuffer, (gl_FragCoord.xy+vec2(i,j)*1.1)/vec2(insize)).rgb);
factor = normpdf3(cc-Output, sigY)*bZ*kernel[kSize+j]*kernel[kSize+i];
Z += factor;
final_colour += factor*cc;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/default_prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<string name="pref_sharpness_seekbar_default" translatable="false">0.60</string>
<string name="pref_saturation_seekbar_default" translatable="false">1.0</string>
<string name="pref_gain_seekbar_default" translatable="false">1.0</string>
<string name="pref_noise_seekbar_default" translatable="false">1.4</string>
<string name="pref_noise_seekbar_default" translatable="false">1.0</string>
<string name="pref_compressor_seekbar_default" translatable="false">1.0</string>
<string name="pref_align_method_default" translatable="false">0</string>
<string name="pref_cfa_default_value" translatable="false">-1</string>
Expand Down
4 changes: 2 additions & 2 deletions app/version.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
#Thu Dec 17 02:57:51 MSK 2020
VERSION_BUILD=2485
#Thu Dec 17 05:05:16 MSK 2020
VERSION_BUILD=2514

0 comments on commit 3aa2575

Please sign in to comment.