-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuv_photo_denoise.py
145 lines (97 loc) · 3.8 KB
/
uv_photo_denoise.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 20 10:37:45 2021
@author: cosmi
"""
"""
Experimental UV Absorption Index program using UV-Pass Filter on DJI Mavic 2 Pro
JPEG 16-bit combo images taken using Ultraviolet-Only Pass Filter
Useful for Batch Processing Multiple Images
%(c)-J. Campbell MuonRay Enterprises 2020
This Python script was created using the Spyder Editor
"""
from scipy import misc
import warnings
warnings.filterwarnings('ignore')
from PIL import Image
import pylab
import rof
import imageio
import numpy as np
from matplotlib import pyplot as plt # For image viewing
#!/usr/bin/python
import getopt
import sys
import matplotlib.pyplot as plt
from matplotlib import colors
from matplotlib import ticker
from matplotlib.colors import LinearSegmentedColormap
#dng reading requires libraw to work
# Open an image
image = misc.imread('DJI_0212.JPG')
# Get the red band from the rgb image, and open it as a numpy matrix
#NIR = image[:, :, 0]
#ir = np.asarray(NIR, float)
ir = (image[:,:,0]).astype('float')
# Get one of the IR image bands (all bands should be same)
#blue = image[:, :, 2]
#r = np.asarray(blue, float)
r = (image[:,:,2]).astype('float')
g = (image[:,:,1]).astype('float')
ir = (image[:,:,0]).astype('float')
denoised_g_channel = g
""" negating noise in the output green channel using
an implementation of the Rudin-Osher-Fatemi (ROF) denoising model
using the numerical procedure presented in eq (11) A. Chambolle (2005).
The ROF model has the interesting property that it finds a smoother version
of the image while preserving edges and structures.
Input: noisy input image (grayscale), initial guess for U, weight of
the TV-regularizing term, steplength, tolerance for stop criterion.
Output: denoised and detextured image, texture residual. """
U,T = rof.denoise(denoised_g_channel,denoised_g_channel)
pylab.figure()
pylab.gray()
pylab.imshow(U)
pylab.axis('equal')
pylab.axis('off')
pylab.show()
#(NIR + Green)
irg = np.add(ir, U)
L=0.5;
rplusb = np.add(ir, r)
rplusbplusg = np.add(ir, r, U)
rminusb = np.subtract(ir, r)
oneplusL = np.add(1, L)
# Create a numpy matrix of zeros to hold the calculated UVRI values for each pixel
uvri = np.zeros(r.size) # The UVRI image will be the same size as the input image
# Calculate UV Reflectance Index
uvri = np.true_divide(np.subtract(U, rminusb), np.add(U, rplusb))
# Display the results
output_name = 'UVReflectanceIndex4.jpg'
#a nice selection of grayscale colour palettes
cols1 = ['blue', 'green', 'yellow', 'red']
cols2 = ['gray', 'gray', 'red', 'yellow', 'green']
cols3 = ['gray', 'blue', 'green', 'yellow', 'red']
cols4 = ['black', 'gray', 'blue', 'green', 'yellow', 'red']
def create_colormap(args):
return LinearSegmentedColormap.from_list(name='custom1', colors=cols4)
#colour bar to match grayscale units
def create_colorbar(fig, image):
position = fig.add_axes([0.125, 0.19, 0.2, 0.05])
norm = colors.Normalize(vmin=-1., vmax=1.)
cbar = plt.colorbar(image,
cax=position,
orientation='horizontal',
norm=norm)
cbar.ax.tick_params(labelsize=6)
tick_locator = ticker.MaxNLocator(nbins=3)
cbar.locator = tick_locator
cbar.update_ticks()
cbar.set_label("UVRI", fontsize=10, x=0.5, y=0.5, labelpad=-25)
fig, ax = plt.subplots()
image = ax.imshow(uvri, cmap=create_colormap(colors))
plt.axis('off')
create_colorbar(fig, image)
extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
fig.savefig(output_name, dpi=600, transparent=True, bbox_inches=extent, pad_inches=0)
# plt.show()