-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.py
More file actions
57 lines (48 loc) · 2.13 KB
/
Main.py
File metadata and controls
57 lines (48 loc) · 2.13 KB
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
from Point import Point
from SaliencyMap import SaliencyMap
from WTA import WTA
import argparse
from numpy import imag
import numpy as np
import cv2
import copy
def run(args):
image = cv2.imread(args.image_path)
#!!! We want only 0.0-1.0 images in the saliency map or things starts to crack
# Never, ever use any other pixel-representation format than 0.0-1.0 float64
image = np.float64(image)/255
# note: Yes, this takes a lot of time. This algorithm's execution time in junkthon is a joke.
saliencyMap = SaliencyMap(image)
# saliencyMap.intensityPyramid.ShowPyramid()
# saliencyMap.colorRPyramid.ShowPyramid()
# saliencyMap.colorGPyramid.ShowPyramid()
# saliencyMap.colorBPyramid.ShowPyramid()
# saliencyMap.colorYPyramid.ShowPyramid()
# saliencyMap.orientation0Pyramid.ShowPyramid()
# saliencyMap.orientation45Pyramid.ShowPyramid()
# saliencyMap.orientation90Pyramid.ShowPyramid()
# saliencyMap.orientation135Pyramid.ShowPyramid()
# todo Here you can show other saliency map steps.
cv2.imshow('Saliency map', saliencyMap.saliencyMap)
cv2.waitKey(0)
# todo when the saliency map is ready please uncomment:
winnerCount = 10 # select how many winners do you want to have, to search for a loop just pass some insanely huge number
wta = WTA(saliencyMap.saliencyMap, blackoutRadius=200, regenerationTime=6)
winners = wta.GetWinnerPoints(6)
winners = wta.WinnerPointsToAnnotationPoints(winners)
annotatedOriginalImage = wta.AnnotateImage(
image, winners)
cv2.imshow('Annotated original image', annotatedOriginalImage)
cv2.waitKey(0)
annotatedSaliencyMap = wta.Annotate2F1Image(saliencyMap.saliencyMap, winners)
cv2.imshow('Annotated saliency map', annotatedSaliencyMap)
cv2.waitKey(0)
print("Salient points:")
for i in range(0, len(winners)):
point: Point = winners[i]
point.Print()
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--image_path', type=str, help='Path to photo from which Sailency Map will be generated', required=True)
args = parser.parse_args()
run(args)