Notes
![]() ![]() Notes - notes.io |
cv2.namedWindow(win_name, cv2.WINDOW_NORMAL)
cv2.resizeWindow(win_name, w, h)
cv2.imshow(win_name, img)
def calcPSF(filterSizeHW, R):
h = np.zeros(filterSizeHW, dtype=np.float32)
center_point = (filterSizeHW[1] // 2, filterSizeHW[0] // 2) # center(x,y)
cv2.circle(h, center_point, R, 255, -1, 8)
summa = np.sum(h)
output_img = h / summa
return output_img
def fftshift(PSF_img):
output_img = PSF_img.copy()
cx, cy = PSF_img.shape[1] // 2, PSF_img.shape[0] // 2
q0 = PSF_img[0:cy, 0:cx].copy()
q1 = PSF_img[0:cy, cx:].copy()
q2 = PSF_img[cy:, 0:cx].copy()
q3 = PSF_img[cy:, cx:].copy()
output_img[0:cy, 0:cx] = q3[:] # (q3 copy to q0_region)
output_img[cy:, cx:] = q0[:] # (q0 copy to q3_region)
output_img[0:cy, cx:] = q2[:] # (q2 copy to q1_region)
output_img[cy:, 0:cx] = q1[:] # (q1 copy to q2_region)
return output_img
def calcWienerFilter(PSF_img, snr):
PSF_shift_img = fftshift(PSF_img)
planes = cv2.merge([PSF_shift_img.copy(), np.zeros_like(PSF_shift_img)]) # merge to -->(H,W,2)
complexl = cv2.dft(planes)
planes = cv2.split(complexl)
planes_0 = planes[0]
denom = cv2.pow(np.abs(planes_0), 2)
denom += snr
output = cv2.divide(planes_0, denom)
return output
def filter2DFreq(img, Hw_wiener_filter):
planes = cv2.merge([img.astype(np.float32), np.zeros_like(img, dtype=np.float32)]) # merge to -->(H,W,2)
# pdb.set_trace()
complexl = cv2.dft(planes, flags=cv2.DFT_SCALE)
complexH = cv2.merge([Hw_wiener_filter, np.zeros_like(Hw_wiener_filter)])
complexlH = cv2.mulSpectrums(complexl, complexH, 0)
complexlH = cv2.idft(complexlH)
output_img = cv2.split(complexlH)[0]
return output_img
if __name__ == "__main__":
img_path = "/content/drive/MyDrive/Khuong/Computer Vision_CPV301/Image/3.jfif"
img_ori = cv2.imread(img_path, cv2.IMREAD_GRAYSCALE)
##Wiener Filter Parameters
R = 53 # circular PSF parameters
snr = 5200 # signal-to-noise ratio
while True:
img = img_ori.copy()
# It needs to process even image only
filterSizeHW = (img.shape[0] & -2), (img.shape[1] & -2)
# Hw calculation
PSF_img = calcPSF(filterSizeHW=filterSizeHW, R=R)
Hw_wiener_filter = calcWienerFilter(PSF_img, snr=1.0 / snr)
# Filtering
imgOut = filter2DFreq(img[:filterSizeHW[0], :filterSizeHW[1]], Hw_wiener_filter)
imgOut = cv2.convertScaleAbs(imgOut)
cv2.normalize(imgOut.copy(), imgOut, 0, 255, cv2.NORM_MINMAX)
cv2_imshow(imgOut)
key = cv2.waitKey()
if key == ord('r'):
R += 1
elif key == ord('R'):
R -= 1
elif key == ord('s'):
snr += 10
elif key == ord('S'):
snr -= 10
elif key == 27: # Esc
break
print("R: {}, snr: {}".format(R, snr))
cv2.destroyAllWindows()
![]() |
Notes is a web-based application for online taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000+ notes created and continuing...
With notes.io;
- * You can take a note from anywhere and any device with internet connection.
- * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
- * You can quickly share your contents without website, blog and e-mail.
- * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
- * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.
Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.
Easy: Notes.io doesn’t require installation. Just write and share note!
Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )
Free: Notes.io works for 14 years and has been free since the day it was started.
You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;
Email: [email protected]
Twitter: http://twitter.com/notesio
Instagram: http://instagram.com/notes.io
Facebook: http://facebook.com/notesio
Regards;
Notes.io Team