Skip to content

Commit

Permalink
Added image saliency handler
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkonrom committed Nov 29, 2017
1 parent 3b027d2 commit d6ea788
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 8 additions & 1 deletion python/imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from python.mainwindow import *
from python.operation import qpixmap_to_pil_image
from python.operation import image_to_qimage

from python.saliency import Saliency

class MyWin(QtWidgets.QMainWindow):
def __init__(self, parent=None):
Expand All @@ -19,6 +19,7 @@ def __init__(self, parent=None):

self.ui.boundariesButton.clicked.connect(self.get_boundaries)
self.ui.semanticSegmentationButton.clicked.connect(self.get_semantic_segmentation)
self.ui.pushButtonImageSaliency.clicked.connect(self.get_saliency)

self.ui.keepAspectRatioCheckBox.stateChanged.connect(self.ui.inputLabel.setKeepAspectRatioEnabled)
self.ui.keepAspectRatioCheckBox.stateChanged.connect(self.ui.outputLabel.setKeepAspectRatioEnabled)
Expand All @@ -43,6 +44,12 @@ def get_semantic_segmentation(self):
self.ui.outputLabel.loadPixmapData(QPixmap.fromImage(image_to_qimage(SemanticSegmentation.execute(
qpixmap_to_pil_image(self.ui.inputLabel.pixmap())))))

def get_saliency(self):
if self.ui.inputLabel.pixmap() is not None:
self.ui.outputLabel.loadPixmapData(QPixmap.fromImage(image_to_qimage(Saliency.execute(qpixmap_to_pil_image(
self.ui.inputLabel.pixmap())))))



if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
Expand Down
18 changes: 10 additions & 8 deletions python/saliency.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import cv2, sys
import numpy as np
from python.operation import Operation

from PIL import Image

class Saliency(Operation):
@staticmethod
Expand Down Expand Up @@ -64,19 +64,21 @@ def backprojection_saliency(img):

@staticmethod
def execute(input_image):
img = np.array(input_image)
img = img[:, :, ::-1].copy()
img = cv2.resize(img, (640 / 2, 480 / 2))
mask = Saliency.backprojection_saliency(img)
segmentation = img * mask[:, :, np.newaxis]
return Image.fromarray(segmentation)





"""
if __name__ == "__main__":
name = sys.argv[1].strip(".jpg")
img = cv2.imread(sys.argv[1], 1)
img = cv2.resize(img, (640 / 2, 480 / 2))
mask = backprojection_saliency(img)
segmentation = img * mask[:, :, np.newaxis]
cv2.imshow("original", img)
cv2.imshow("segmentation", segmentation)
cv2.waitKey(-1)
"""

0 comments on commit d6ea788

Please sign in to comment.