OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Thu, 25 Jan 2018 08:50:49 -0600Frequential Analysis in openCVhttp://answers.opencv.org/question/167044/frequential-analysis-in-opencv/ I am going through a research paper and trying to implement it. In the paper it is saying :
That they use the isotrope Gaussian bandwidth Filter, giving a formula and then using the formula they get the frequential map.
My question being, how to apply a particular formula to the matrix image (Section 3.2), and what is the frequential map, as in what format it is?
Link for the paper : Frequential and color analysis for hair mask segmentation
PS : Its difficult for me to write the equation over here, so please bear with me.
![image description](/upfiles/1500283945158928.png) Mon, 17 Jul 2017 02:53:34 -0500http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/Answer by LBerger for <p>I am going through a research paper and trying to implement it. In the paper it is saying : </p>
<p>That they use the isotrope Gaussian bandwidth Filter, giving a formula and then using the formula they get the frequential map.</p>
<p>My question being, how to apply a particular formula to the matrix image (Section 3.2), and what is the frequential map, as in what format it is?</p>
<p>Link for the paper : Frequential and color analysis for hair mask segmentation</p>
<p>PS : Its difficult for me to write the equation over here, so please bear with me.</p>
<p><img alt="image description" src="/upfiles/1500283945158928.png"/> </p>
http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/?answer=167051#post-id-167051I understand that filter is defined in frequency domain: fourier transform of image, multiply by filter and inverse fourier transform and it gives you frequential_mask(i, j)
Python code :
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
from mpl_toolkits.mplot3d.axes3d import Axes3D
import numpy as np
import cv2 as cv
def hairFilter(fx, fy ,f0, sigma):
f = np.sqrt(fx**2+fy**2);
return np.exp(-(f0-f)**2/(sigma*sigma))
fx = np.linspace(-0.5, 0.5, 200)
print ( fx.shape )
fy = np.linspace(-0.5, 0.5, 200)
X,Y = np.meshgrid(fx, fy)
f0 = 0.1
sigma = 0.04
hf=hairFilter(X,Y,f0,sigma)
fig = plt.figure(figsize=(14,6))
fig = plt.figure(figsize=(8,6))
ax = fig.add_subplot(1, 1, 1, projection='3d')
p = ax.plot_wireframe(X, Y, hf, rstride=4, cstride=4)
plt.show()
![image description](/upfiles/15169792681195043.jpg)Mon, 17 Jul 2017 03:25:23 -0500http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/?answer=167051#post-id-167051Answer by Ivan888 for <p>I am going through a research paper and trying to implement it. In the paper it is saying : </p>
<p>That they use the isotrope Gaussian bandwidth Filter, giving a formula and then using the formula they get the frequential map.</p>
<p>My question being, how to apply a particular formula to the matrix image (Section 3.2), and what is the frequential map, as in what format it is?</p>
<p>Link for the paper : Frequential and color analysis for hair mask segmentation</p>
<p>PS : Its difficult for me to write the equation over here, so please bear with me.</p>
<p><img alt="image description" src="/upfiles/1500283945158928.png"/> </p>
http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/?answer=183219#post-id-183219Thanks LBerger!
As I understand second step is "multiply by filter"... but how to calculate appropriate convolution kernel and how to apply it in frequential domain?
Please see below code:
img = cv2.imread("sad.jpg", 0)
# fft to convert the image to freq domain
f = np.fft.fft2(img)
**# HOW TO APPLY GAUSSIAN FILTER HERE ?**
# inverse fft to get the image back
img_back = np.fft.ifft2(f)
img_back = np.abs(img_back)
plt.subplot(131), plt.imshow(img, cmap = 'gray')
plt.title('Input image'), plt.xticks([]), plt.yticks([])
plt.subplot(132), plt.imshow(img_back, cmap = 'gray')
plt.title('Image after HPF'), plt.xticks([]), plt.yticks([])
plt.subplot(133), plt.imshow(img_back)
plt.title('Final result'), plt.xticks([]), plt.yticks([])
plt.show()
Thu, 25 Jan 2018 07:01:11 -0600http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/?answer=183219#post-id-183219Comment by berak for <p>Thanks LBerger!</p>
<p>As I understand second step is "multiply by filter"... but how to calculate appropriate convolution kernel and how to apply it in frequential domain?
Please see below code:</p>
<pre><code>img = cv2.imread("sad.jpg", 0)
# fft to convert the image to freq domain
f = np.fft.fft2(img)
**# HOW TO APPLY GAUSSIAN FILTER HERE ?**
# inverse fft to get the image back
img_back = np.fft.ifft2(f)
img_back = np.abs(img_back)
plt.subplot(131), plt.imshow(img, cmap = 'gray')
plt.title('Input image'), plt.xticks([]), plt.yticks([])
plt.subplot(132), plt.imshow(img_back, cmap = 'gray')
plt.title('Image after HPF'), plt.xticks([]), plt.yticks([])
plt.subplot(133), plt.imshow(img_back)
plt.title('Final result'), plt.xticks([]), plt.yticks([])
plt.show()
</code></pre>
http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/?comment=183220#post-id-183220@ivan888 , please do not post answers here, if you have a question or comment.Thu, 25 Jan 2018 08:50:49 -0600http://answers.opencv.org/question/167044/frequential-analysis-in-opencv/?comment=183220#post-id-183220