-
Notifications
You must be signed in to change notification settings - Fork 0
/
expose_stack_denoise.py
72 lines (45 loc) · 1.79 KB
/
expose_stack_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
# -*- coding: utf-8 -*-
"""
Created on Tue Jul 20 02:27:11 2021
@author: cosmi
"""
import os, numpy
from PIL import Image
import rof
from matplotlib import pyplot as plt # For image viewing
files = os.listdir(os.getcwd())
images = [name for name in files if name[-4:] in [".jpg", ".JPG"]]
width, height = Image.open(images[0]).size
stack = numpy.zeros((height, width, 3), numpy.float)
counter = 1
#denoise source images
for image in images:
outfile = image[:-3] + "png"
print( "new filename : " + outfile)
print ("Denoising image " + str(counter))
im = numpy.array(Image.open(image).convert('L'))
U,T = rof.denoise(im,im)
fig, ax = plt.subplots()
image = ax.imshow(U, cmap='gray')
plt.axis('off')
#Lock or Unlock Key Bar Here for Mapping/Sampling/Showcasing:
#create_colorbar(fig, image)
extent = ax.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
#imageio.imsave(outfile, ndvi)
fig.savefig(outfile, dpi=600, transparent=True, bbox_inches=extent, pad_inches=0)
counter += 1
#stacking denoised images
imlist = [name for name in files if name[-4:] in [".png", ".PNG"]]
width2, height2 = Image.open(imlist[0]).size
stack = numpy.zeros((height2, width2, 3), numpy.float)
counter = 1
for pngimage in imlist:
print ("Processing image " + str(counter))
image_new = numpy.array(Image.open(pngimage), dtype = numpy.float)
stack = numpy.maximum(stack, image_new)
counter += 1
stack = numpy.array(numpy.round(stack), dtype = numpy.uint8)
output = Image.fromarray(stack, mode = "RGB")
output.save("exposure_stacked_denoised_image.jpg", "JPEG")
#convert from greyscale to colour
#color_img = cv2.cvtColor(output, cv.CV_GRAY2RGB)