Skip to content

Instantly share code, notes, and snippets.

@Cranked
Last active May 22, 2019 11:21
Show Gist options
  • Save Cranked/38418b58bbeeab87cf02314217e300a1 to your computer and use it in GitHub Desktop.
Save Cranked/38418b58bbeeab87cf02314217e300a1 to your computer and use it in GitHub Desktop.
Python Resim Filtreleme
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'image_processing.ui'
#
# Created by: PyQt5 UI code generator 5.5.1
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from PIL import Image,ImageFilter
class Ui_MainWindow(object):
image = Image.open("kus.jpg")
konum = 0 #hangi resimde oldugumuzu bulmak için 0'dan başlattık.
max=0 #max tanımlamamızın sebebi kaçtane oldugunu bilmek ve ileri tusuna basıldıgında gidebileceği max yeri bulabilmek
yol = "kus" #Resmimizin ismi klasörünüzün altına resimi attığınızda burayı attgınız resmin adını yazarak değiştirin.
uzanti = ".jpg"#Resminizin uzantısı
aci = 0# Resmin Açısı
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(628, 584)
MainWindow.setCursor(QtGui.QCursor(QtCore.Qt.ArrowCursor))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(0, 70, 181, 451))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setObjectName("verticalLayout")
self.pushButton_4 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_4.setObjectName("pushButton_4")
self.verticalLayout.addWidget(self.pushButton_4)
self.pushButton_8 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_8.setObjectName("pushButton_8")
self.verticalLayout.addWidget(self.pushButton_8)
self.pushButton_5 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_5.setObjectName("pushButton_5")
self.verticalLayout.addWidget(self.pushButton_5)
self.pushButton_9 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_9.setObjectName("pushButton_9")
self.verticalLayout.addWidget(self.pushButton_9)
self.pushButton_6 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_6.setObjectName("pushButton_6")
self.verticalLayout.addWidget(self.pushButton_6)
self.pushButton_13 = QtWidgets.QPushButton(self.verticalLayoutWidget)
self.pushButton_13.setObjectName("pushButton_13")
self.verticalLayout.addWidget(self.pushButton_13)
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(30, 10, 120, 40))
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("sola.jpg"))
self.pushButton.setIcon(icon)
self.pushButton.setObjectName("pushButton")
self.pushButton_14 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_14.setGeometry(QtCore.QRect(290, 10, 120, 40))
icon2 = QtGui.QIcon()
icon2.addPixmap(QtGui.QPixmap("geri.png"))
self.pushButton_14.setIcon(icon2)
self.pushButton_14.setObjectName("pushButton_14")
self.pushButton_15 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_15.setGeometry(QtCore.QRect(420, 10, 120, 40))
icon3 = QtGui.QIcon()
icon3.addPixmap(QtGui.QPixmap("ileri.png"))
self.pushButton_15.setIcon(icon3)
self.pushButton_15.setObjectName("pushButton_15")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(160, 10, 120, 40))
icon1 = QtGui.QIcon()
icon1.addPixmap(QtGui.QPixmap("saga.jpg"))
self.pushButton_2.setIcon(icon1)
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(200, 60, 411, 441))
self.label.setText("")
self.label.setScaledContents(False)
self.label.setObjectName("label")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 628, 25))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.pushButton_4.clicked.connect(self.contour)
self.pushButton_8.clicked.connect(self.edge_enhance)
self.pushButton_5.clicked.connect(self.emboss)
self.pushButton_9.clicked.connect(self.find_edges)
self.pushButton_6.clicked.connect(self.smooth)
self.pushButton_13.clicked.connect(self.siyah)
self.pushButton.clicked.connect(self.sola_dondur)
self.pushButton_2.clicked.connect(self.saga_dondur)
self.pushButton_14.clicked.connect(self.geri)
self.pushButton_15.clicked.connect(self.ileri)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def contour(self):
self.max += 1
self.konum += 1
self.image.filter(ImageFilter.CONTOUR).save(self.yol + str(self.konum) + self.uzanti)
contour_image = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
self.image = contour_image
def siyah(self):
self.konum += 1
self.max += 1
self.image.convert(mode="L").save(self.yol + str(self.konum) + self.uzanti)
siyahbeyaz = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
self.image = siyahbeyaz
def sola_dondur(self):
self.aci += 90
self.image.rotate(self.aci).save(self.yol+str(self.konum)+self.uzanti)
sola_dondurme=Image.open(self.yol+str(self.konum)+self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol+str(self.konum)+self.uzanti))
image=sola_dondurme
def geri(self):
if self.konum>=2:
self.konum -= 1
geri_alma=Image.open(self.yol+str(self.konum)+self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
image=geri_alma
self.geri_state=True
def ileri(self):
try:
if self.konum+1<self.max:
self.konum += 1
sola_dondurme=Image.open(self.yol+str(self.konum)+self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
image=sola_dondurme
except:
pass
def saga_dondur(self):
self.aci -= 90
self.image.rotate(self.aci).save(self.yol + str(self.konum) + self.uzanti)
saga_dondurme = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol+str(self.konum)+self.uzanti))
image = saga_dondurme
def smooth(self):
self.max += 1
self.konum += 1
self.image.filter(ImageFilter.SMOOTH).save(self.yol + str(self.konum) + self.uzanti)
contour_image = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
self.image = contour_image
def find_edges(self):
self.konum += 1
self.max += 1
self.image.filter(ImageFilter.FIND_EDGES).save(self.yol + str(self.konum) + self.uzanti)
contour_image = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
self.image = contour_image
def emboss(self):
self.konum += 1
self.max += 1
self.image.filter(ImageFilter.EMBOSS).save(self.yol + str(self.konum) + self.uzanti)
contour_image = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
self.image = contour_image
def edge_enhance(self):
self.konum += 1
self.max += 1
self.image.filter(ImageFilter.EDGE_ENHANCE).save(self.yol + str(self.konum) + self.uzanti)
contour_image = Image.open(self.yol + str(self.konum) + self.uzanti)
self.label.setPixmap(QtGui.QPixmap(self.yol + str(self.konum) + self.uzanti))
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "İMAGE PROCESSİNG"))
self.pushButton_4.setText(_translate("MainWindow", "Contour"))
self.pushButton_8.setText(_translate("MainWindow", "edge_enhance"))
self.pushButton_5.setText(_translate("MainWindow", "Emboss"))
self.pushButton_9.setText(_translate("MainWindow", "Fınd_edges"))
self.pushButton_6.setText(_translate("MainWindow", "Smooth"))
self.pushButton_13.setText(_translate("MainWindow", "Siyah Beyaz"))
self.pushButton_14.setText(_translate("MainWindow", "Geri Al"))
self.pushButton_15.setText(_translate("MainWindow", "İleri Al"))
self.pushButton.setText(_translate("MainWindow", "Sola Döndür"))
self.pushButton.setShortcut(_translate("MainWindow", "Left"))
self.pushButton_2.setText(_translate("MainWindow", "Sağa Döndür"))
self.pushButton_2.setShortcut(_translate("MainWindow", "Right"))
self.pushButton_14.setShortcut(_translate("MainWindow", "Ctrl+Z"))
self.pushButton_15.setShortcut(_translate("MainWindow", "Ctrl+A"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment