Skip to content

Commit 3aa2575

Browse files
committed
Updated denoising
1 parent 158bbb0 commit 3aa2575

9 files changed

Lines changed: 75 additions & 16 deletions

File tree

app/src/main/java/com/eszdman/photoncamera/processing/opengl/postpipeline/Demosaic.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,13 @@ public void Run() {
3838
//Green Channel guided denoising
3939
GLTexture outp = previousNode.WorkingTexture;
4040

41-
/*glProg.useProgram(R.raw.denoisebygreen);
41+
glProg.useProgram(R.raw.denoisebygreen);
4242
glProg.setTexture("RawBuffer",previousNode.WorkingTexture);
4343
glProg.setTexture("GreenBuffer",basePipeline.main1);
4444
//glProg.setVar("CfaPattern", params.cfaPattern);
4545
GLTexture prev = previousNode.WorkingTexture;
4646
outp = basePipeline.main2;
47-
glProg.drawBlocks(outp);*/
47+
glProg.drawBlocks(outp);
4848

4949
/*glProg.useProgram(R.raw.medianfilterhotpixel);
5050
GLTexture t = prev;

app/src/main/java/com/eszdman/photoncamera/processing/opengl/postpipeline/SmartNR.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,9 @@ public void Run() {
5656

5757
float denoiseLevel = (float) Math.sqrt((CameraFragment.mCaptureResult.get(CaptureResult.SENSOR_SENSITIVITY)) * IsoExpoSelector.getMPY() - 50.)*6400.f / (6.2f*IsoExpoSelector.getISOAnalog());
5858
denoiseLevel += 0.25;
59-
denoiseLevel*=(float)PhotonCamera.getSettings().noiseRstr;
59+
float str = (float)PhotonCamera.getSettings().noiseRstr;
60+
if(str > 1.0)
61+
denoiseLevel*=str;
6062
//Chroma NR
6163
/*glProg.useProgram(R.raw.bilateralcolor);
6264
@@ -71,17 +73,18 @@ public void Run() {
7173
Log.d("PostNode:" + Name, "denoiseLevel:" + denoiseLevel + " iso:" + CameraFragment.mCaptureResult.get(CaptureResult.SENSOR_SENSITIVITY));
7274
//glProg.useProgram(R.raw.nlmeans);
7375
if (denoiseLevel > 2.0) {
74-
glProg.useProgram(R.raw.nlmeans);
76+
glProg.useProgram(R.raw.bilateralguide);
7577
glProg.setVar("tpose",1,1);
7678
glProg.setTexture("InputBuffer",previousNode.WorkingTexture);
77-
glProg.setTexture("NoiseMap",detectblur2);
79+
//glProg.setTexture("NoiseMap",detectblur2);
7880
int kernelsize = (int)(denoiseLevel) + 1;
7981
kernelsize = Math.max(kernelsize,2);
8082
kernelsize = Math.min(kernelsize,8);
8183
Log.d("PostNode:" + Name, "denoiseLevel:" + denoiseLevel + " windowSize:" + kernelsize);
8284
glProg.setVar("kernel",kernelsize);
85+
if(str > 1.f) str = 1.f;
8386
if(denoiseLevel > 6.f)
84-
glProg.setVar("isofactor",denoiseLevel/6.f);
87+
glProg.setVar("isofactor",denoiseLevel*str/9.f);
8588
else glProg.setVar("isofactor",1.f);
8689
glProg.setVar("size",previousNode.WorkingTexture.mSize);
8790
WorkingTexture = basePipeline.getMain();

app/src/main/java/com/eszdman/photoncamera/ui/camera/CameraFragment.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public class CameraFragment extends Fragment implements ProcessingEventsListener
126126
/**
127127
* Timeout for the pre-capture sequence.
128128
*/
129-
private static final long PRECAPTURE_TIMEOUT_MS = 200;
129+
private static final long PRECAPTURE_TIMEOUT_MS = 1500;
130130
private static final String ACTIVE_FRONTCAM_ID = "ACTIVE_FRONTCAM_ID"; //key for savedInstanceState
131131
public static CameraCharacteristics mCameraCharacteristics;
132132
public static CaptureResult mCaptureResult;
@@ -1409,9 +1409,9 @@ private void captureStillPicture() {
14091409
PhotonCamera.getParameters().cameraRotation = PhotonCamera.getGravity().getCameraRotation();
14101410

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

14381438
//mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_OFF);
14391439
//mPreviewRequestBuilder.set(CaptureRequest.LENS_FOCUS_DISTANCE, mFocus);
1440-
//rebuildPreviewBuilder();
1440+
rebuildPreviewBuilder();
14411441

14421442
IsoExpoSelector.useTripod = PhotonCamera.getSensors().getShakiness() < 2;
14431443
for (int i = 0; i < frameCount; i++) {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
#version 300 es
2+
precision highp float;
3+
precision mediump sampler2D;
4+
uniform sampler2D InputBuffer;
5+
uniform sampler2D NoiseMap;
6+
uniform int kernel;
7+
uniform float isofactor;
8+
uniform ivec2 size;
9+
uniform ivec2 tpose;
10+
#define M_PI 3.1415926535897932384626433832795
11+
12+
//#define sigma (0.05)
13+
//const int kernel = 6;
14+
const int window = 2;
15+
#import interpolation
16+
#define luminocity(x) ((((x.r+x.g+x.b)/3.0))+0.001)
17+
/*float luminocity(vec3 color) {
18+
return (color.r+color.g+color.b)/3.0;
19+
}*/
20+
#define distribute(x,dev,sigma) ((exp(-(x-dev) * (x-dev) / (2.0 * sigma * sigma)) / (sqrt(2.0 * M_PI) * sigma)))
21+
22+
float nlmeans(ivec2 coords) {
23+
float processed = 0.0;
24+
float weights = 0.0;
25+
float noisefactor = clamp((textureBicubic(NoiseMap, vec2(coords)/vec2(size)).r)*0.55*isofactor,0.0005,1.0);
26+
noisefactor*=noisefactor;
27+
noisefactor*=0.6;
28+
for(int i = -kernel; i < kernel; i++) {
29+
for(int j = -kernel; j < kernel; j++) {
30+
ivec2 patchCoord = coords + ivec2(i, j);
31+
//float w = comparePatches(patchCoord, coords,0.01*0.5 + noisefactor*0.35);
32+
float sigma = (0.01*0.5 + noisefactor*0.35);
33+
float w = distribute(luminocity(texelFetch(InputBuffer, coords,0).rgb),
34+
luminocity(texelFetch(InputBuffer,patchCoord,0).rgb),sigma);
35+
w/=((2.0 * float(window) + 1.0) * (2.0 * float(window) + 1.0));
36+
processed += w * luminocity(texelFetch(InputBuffer, patchCoord,0).rgb);
37+
weights += w;
38+
}
39+
}
40+
return processed / weights;
41+
}
42+
43+
//////////////////////////////////////////////////////////////////////////////////
44+
out vec3 Output;
45+
uniform int yOffset;
46+
void main() {
47+
ivec2 xy = ivec2(gl_FragCoord.xy);
48+
xy+=ivec2(0,yOffset);
49+
vec3 xyz = (texelFetch(InputBuffer, xy,0).rgb)+0.001;
50+
float br = (xyz.r+xyz.g+xyz.b)/3.0;
51+
xyz/=br;
52+
br = nlmeans(xy);
53+
Output = clamp(xyz*br,0.0,1.0);
54+
//float noisefactor = clamp(textureLinear(NoiseMap, vec2(xy)/vec2(size)).r,0.0005,0.6);
55+
//Output = vec3(noisefactor*1.9);
56+
}

app/src/main/res/raw/denoisebygreen.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void main() {
3232
break;
3333
}
3434
}
35-
if((g[0]+g[1]+g[2]+g[3]+g[4])*0.9 > g[5]+g[6]+g[7]+g[8]){
35+
if((g[0]+g[1]+g[2]+g[3]+g[4])*0.9 > g[5]+g[6]+g[7]+g[8] && right){
3636
g[0]*=mainv;
3737
g[5]*=sharpen;
3838
g[6]*=sharpen;

app/src/main/res/raw/sharpeningbilateral.glsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() {
4242
{
4343
for (int j=-kSize; j <= kSize; ++j)
4444
{
45-
cc = vec3(textureBicubic(InputBuffer, (gl_FragCoord.xy+vec2(i,j)*0.9)/vec2(insize)).rgb);
45+
cc = vec3(textureBicubic(InputBuffer, (gl_FragCoord.xy+vec2(i,j)*1.1)/vec2(insize)).rgb);
4646
factor = normpdf3(cc-Output, sigY)*bZ*kernel[kSize+j]*kernel[kSize+i];
4747
Z += factor;
4848
final_colour += factor*cc;

app/src/main/res/values/default_prefs.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
<string name="pref_sharpness_seekbar_default" translatable="false">0.60</string>
5959
<string name="pref_saturation_seekbar_default" translatable="false">1.0</string>
6060
<string name="pref_gain_seekbar_default" translatable="false">1.0</string>
61-
<string name="pref_noise_seekbar_default" translatable="false">1.4</string>
61+
<string name="pref_noise_seekbar_default" translatable="false">1.0</string>
6262
<string name="pref_compressor_seekbar_default" translatable="false">1.0</string>
6363
<string name="pref_align_method_default" translatable="false">0</string>
6464
<string name="pref_cfa_default_value" translatable="false">-1</string>

app/version.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
#Thu Dec 17 02:57:51 MSK 2020
2-
VERSION_BUILD=2485
1+
#Thu Dec 17 05:05:16 MSK 2020
2+
VERSION_BUILD=2514

0 commit comments

Comments
 (0)