-
Notifications
You must be signed in to change notification settings - Fork 0
/
spectralresidualsaliency.py
38 lines (33 loc) · 1.15 KB
/
spectralresidualsaliency.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
# https://www.mathworks.com/matlabcentral/mlc-downloads/downloads/submissions/38512/versions/1/previews/CLE/saltool/SpectralR/SpectralResidualSaliency.m/index.html?access_key=
import sys
import cv2
import convolutions
import numpy as np
from matplotlib import pyplot as plt
from saliencyImage import kernel
from saliencyImage import getSaliencyFrame
def getSaliency(img):
return cv2Methode(img)
def cv2Methode(img):
saliency = cv2.saliency.StaticSaliencySpectralResidual_create()
(success, saliencyMap) = saliency.computeSaliency(img)
saliencyMap = (saliencyMap * 255).astype("uint8")
return saliencyMap
# reformed version from minerva
def residualMethode(img):
width=img.shape[0]
height=img.shape[1]
img = cv2.resize(img, (64, 64))
kernl = kernel(5)
f = np.fft.fft2(img)
logamp = np.log(np.abs(f))
phase = np.angle(f)
sr = logamp - cv2.filter2D(logamp, -1, kernl)
sm = np.abs(np.fft.ifft2(np.exp(sr + 1j*phase)))**2
msm = np.max(sm)
sm = np.asarray(sm*255/msm, dtype=np.uint8)
cv2.filter2D(sm, -1, kernl)
return sm
# method based of a paper
def residualMethode2(img):
return getSaliencyFrame(img)