Skip to content

Commit

Permalink
Saliency option added
Browse files Browse the repository at this point in the history
  • Loading branch information
nikkonrom committed Nov 29, 2017
1 parent d0a2689 commit e246d95
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 9 deletions.
24 changes: 24 additions & 0 deletions python/boundaries.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from PyQt5.QtGui import QImage
from PIL import Image
from PyQt5.QtGui import QPixmap
from matplotlib import pyplot as plt
from python.operation import *
import numpy as np
from skimage.filters import roberts, sobel, scharr, prewitt


class BoundariesOperation(Operation):
@staticmethod
def execute(input_pixmap, filter_number):
grayscale = qpixmap_to_pil_image(input_pixmap).convert('L')
if filter_number == 1:
edges = roberts(grayscale)
elif filter_number == 2:
edges = prewitt(grayscale)
elif filter_number == 3:
edges = scharr(grayscale)
elif filter_number == 4:
edges = sobel(grayscale)
array = np.uint8(plt.cm.gist_earth(edges) * 255)
output_qimage = image_to_qimage(Image.fromarray(array)).convertToFormat(QImage.Format_Grayscale8)
return QPixmap.fromImage(output_qimage)
3 changes: 3 additions & 0 deletions python/converter.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/bash
pyuic5 mainwindow.ui -o mainwindow.py

12 changes: 10 additions & 2 deletions python/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(736, 397)
MainWindow.resize(827, 488)
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("C:/Users/jeavr/Desktop/unnamed.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off)
MainWindow.setWindowIcon(icon)
Expand Down Expand Up @@ -48,6 +48,12 @@ def setupUi(self, MainWindow):
self.semanticSegmentationButton = QtWidgets.QPushButton(self.groupBox)
self.semanticSegmentationButton.setObjectName("semanticSegmentationButton")
self.verticalLayout_2.addWidget(self.semanticSegmentationButton)
self.pushButtonImageSaliency = QtWidgets.QPushButton(self.groupBox)
self.pushButtonImageSaliency.setObjectName("pushButtonImageSaliency")
self.verticalLayout_2.addWidget(self.pushButtonImageSaliency)
self.pushButtonFaceRecognition = QtWidgets.QPushButton(self.groupBox)
self.pushButtonFaceRecognition.setObjectName("pushButtonFaceRecognition")
self.verticalLayout_2.addWidget(self.pushButtonFaceRecognition)
spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
self.verticalLayout_2.addItem(spacerItem)
self.stackedWidget = QtWidgets.QStackedWidget(self.groupBox)
Expand Down Expand Up @@ -135,7 +141,7 @@ def setupUi(self, MainWindow):
self.verticalLayout.addLayout(self.horizontalLayout_2)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 736, 22))
self.menubar.setGeometry(QtCore.QRect(0, 0, 827, 22))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
Expand Down Expand Up @@ -165,6 +171,8 @@ def retranslateUi(self, MainWindow):
self.groupBox.setTitle(_translate("MainWindow", "Controlls"))
self.boundariesButton.setText(_translate("MainWindow", "Boundaries"))
self.semanticSegmentationButton.setText(_translate("MainWindow", "Semantic Segmentation"))
self.pushButtonImageSaliency.setText(_translate("MainWindow", "Saliency"))
self.pushButtonFaceRecognition.setText(_translate("MainWindow", "Face Recognition"))
self.groupBox_2.setTitle(_translate("MainWindow", "Boundaries options"))
self.radioButtonRoberts.setText(_translate("MainWindow", "Roberts filter"))
self.radioButtonPrewitt.setText(_translate("MainWindow", "Prewitt filter"))
Expand Down
20 changes: 17 additions & 3 deletions python/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>736</width>
<height>397</height>
<width>827</width>
<height>488</height>
</rect>
</property>
<property name="windowTitle">
Expand Down Expand Up @@ -70,6 +70,20 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonImageSaliency">
<property name="text">
<string>Saliency</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButtonFaceRecognition">
<property name="text">
<string>Face Recognition</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -252,7 +266,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>736</width>
<width>827</width>
<height>22</height>
</rect>
</property>
Expand Down
31 changes: 31 additions & 0 deletions python/operation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from PIL.ImageQt import ImageQt
from PyQt5.QtCore import QBuffer
from PyQt5.QtCore import QIODevice
from PyQt5.QtGui import QImage
from PIL import Image
import io


class Operation(object):
@staticmethod
def execute(input_pixmap):
return input_pixmap


def qpixmap_to_pil_image(pixmap):
image = QImage(pixmap)
buffer = QBuffer()
buffer.open(QIODevice.ReadWrite)
image.save(buffer, "PNG")

strio = io.BytesIO()
strio.write(buffer.data())
buffer.close()
strio.seek(0)
byte_img = strio.read()
data_bytes = io.BytesIO(byte_img)
return Image.open(data_bytes)


def image_to_qimage(img):
return ImageQt(img)
Loading

0 comments on commit e246d95

Please sign in to comment.