Wiener_Filtering-002.png is the original one, Wiener_Filtering-001.png the noise one and Wiener_Filtering-000.png the treated one.
Similar results as above:
fromscipy.signalimportwienerimportmatplotlib.pyplotaspltfromPILimportImageimportwarningsimg=Image.open('Wiener_Filtering-001.png').convert('L')figure,plots=plt.subplots(1,5)figure.suptitle('Comparison of multiple Wiener filter size')plot=plots[0]plot.imshow(img)plot.set_title('Original')foriinrange(1,5):warnings.filterwarnings('error')try:filtered_img=wiener(img,i)hasError=Falseexcept:warnings.resetwarnings()filtered_img=wiener(img,i)hasError=Trueplot=plots[i]plot.set_title(f'wiener(img, {i})\n({hasError=})')plot.imshow(filtered_img)plt.tight_layout()plt.show()
The error is:
/home/benjamin/.local/lib/python3.10/site-packages/scipy/signal/_signaltools.py:1659: RuntimeWarning: divide by zero encountered in divide
res *= (1 - noise / lVar)
/home/benjamin/.local/lib/python3.10/site-packages/scipy/signal/_signaltools.py:1659: RuntimeWarning: invalid value encountered in multiply
res *= (1 - noise / lVar)
fromPILimportImage,ImageChopsimportmathimportoperatorimportfunctoolsdefopenImage(filePath):returnImage.open(filePath).convert('L')im1=openImage('Wiener_Filtering-001.png')im2=openImage('Wiener_Filtering-002.png')defrmsdiff(im1,im2):"Calculate the root-mean-square difference between two images"h=ImageChops.difference(im1,im2).histogram()# calculate rmsreturnmath.sqrt(functools.reduce(operator.add,map(lambdah,i:h*(i**2),h,range(256)))/(float(im1.size[0])*im1.size[1]))print(rmsdiff(im1,im2))
Check initial CAI paper for details, also see the end of section IV. C. for details.
https://web.archive.org/web/20240320105334/https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/8-Linear-Image-Processing/Wiener_Filtering.pdf#page=5
```bash
pdfimages Wiener_Filtering.pdf -png -f 5 -l 5 Wiener_Filtering
```
Unclear how to get `Wiener_Filtering-006.png` from `Wiener_Filtering-001.png`.
```py
from scipy.signal import wiener
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
img = Image.open('Wiener_Filtering-001.png').convert('L')
filtered_img = wiener(img, (5, 5))
f, (plot1, plot2) = plt.subplots(1, 2)
plot1.imshow(img)
plot2.imshow(filtered_img)
plt.show()
```
Based on https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.wiener.html
Let us try to reproduce:
https://web.archive.org/web/20240320105334/https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/8-Linear-Image-Processing/Wiener_Filtering.pdf#page=7
```bash
pdfimages Wiener_Filtering.pdf -png -f 7 -l 7 Wiener_Filtering
```
`Wiener_Filtering-002.png` is the original one, `Wiener_Filtering-001.png` the noise one and `Wiener_Filtering-000.png` the treated one.
Similar results as above:
```py
from scipy.signal import wiener
import matplotlib.pyplot as plt
from PIL import Image
import warnings
img = Image.open('Wiener_Filtering-001.png').convert('L')
figure, plots = plt.subplots(1, 5)
figure.suptitle('Comparison of multiple Wiener filter size')
plot = plots[0]
plot.imshow(img)
plot.set_title('Original')
for i in range(1, 5):
warnings.filterwarnings('error')
try:
filtered_img = wiener(img, i)
hasError = False
except:
warnings.resetwarnings()
filtered_img = wiener(img, i)
hasError = True
plot = plots[i]
plot.set_title(f'wiener(img, {i})\n({hasError=})')
plot.imshow(filtered_img)
plt.tight_layout()
plt.show()
```
The error is:
```
/home/benjamin/.local/lib/python3.10/site-packages/scipy/signal/_signaltools.py:1659: RuntimeWarning: divide by zero encountered in divide
res *= (1 - noise / lVar)
/home/benjamin/.local/lib/python3.10/site-packages/scipy/signal/_signaltools.py:1659: RuntimeWarning: invalid value encountered in multiply
res *= (1 - noise / lVar)
```
While https://stackoverflow.com/a/41020626 looks interesting:
```py
from skimage import color, data, restoration
from scipy.signal import convolve2d
img = color.rgb2gray(data.astronaut())
psf = np.ones((5, 5)) / 25
img = convolve2d(img, psf, 'same')
img += 0.1 * img.std() * np.random.standard_normal(img.shape)
deconvolved_img = restoration.wiener(img, psf, 1100)
f, (plot1, plot2) = plt.subplots(1, 2)
plot1.imshow(img)
plot2.imshow(deconvolved_img)
plt.show()
```
with my image it does not seem to be interesting.
```py
from skimage import color, data, restoration
from scipy.signal import convolve2d
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
img = Image.open('Wiener_Filtering-001.png').convert('L')
img = np.array(img)
psf = np.ones((5, 5)) / 25
deconvolved_img = restoration.wiener(img, psf, 1100)
f, (plot1, plot2) = plt.subplots(1, 2)
plot1.imshow(img)
plot2.imshow(deconvolved_img)
plt.show()
```
I am able to correctly compute RMS thanks to [the Stack Overflow answer 11818358](https://stackoverflow.com/a/11818358).
```py
from PIL import Image, ImageChops
import math
import operator
import functools
def openImage(filePath):
return Image.open(filePath).convert('L')
im1 = openImage('Wiener_Filtering-001.png')
im2 = openImage('Wiener_Filtering-002.png')
def rmsdiff(im1, im2):
"Calculate the root-mean-square difference between two images"
h = ImageChops.difference(im1, im2).histogram()
# calculate rms
return math.sqrt(functools.reduce(operator.add,
map(lambda h, i: h*(i**2), h, range(256))
) / (float(im1.size[0]) * im1.size[1]))
print(rmsdiff(im1, im2))
```
Check initial CAI paper for details, also see the end of section IV. C. for details.
https://web.stanford.edu/class/ee368/Handouts/Lectures/Examples/8-Linear-Image-Processing/Wiener_Filtering/
It seems that thanks to #5 can deduce if denoised.
https://ipolcore.ipol.im/api/demoinfo/staticData/demoExtras/77777000278/
The image looks simpler, hence is possibly denoised.
Should try applying on an image where I added Gaussian noise and measure RMS.
With `Brightness` `127` and `Contrast` `100`, get:
Before Wiener filter:

After Wiener filter:

Taking an example image region:
Before Wiener filter:

After Wiener filter:

The image looks simpler, hence is possibly denoised.
Should try applying on an image where I added Gaussian noise and measure RMS.
fromPILimportImage,ImageChopsimportmathimportoperatorimportfunctoolsimportmatplotlib.pyplotaspltimportnumpydefopenImage(filePath):returnImage.open(filePath).convert('L')im1=openImage('Wiener_Filtering-001.png')im1Pixels=im1.load()im2=openImage('Wiener_Filtering-002.png')defrmsdiff(im1,im2):"Calculate the root-mean-square difference between two images"h=ImageChops.difference(im1,im2).histogram()# calculate rmsreturnmath.sqrt(functools.reduce(operator.add,map(lambdah,i:h*(i**2),h,range(256)))/(float(im1.size[0])*im1.size[1]))print(rmsdiff(im1,im2))Y=[]forsigma_0innumpy.arange(1,20,1):h_wImage=Image.new(MODE,(im1.size[0],im1.size[1]))h_wImagePixels=h_wImage.load()foriintqdm(range(im1.size[0])):forjinrange(im1.size[1]):h_wImagePixels[i,j]=round(h_w(im1,im1Pixels,i,j))rmsdiffValue=rmsdiff(h_wImage,im2)Y+=[rmsdiffValue]plt.plot(Y)plt.show()
```py
from PIL import Image, ImageChops
import math
import operator
import functools
import matplotlib.pyplot as plt
import numpy
def openImage(filePath):
return Image.open(filePath).convert('L')
im1 = openImage('Wiener_Filtering-001.png')
im1Pixels = im1.load()
im2 = openImage('Wiener_Filtering-002.png')
def rmsdiff(im1, im2):
"Calculate the root-mean-square difference between two images"
h = ImageChops.difference(im1, im2).histogram()
# calculate rms
return math.sqrt(functools.reduce(operator.add,
map(lambda h, i: h*(i**2), h, range(256))
) / (float(im1.size[0]) * im1.size[1]))
print(rmsdiff(im1, im2))
Y = []
for sigma_0 in numpy.arange(1, 20, 1):
h_wImage = Image.new(MODE, (im1.size[0], im1.size[1]))
h_wImagePixels = h_wImage.load()
for i in tqdm(range(im1.size[0])):
for j in range(im1.size[1]):
h_wImagePixels[i, j] = round(h_w(im1, im1Pixels, i, j))
rmsdiffValue = rmsdiff(h_wImage, im2)
Y += [rmsdiffValue]
plt.plot(Y)
plt.show()
```

Unable to reduce RMS results of denoised https://web.archive.org/web/20240320105334/https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/8-Linear-Image-Processing/Wiener_Filtering.pdf#page=7 maybe should try with other `Q` values but it would need adapting the code not to have out of bound errors.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
https://web.archive.org/web/20240320105334/https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/8-Linear-Image-Processing/Wiener_Filtering.pdf#page=5
Unclear how to get
Wiener_Filtering-006.pngfromWiener_Filtering-001.png.Based on https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.wiener.html
Let us try to reproduce:
https://web.archive.org/web/20240320105334/https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/8-Linear-Image-Processing/Wiener_Filtering.pdf#page=7
Wiener_Filtering-002.pngis the original one,Wiener_Filtering-001.pngthe noise one andWiener_Filtering-000.pngthe treated one.Similar results as above:
The error is:
While https://stackoverflow.com/a/41020626 looks interesting:
with my image it does not seem to be interesting.
I am able to correctly compute RMS thanks to the Stack Overflow answer 11818358.
Check initial CAI paper for details, also see the end of section IV. C. for details.
https://web.stanford.edu/class/ee368/Handouts/Lectures/Examples/8-Linear-Image-Processing/Wiener_Filtering/
It seems that thanks to #5 can deduce if denoised.
https://ipolcore.ipol.im/api/demoinfo/staticData/demoExtras/77777000278/
With
Brightness127andContrast100, get:Before Wiener filter:
After Wiener filter:
Taking an example image region:
Before Wiener filter:
After Wiener filter:
The image looks simpler, hence is possibly denoised.
Should try applying on an image where I added Gaussian noise and measure RMS.
Unable to reduce RMS results of denoised https://web.archive.org/web/20240320105334/https://web.stanford.edu/class/ee368/Handouts/Lectures/2014_Spring/8-Linear-Image-Processing/Wiener_Filtering.pdf#page=7 maybe should try with other
Qvalues but it would need adapting the code not to have out of bound errors.Related to Benjamin_Loison/PRNU_extraction/issues/1.