Skip to content

Commit 8f8f71b

Browse files
authored
Add files via upload
1 parent 83596e3 commit 8f8f71b

File tree

2 files changed

+280
-0
lines changed

2 files changed

+280
-0
lines changed

ndvi_denoise_batch.py

+135
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Created on Mon Sep 20 10:37:45 2021
4+
5+
@author: cosmi
6+
"""
7+
8+
"""
9+
Denoised Vegetation Index Mapping program using DJI Mavic 2 Pro
10+
JPEG 16-bit combo images taken using InfraBlue Filter
11+
%(c)-J. Campbell MuonRay Enterprises 2021
12+
% creative commons For non-profit use only
13+
This Python script was created using the Spyder Editor
14+
"""
15+
16+
import warnings
17+
warnings.filterwarnings('ignore')
18+
19+
from PIL import Image
20+
import pylab
21+
import rof
22+
23+
from scipy import misc
24+
import imageio
25+
import numpy as np
26+
from matplotlib import pyplot as plt # For image viewing
27+
28+
#!/usr/bin/python
29+
import os
30+
import getopt
31+
import sys
32+
33+
import matplotlib.pyplot as plt
34+
from matplotlib import colors
35+
from matplotlib import ticker
36+
from matplotlib.colors import LinearSegmentedColormap
37+
38+
39+
40+
#a nice selection of grayscale colour palettes
41+
cols1 = ['blue', 'green', 'yellow', 'red']
42+
cols2 = ['gray', 'gray', 'red', 'yellow', 'green']
43+
cols3 = ['gray', 'blue', 'green', 'yellow', 'red']
44+
45+
cols4 = ['black', 'gray', 'blue', 'green', 'yellow', 'red']
46+
47+
def create_colormap(args):
48+
return LinearSegmentedColormap.from_list(name='custom1', colors=cols3)
49+
50+
#colour bar to match grayscale units
51+
def create_colorbar(fig, image):
52+
position = fig.add_axes([0.125, 0.19, 0.2, 0.05])
53+
norm = colors.Normalize(vmin=-1., vmax=1.)
54+
cbar = plt.colorbar(image,
55+
cax=position,
56+
orientation='horizontal',
57+
norm=norm)
58+
cbar.ax.tick_params(labelsize=6)
59+
tick_locator = ticker.MaxNLocator(nbins=3)
60+
cbar.locator = tick_locator
61+
cbar.update_ticks()
62+
cbar.set_label("NDVI", fontsize=10, x=0.5, y=0.5, labelpad=-25)
63+
64+
65+
66+
for infile in os.listdir("./"):
67+
print( "file : " + infile)
68+
if infile[-3:] == "jpg" or infile[-3:] == "JPG" :
69+
# print "is tif or DNG (RAW)"
70+
outfile = infile[:-3] + "jpg"
71+
rgb = misc.imread(infile)
72+
73+
74+
print( "new filename : " + outfile)
75+
# Extract Red, Green and Blue channels and save as separate files
76+
77+
78+
R = rgb[:,:,0]
79+
G = rgb[:,:,1]
80+
B = rgb[:,:,2]
81+
82+
# Get the red band from the rgb image, and open it as a numpy matrix
83+
#NIR = image[:, :, 0]
84+
#ir = np.asarray(NIR, float)
85+
86+
ir = (R).astype('float')
87+
88+
# Get one of the IR image bands (all bands should be same)
89+
#blue = image[:, :, 2]
90+
91+
#r = np.asarray(blue, float)
92+
93+
r = (B).astype('float')
94+
95+
#denoise
96+
97+
denoised_ir_channel = ir
98+
99+
100+
U,T = rof.denoise(denoised_ir_channel,denoised_ir_channel)
101+
102+
#pylab.figure()
103+
#pylab.gray()
104+
#pylab.imshow(U)
105+
#pylab.axis('equal')
106+
#pylab.axis('off')
107+
#pylab.show()
108+
109+
110+
# Create a numpy matrix of zeros to hold the calculated NDVI values for each pixel
111+
# The NDVI image will be the same size as the input image
112+
113+
114+
ndvi = np.zeros(r.size)
115+
116+
# Calculate NDVI
117+
118+
119+
ndvi = np.true_divide(np.subtract(U, r), np.add(U, r))
120+
fig, ax = plt.subplots()
121+
122+
image = ax.imshow(ndvi, cmap=create_colormap(colors))
123+
plt.axis('off')
124+
#Lock or Unlock Key Bar Here for Mapping/Sampling/Showcasing:
125+
#create_colorbar(fig, image)
126+
extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
127+
#imageio.imsave(outfile, ndvi)
128+
fig.savefig(outfile, dpi=600, transparent=True, bbox_inches=extent, pad_inches=0)
129+
130+
# plt.show()
131+
132+
133+
# rgb = raw.postprocess()
134+
135+
# plt.show()

uv_photo_denoise.py

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

0 commit comments

Comments
 (0)