first commit

master
XIE 2 years ago
commit ce2420b640

8
.idea/.gitignore vendored

@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml

@ -0,0 +1 @@
driver.py

@ -0,0 +1,35 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="DuplicatedCode" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<Languages>
<language minSize="1586" name="Python" />
</Languages>
</inspection_tool>
<inspection_tool class="PyPep8NamingInspection" enabled="true" level="WEAK WARNING" enabled_by_default="true">
<option name="ignoredErrors">
<list>
<option value="N801" />
<option value="N802" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyStubPackagesAdvertiser" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredPackages">
<list>
<option value="PyQt5-stubs==5.15.6.0" />
</list>
</option>
</inspection_tool>
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="cv2.imread" />
<option value="cv2.*" />
<option value="PyQt5.QtWidgets.clicked.connect" />
<option value="PyQt5.QtCore.Qt.SolidPattern" />
</list>
</option>
</inspection_tool>
</profile>
</component>

@ -0,0 +1,6 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (Test)" project-jdk-type="Python SDK" />
</project>

@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/数字图像处理.iml" filepath="$PROJECT_DIR$/.idea/数字图像处理.iml" />
</modules>
</component>
</project>

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$">
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.6 (Test)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

300
DIP.py

@ -0,0 +1,300 @@
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'DIP.ui'
#
# Created by: PyQt5 UI code generator 5.15.6
#
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_DigitalImageProcessing(object):
def setupUi(self, DigitalImageProcessing):
DigitalImageProcessing.setObjectName("DigitalImageProcessing")
DigitalImageProcessing.resize(975, 614)
self.centralwidget = QtWidgets.QWidget(DigitalImageProcessing)
self.centralwidget.setObjectName("centralwidget")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(30, 40, 421, 321))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(14)
self.groupBox.setFont(font)
self.groupBox.setObjectName("groupBox")
self.original_img = QtWidgets.QLabel(self.groupBox)
self.original_img.setGeometry(QtCore.QRect(40, 30, 351, 261))
self.original_img.setStyleSheet("background : rgb(0, 170, 255)")
self.original_img.setText("")
self.original_img.setObjectName("original_img")
self.groupBox_2 = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox_2.setGeometry(QtCore.QRect(520, 40, 411, 321))
font = QtGui.QFont()
font.setFamily("Agency FB")
font.setPointSize(14)
self.groupBox_2.setFont(font)
self.groupBox_2.setObjectName("groupBox_2")
self.fixed_img = QtWidgets.QLabel(self.groupBox_2)
self.fixed_img.setGeometry(QtCore.QRect(30, 30, 361, 261))
self.fixed_img.setStyleSheet("background : rgb(0, 170, 255)")
self.fixed_img.setText("")
self.fixed_img.setObjectName("fixed_img")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(390, 410, 191, 91))
self.pushButton.setObjectName("pushButton")
DigitalImageProcessing.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(DigitalImageProcessing)
self.menubar.setGeometry(QtCore.QRect(0, 0, 975, 21))
self.menubar.setObjectName("menubar")
self.menu = QtWidgets.QMenu(self.menubar)
self.menu.setObjectName("menu")
self.menu_2 = QtWidgets.QMenu(self.menubar)
self.menu_2.setObjectName("menu_2")
self.menu_3 = QtWidgets.QMenu(self.menubar)
self.menu_3.setObjectName("menu_3")
self.menu_Hough = QtWidgets.QMenu(self.menubar)
self.menu_Hough.setObjectName("menu_Hough")
self.menu_4 = QtWidgets.QMenu(self.menubar)
self.menu_4.setObjectName("menu_4")
self.menu_5 = QtWidgets.QMenu(self.menubar)
self.menu_5.setObjectName("menu_5")
self.menu_6 = QtWidgets.QMenu(self.menubar)
self.menu_6.setObjectName("menu_6")
self.menu_7 = QtWidgets.QMenu(self.menubar)
self.menu_7.setObjectName("menu_7")
self.menu_8 = QtWidgets.QMenu(self.menubar)
self.menu_8.setObjectName("menu_8")
DigitalImageProcessing.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(DigitalImageProcessing)
self.statusbar.setObjectName("statusbar")
DigitalImageProcessing.setStatusBar(self.statusbar)
self.actionyu = QtWidgets.QAction(DigitalImageProcessing)
self.actionyu.setObjectName("actionyu")
self.actionhuo = QtWidgets.QAction(DigitalImageProcessing)
self.actionhuo.setObjectName("actionhuo")
self.actionfei = QtWidgets.QAction(DigitalImageProcessing)
self.actionfei.setObjectName("actionfei")
self.actionjiafa = QtWidgets.QAction(DigitalImageProcessing)
self.actionjiafa.setObjectName("actionjiafa")
self.actionjianfa = QtWidgets.QAction(DigitalImageProcessing)
self.actionjianfa.setObjectName("actionjianfa")
self.actionchengfa = QtWidgets.QAction(DigitalImageProcessing)
self.actionchengfa.setObjectName("actionchengfa")
self.actionchufa = QtWidgets.QAction(DigitalImageProcessing)
self.actionchufa.setObjectName("actionchufa")
self.actionkuozhansuofang = QtWidgets.QAction(DigitalImageProcessing)
self.actionkuozhansuofang.setObjectName("actionkuozhansuofang")
self.actiontuxiangpingyi = QtWidgets.QAction(DigitalImageProcessing)
self.actiontuxiangpingyi.setObjectName("actiontuxiangpingyi")
self.actiontuxiangxuanzhuan = QtWidgets.QAction(DigitalImageProcessing)
self.actiontuxiangxuanzhuan.setObjectName("actiontuxiangxuanzhuan")
self.actiontuxiangfanzhuan = QtWidgets.QAction(DigitalImageProcessing)
self.actiontuxiangfanzhuan.setObjectName("actiontuxiangfanzhuan")
self.actionchuizhifanzhuan = QtWidgets.QAction(DigitalImageProcessing)
self.actionchuizhifanzhuan.setObjectName("actionchuizhifanzhuan")
self.actionhuiduzhifangtu = QtWidgets.QAction(DigitalImageProcessing)
self.actionhuiduzhifangtu.setObjectName("actionhuiduzhifangtu")
self.actioncaisezhifangtu = QtWidgets.QAction(DigitalImageProcessing)
self.actioncaisezhifangtu.setObjectName("actioncaisezhifangtu")
self.actionhuizhizhifangtu = QtWidgets.QAction(DigitalImageProcessing)
self.actionhuizhizhifangtu.setObjectName("actionhuizhizhifangtu")
self.actionfenduanxianxingbianhuanduizhifangtuxiugai = QtWidgets.QAction(DigitalImageProcessing)
self.actionfenduanxianxingbianhuanduizhifangtuxiugai.setObjectName("actionfenduanxianxingbianhuanduizhifangtuxiugai")
self.actionbianyuanjiancedejibenyuanli = QtWidgets.QAction(DigitalImageProcessing)
self.actionbianyuanjiancedejibenyuanli.setObjectName("actionbianyuanjiancedejibenyuanli")
self.actionRoberts = QtWidgets.QAction(DigitalImageProcessing)
self.actionRoberts.setObjectName("actionRoberts")
self.actionPrewitt_Sobel = QtWidgets.QAction(DigitalImageProcessing)
self.actionPrewitt_Sobel.setObjectName("actionPrewitt_Sobel")
self.actionLaplacian = QtWidgets.QAction(DigitalImageProcessing)
self.actionLaplacian.setObjectName("actionLaplacian")
self.actionLoG = QtWidgets.QAction(DigitalImageProcessing)
self.actionLoG.setObjectName("actionLoG")
self.actionCanny = QtWidgets.QAction(DigitalImageProcessing)
self.actionCanny.setObjectName("actionCanny")
self.actionxingtaixue = QtWidgets.QAction(DigitalImageProcessing)
self.actionxingtaixue.setObjectName("actionxingtaixue")
self.actionjiegouyuan = QtWidgets.QAction(DigitalImageProcessing)
self.actionjiegouyuan.setText("")
self.actionjiegouyuan.setObjectName("actionjiegouyuan")
self.actionjiegouyuandefenlei = QtWidgets.QAction(DigitalImageProcessing)
self.actionjiegouyuandefenlei.setObjectName("actionjiegouyuandefenlei")
self.actionfushi = QtWidgets.QAction(DigitalImageProcessing)
self.actionfushi.setObjectName("actionfushi")
self.actionpengzhang = QtWidgets.QAction(DigitalImageProcessing)
self.actionpengzhang.setObjectName("actionpengzhang")
self.actionkaiyunsuan = QtWidgets.QAction(DigitalImageProcessing)
self.actionkaiyunsuan.setObjectName("actionkaiyunsuan")
self.actionbiyunsuan = QtWidgets.QAction(DigitalImageProcessing)
self.actionbiyunsuan.setObjectName("actionbiyunsuan")
self.actionzao_sheng_miaoshuqi = QtWidgets.QAction(DigitalImageProcessing)
self.actionzao_sheng_miaoshuqi.setObjectName("actionzao_sheng_miaoshuqi")
self.actionjunzhileilvboqi = QtWidgets.QAction(DigitalImageProcessing)
self.actionjunzhileilvboqi.setObjectName("actionjunzhileilvboqi")
self.actionpaixutongjileilvboqi = QtWidgets.QAction(DigitalImageProcessing)
self.actionpaixutongjileilvboqi.setObjectName("actionpaixutongjileilvboqi")
self.actionxuanzexinglvboqi = QtWidgets.QAction(DigitalImageProcessing)
self.actionxuanzexinglvboqi.setObjectName("actionxuanzexinglvboqi")
self.actionfangshebianhuan = QtWidgets.QAction(DigitalImageProcessing)
self.actionfangshebianhuan.setObjectName("actionfangshebianhuan")
self.actionHough = QtWidgets.QAction(DigitalImageProcessing)
self.actionHough.setObjectName("actionHough")
self.actionHoughP = QtWidgets.QAction(DigitalImageProcessing)
self.actionHoughP.setObjectName("actionHoughP")
self.actionlingyupingjunfa = QtWidgets.QAction(DigitalImageProcessing)
self.actionlingyupingjunfa.setObjectName("actionlingyupingjunfa")
self.actionzhongzhilvbo = QtWidgets.QAction(DigitalImageProcessing)
self.actionzhongzhilvbo.setObjectName("actionzhongzhilvbo")
self.actionlixiang = QtWidgets.QAction(DigitalImageProcessing)
self.actionlixiang.setObjectName("actionlixiang")
self.actionButterworth = QtWidgets.QAction(DigitalImageProcessing)
self.actionButterworth.setObjectName("actionButterworth")
self.actionGauss = QtWidgets.QAction(DigitalImageProcessing)
self.actionGauss.setObjectName("actionGauss")
self.menu.addAction(self.actionyu)
self.menu.addAction(self.actionhuo)
self.menu.addAction(self.actionfei)
self.menu.addAction(self.actionjiafa)
self.menu.addAction(self.actionjianfa)
self.menu.addAction(self.actionchengfa)
self.menu.addAction(self.actionchufa)
self.menu_2.addAction(self.actionkuozhansuofang)
self.menu_2.addAction(self.actiontuxiangpingyi)
self.menu_2.addAction(self.actiontuxiangxuanzhuan)
self.menu_2.addAction(self.actiontuxiangfanzhuan)
self.menu_2.addAction(self.actionchuizhifanzhuan)
self.menu_2.addAction(self.actionfangshebianhuan)
self.menu_3.addAction(self.actionhuiduzhifangtu)
self.menu_3.addAction(self.actioncaisezhifangtu)
self.menu_3.addAction(self.actionhuizhizhifangtu)
self.menu_3.addAction(self.actionfenduanxianxingbianhuanduizhifangtuxiugai)
self.menu_Hough.addAction(self.actionHough)
self.menu_Hough.addAction(self.actionHoughP)
self.menu_4.addAction(self.actionbianyuanjiancedejibenyuanli)
self.menu_4.addAction(self.actionRoberts)
self.menu_4.addAction(self.actionPrewitt_Sobel)
self.menu_4.addAction(self.actionLaplacian)
self.menu_4.addAction(self.actionLoG)
self.menu_4.addAction(self.actionCanny)
self.menu_5.addAction(self.actionfushi)
self.menu_5.addAction(self.actionpengzhang)
self.menu_5.addAction(self.actionkaiyunsuan)
self.menu_5.addAction(self.actionbiyunsuan)
self.menu_6.addAction(self.actionzao_sheng_miaoshuqi)
self.menu_6.addAction(self.actionjunzhileilvboqi)
self.menu_6.addAction(self.actionpaixutongjileilvboqi)
self.menu_6.addAction(self.actionxuanzexinglvboqi)
self.menu_7.addAction(self.actionlingyupingjunfa)
self.menu_7.addAction(self.actionzhongzhilvbo)
self.menu_8.addAction(self.actionlixiang)
self.menu_8.addAction(self.actionButterworth)
self.menu_8.addAction(self.actionGauss)
self.menubar.addAction(self.menu.menuAction())
self.menubar.addAction(self.menu_2.menuAction())
self.menubar.addAction(self.menu_3.menuAction())
self.menubar.addAction(self.menu_Hough.menuAction())
self.menubar.addAction(self.menu_4.menuAction())
self.menubar.addAction(self.menu_5.menuAction())
self.menubar.addAction(self.menu_6.menuAction())
self.menubar.addAction(self.menu_7.menuAction())
self.menubar.addAction(self.menu_8.menuAction())
self.retranslateUi(DigitalImageProcessing)
self.pushButton.clicked.connect(DigitalImageProcessing.openImg)
self.actionyu.triggered.connect(DigitalImageProcessing.alAnd)
self.actionhuo.triggered.connect(DigitalImageProcessing.alOr)
self.actionfei.triggered.connect(DigitalImageProcessing.alNegation)
self.actionjiafa.triggered.connect(DigitalImageProcessing.alAdd)
self.actionjianfa.triggered.connect(DigitalImageProcessing.alSubtract)
self.actionchengfa.triggered.connect(DigitalImageProcessing.alMulty)
self.actionchufa.triggered.connect(DigitalImageProcessing.alDivide)
self.actiontuxiangfanzhuan.triggered.connect(DigitalImageProcessing.horizonal)
self.actionchuizhifanzhuan.triggered.connect(DigitalImageProcessing.vertical)
self.actiontuxiangpingyi.triggered.connect(DigitalImageProcessing.moveImg)
self.actiontuxiangxuanzhuan.triggered.connect(DigitalImageProcessing.rotation)
self.actionkuozhansuofang.triggered.connect(DigitalImageProcessing.extend)
self.actionfangshebianhuan.triggered.connect(DigitalImageProcessing.affine)
self.actionhuiduzhifangtu.triggered.connect(DigitalImageProcessing.histGrey)
self.actioncaisezhifangtu.triggered.connect(DigitalImageProcessing.histRGB)
self.actionhuizhizhifangtu.triggered.connect(DigitalImageProcessing.histD)
self.actionfenduanxianxingbianhuanduizhifangtuxiugai.triggered.connect(DigitalImageProcessing.editHist)
self.actionHough.triggered.connect(DigitalImageProcessing.houghLines)
self.actionHoughP.triggered.connect(DigitalImageProcessing.houghLinesP)
self.actionbianyuanjiancedejibenyuanli.triggered.connect(DigitalImageProcessing.basic_of_edge_detection)
self.actionRoberts.triggered.connect(DigitalImageProcessing.roberts)
self.actionPrewitt_Sobel.triggered.connect(DigitalImageProcessing.sobel)
self.actionLaplacian.triggered.connect(DigitalImageProcessing.laplacian)
self.actionLoG.triggered.connect(DigitalImageProcessing.LoG)
self.actionCanny.triggered.connect(DigitalImageProcessing.canny)
self.actionfushi.triggered.connect(DigitalImageProcessing.corrode)
self.actionpengzhang.triggered.connect(DigitalImageProcessing.dilation)
self.actionkaiyunsuan.triggered.connect(DigitalImageProcessing.open)
self.actionbiyunsuan.triggered.connect(DigitalImageProcessing.close)
self.actionzao_sheng_miaoshuqi.triggered.connect(DigitalImageProcessing.describe)
self.actionjunzhileilvboqi.triggered.connect(DigitalImageProcessing.meanFilter)
self.actionpaixutongjileilvboqi.triggered.connect(DigitalImageProcessing.sortFilter)
self.actionxuanzexinglvboqi.triggered.connect(DigitalImageProcessing.selectiveFilter)
self.actionlingyupingjunfa.triggered.connect(DigitalImageProcessing.avg_blur)
self.actionzhongzhilvbo.triggered.connect(DigitalImageProcessing.mid_blur)
self.actionlixiang.triggered.connect(DigitalImageProcessing.low_pass)
self.actionButterworth.triggered.connect(DigitalImageProcessing.butterworth)
self.actionGauss.triggered.connect(DigitalImageProcessing.gauss)
QtCore.QMetaObject.connectSlotsByName(DigitalImageProcessing)
def retranslateUi(self, DigitalImageProcessing):
_translate = QtCore.QCoreApplication.translate
DigitalImageProcessing.setWindowTitle(_translate("DigitalImageProcessing", "数字图像处理"))
self.groupBox.setTitle(_translate("DigitalImageProcessing", "原始图片"))
self.groupBox_2.setTitle(_translate("DigitalImageProcessing", "修改后图片"))
self.pushButton.setText(_translate("DigitalImageProcessing", "打开图片"))
self.menu.setTitle(_translate("DigitalImageProcessing", "数字图像的计算"))
self.menu_2.setTitle(_translate("DigitalImageProcessing", "数字图像的几何变换"))
self.menu_3.setTitle(_translate("DigitalImageProcessing", "数字图像直方图"))
self.menu_Hough.setTitle(_translate("DigitalImageProcessing", "使用Hough变换实现线条变换检测"))
self.menu_4.setTitle(_translate("DigitalImageProcessing", "边缘检测"))
self.menu_5.setTitle(_translate("DigitalImageProcessing", "数字图像形态学"))
self.menu_6.setTitle(_translate("DigitalImageProcessing", "噪声滤除"))
self.menu_7.setTitle(_translate("DigitalImageProcessing", "空域的平滑"))
self.menu_8.setTitle(_translate("DigitalImageProcessing", "频域的平滑"))
self.actionyu.setText(_translate("DigitalImageProcessing", "与运算"))
self.actionhuo.setText(_translate("DigitalImageProcessing", "或运算"))
self.actionfei.setText(_translate("DigitalImageProcessing", "非运算"))
self.actionjiafa.setText(_translate("DigitalImageProcessing", "加法运算"))
self.actionjianfa.setText(_translate("DigitalImageProcessing", "减法运算"))
self.actionchengfa.setText(_translate("DigitalImageProcessing", "乘法运算"))
self.actionchufa.setText(_translate("DigitalImageProcessing", "除法运算"))
self.actionkuozhansuofang.setText(_translate("DigitalImageProcessing", "扩展缩放"))
self.actiontuxiangpingyi.setText(_translate("DigitalImageProcessing", "图像平移"))
self.actiontuxiangxuanzhuan.setText(_translate("DigitalImageProcessing", "图像旋转"))
self.actiontuxiangfanzhuan.setText(_translate("DigitalImageProcessing", "图像水平翻转"))
self.actionchuizhifanzhuan.setText(_translate("DigitalImageProcessing", "图像垂直翻转"))
self.actionhuiduzhifangtu.setText(_translate("DigitalImageProcessing", "灰度直方图"))
self.actioncaisezhifangtu.setText(_translate("DigitalImageProcessing", "彩色直方图"))
self.actionhuizhizhifangtu.setText(_translate("DigitalImageProcessing", "绘制直方图"))
self.actionfenduanxianxingbianhuanduizhifangtuxiugai.setText(_translate("DigitalImageProcessing", "分段线性变换对直方图修改"))
self.actionbianyuanjiancedejibenyuanli.setText(_translate("DigitalImageProcessing", "边缘检测的基本原理与图像增强"))
self.actionRoberts.setText(_translate("DigitalImageProcessing", "Roberts"))
self.actionPrewitt_Sobel.setText(_translate("DigitalImageProcessing", "Prewitt & Sobel"))
self.actionLaplacian.setText(_translate("DigitalImageProcessing", "Laplacian"))
self.actionLoG.setText(_translate("DigitalImageProcessing", "LoG"))
self.actionCanny.setText(_translate("DigitalImageProcessing", "Canny"))
self.actionxingtaixue.setText(_translate("DigitalImageProcessing", "图像形态学操作"))
self.actionjiegouyuandefenlei.setText(_translate("DigitalImageProcessing", "jiegouyuandefenlei"))
self.actionfushi.setText(_translate("DigitalImageProcessing", "腐蚀"))
self.actionpengzhang.setText(_translate("DigitalImageProcessing", "膨胀"))
self.actionkaiyunsuan.setText(_translate("DigitalImageProcessing", "开运算"))
self.actionbiyunsuan.setText(_translate("DigitalImageProcessing", "闭运算"))
self.actionzao_sheng_miaoshuqi.setText(_translate("DigitalImageProcessing", "噪声描述器"))
self.actionjunzhileilvboqi.setText(_translate("DigitalImageProcessing", "均值滤波器"))
self.actionpaixutongjileilvboqi.setText(_translate("DigitalImageProcessing", "排序统计类滤波器"))
self.actionxuanzexinglvboqi.setText(_translate("DigitalImageProcessing", "选择性滤波器"))
self.actionfangshebianhuan.setText(_translate("DigitalImageProcessing", "仿射变换"))
self.actionHough.setText(_translate("DigitalImageProcessing", "使用Hough变换实现线条变化检测"))
self.actionHoughP.setText(_translate("DigitalImageProcessing", "HoughP"))
self.actionlingyupingjunfa.setText(_translate("DigitalImageProcessing", "邻域平均法"))
self.actionzhongzhilvbo.setText(_translate("DigitalImageProcessing", "中值滤波法"))
self.actionlixiang.setText(_translate("DigitalImageProcessing", "理想低通滤波"))
self.actionButterworth.setText(_translate("DigitalImageProcessing", "巴特沃斯低通滤波"))
self.actionGauss.setText(_translate("DigitalImageProcessing", "高斯低通滤波"))

412
DIP.ui

@ -0,0 +1,412 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>DigitalImageProcessing</class>
<widget class="QMainWindow" name="DigitalImageProcessing">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>975</width>
<height>614</height>
</rect>
</property>
<property name="windowTitle">
<string>数字图像处理</string>
</property>
<widget class="QWidget" name="centralwidget">
<widget class="QGroupBox" name="groupBox">
<property name="geometry">
<rect>
<x>30</x>
<y>40</y>
<width>421</width>
<height>321</height>
</rect>
</property>
<property name="font">
<font>
<family>Agency FB</family>
<pointsize>14</pointsize>
</font>
</property>
<property name="title">
<string>原始图片</string>
</property>
<widget class="QLabel" name="original_img">
<property name="geometry">
<rect>
<x>40</x>
<y>30</y>
<width>351</width>
<height>261</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background : rgb(0, 170, 255)</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QGroupBox" name="groupBox_2">
<property name="geometry">
<rect>
<x>520</x>
<y>40</y>
<width>411</width>
<height>321</height>
</rect>
</property>
<property name="font">
<font>
<family>Agency FB</family>
<pointsize>14</pointsize>
</font>
</property>
<property name="title">
<string>修改后图片</string>
</property>
<widget class="QLabel" name="fixed_img">
<property name="geometry">
<rect>
<x>30</x>
<y>30</y>
<width>361</width>
<height>261</height>
</rect>
</property>
<property name="styleSheet">
<string notr="true">background : rgb(0, 170, 255)</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</widget>
<widget class="QPushButton" name="pushButton">
<property name="geometry">
<rect>
<x>390</x>
<y>410</y>
<width>191</width>
<height>91</height>
</rect>
</property>
<property name="text">
<string>打开图片</string>
</property>
</widget>
</widget>
<widget class="QMenuBar" name="menubar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>975</width>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menu">
<property name="title">
<string>数字图像的计算</string>
</property>
<addaction name="actionyu"/>
<addaction name="actionhuo"/>
<addaction name="actionfei"/>
<addaction name="actionjiafa"/>
<addaction name="actionjianfa"/>
<addaction name="actionchengfa"/>
<addaction name="actionchufa"/>
</widget>
<widget class="QMenu" name="menu_2">
<property name="title">
<string>数字图像的几何变换</string>
</property>
<addaction name="actionkuozhansuofang"/>
<addaction name="actiontuxiangpingyi"/>
<addaction name="actiontuxiangxuanzhuan"/>
<addaction name="actiontuxiangfanzhuan"/>
<addaction name="actionchuizhifanzhuan"/>
<addaction name="actionfangshebianhuan"/>
</widget>
<widget class="QMenu" name="menu_3">
<property name="title">
<string>数字图像直方图</string>
</property>
<addaction name="actionhuiduzhifangtu"/>
<addaction name="actioncaisezhifangtu"/>
<addaction name="actionhuizhizhifangtu"/>
<addaction name="actionfenduanxianxingbianhuanduizhifangtuxiugai"/>
</widget>
<widget class="QMenu" name="menu_Hough">
<property name="title">
<string>使用Hough变换实现线条变换检测</string>
</property>
<addaction name="actionHough"/>
<addaction name="actionHoughP"/>
</widget>
<widget class="QMenu" name="menu_4">
<property name="title">
<string>边缘检测</string>
</property>
<addaction name="actionbianyuanjiancedejibenyuanli"/>
<addaction name="actionRoberts"/>
<addaction name="actionPrewitt_Sobel"/>
<addaction name="actionLaplacian"/>
<addaction name="actionLoG"/>
<addaction name="actionCanny"/>
</widget>
<widget class="QMenu" name="menu_5">
<property name="title">
<string>数字图像形态学</string>
</property>
<addaction name="actionfushi"/>
<addaction name="actionpengzhang"/>
<addaction name="actionkaiyunsuan"/>
<addaction name="actionbiyunsuan"/>
</widget>
<widget class="QMenu" name="menu_6">
<property name="title">
<string>噪声滤除</string>
</property>
<addaction name="actionzao_sheng_miaoshuqi"/>
<addaction name="actionjunzhileilvboqi"/>
<addaction name="actionpaixutongjileilvboqi"/>
<addaction name="actionxuanzexinglvboqi"/>
</widget>
<widget class="QMenu" name="menu_7">
<property name="title">
<string>空域的平滑</string>
</property>
<addaction name="actionlingyupingjunfa"/>
<addaction name="actionzhongzhilvbo"/>
</widget>
<widget class="QMenu" name="menu_8">
<property name="title">
<string>频域的平滑</string>
</property>
<addaction name="actionlixiang"/>
<addaction name="actionButterworth"/>
<addaction name="actionGauss"/>
</widget>
<addaction name="menu"/>
<addaction name="menu_2"/>
<addaction name="menu_3"/>
<addaction name="menu_Hough"/>
<addaction name="menu_4"/>
<addaction name="menu_5"/>
<addaction name="menu_6"/>
<addaction name="menu_7"/>
<addaction name="menu_8"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionyu">
<property name="text">
<string>与运算</string>
</property>
</action>
<action name="actionhuo">
<property name="text">
<string>或运算</string>
</property>
</action>
<action name="actionfei">
<property name="text">
<string>非运算</string>
</property>
</action>
<action name="actionjiafa">
<property name="text">
<string>加法运算</string>
</property>
</action>
<action name="actionjianfa">
<property name="text">
<string>减法运算</string>
</property>
</action>
<action name="actionchengfa">
<property name="text">
<string>乘法运算</string>
</property>
</action>
<action name="actionchufa">
<property name="text">
<string>除法运算</string>
</property>
</action>
<action name="actionkuozhansuofang">
<property name="text">
<string>扩展缩放</string>
</property>
</action>
<action name="actiontuxiangpingyi">
<property name="text">
<string>图像平移</string>
</property>
</action>
<action name="actiontuxiangxuanzhuan">
<property name="text">
<string>图像旋转</string>
</property>
</action>
<action name="actiontuxiangfanzhuan">
<property name="text">
<string>图像水平翻转</string>
</property>
</action>
<action name="actionchuizhifanzhuan">
<property name="text">
<string>图像垂直翻转</string>
</property>
</action>
<action name="actionhuiduzhifangtu">
<property name="text">
<string>灰度直方图</string>
</property>
</action>
<action name="actioncaisezhifangtu">
<property name="text">
<string>彩色直方图</string>
</property>
</action>
<action name="actionhuizhizhifangtu">
<property name="text">
<string>绘制直方图</string>
</property>
</action>
<action name="actionfenduanxianxingbianhuanduizhifangtuxiugai">
<property name="text">
<string>分段线性变换对直方图修改</string>
</property>
</action>
<action name="actionbianyuanjiancedejibenyuanli">
<property name="text">
<string>边缘检测的基本原理与图像增强</string>
</property>
</action>
<action name="actionRoberts">
<property name="text">
<string>Roberts</string>
</property>
</action>
<action name="actionPrewitt_Sobel">
<property name="text">
<string>Prewitt &amp; Sobel</string>
</property>
</action>
<action name="actionLaplacian">
<property name="text">
<string>Laplacian</string>
</property>
</action>
<action name="actionLoG">
<property name="text">
<string>LoG</string>
</property>
</action>
<action name="actionCanny">
<property name="text">
<string>Canny</string>
</property>
</action>
<action name="actionxingtaixue">
<property name="text">
<string>图像形态学操作</string>
</property>
</action>
<action name="actionjiegouyuan">
<property name="text">
<string/>
</property>
</action>
<action name="actionjiegouyuandefenlei">
<property name="text">
<string>jiegouyuandefenlei</string>
</property>
</action>
<action name="actionfushi">
<property name="text">
<string>腐蚀</string>
</property>
</action>
<action name="actionpengzhang">
<property name="text">
<string>膨胀</string>
</property>
</action>
<action name="actionkaiyunsuan">
<property name="text">
<string>开运算</string>
</property>
</action>
<action name="actionbiyunsuan">
<property name="text">
<string>闭运算</string>
</property>
</action>
<action name="actionzao_sheng_miaoshuqi">
<property name="text">
<string>噪声描述器</string>
</property>
</action>
<action name="actionjunzhileilvboqi">
<property name="text">
<string>均值滤波器</string>
</property>
</action>
<action name="actionpaixutongjileilvboqi">
<property name="text">
<string>排序统计类滤波器</string>
</property>
</action>
<action name="actionxuanzexinglvboqi">
<property name="text">
<string>选择性滤波器</string>
</property>
</action>
<action name="actionfangshebianhuan">
<property name="text">
<string>仿射变换</string>
</property>
</action>
<action name="actionHough">
<property name="text">
<string>使用Hough变换实现线条变化检测</string>
</property>
</action>
<action name="actionHoughP">
<property name="text">
<string>HoughP</string>
</property>
</action>
<action name="actionlingyupingjunfa">
<property name="text">
<string>邻域平均法</string>
</property>
</action>
<action name="actionzhongzhilvbo">
<property name="text">
<string>中值滤波法</string>
</property>
</action>
<action name="actionlixiang">
<property name="text">
<string>理想低通滤波</string>
</property>
</action>
<action name="actionButterworth">
<property name="text">
<string>巴特沃斯低通滤波</string>
</property>
</action>
<action name="actionGauss">
<property name="text">
<string>高斯低通滤波</string>
</property>
</action>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,78 @@
import cv2
import numpy as np
class edgeDetect:
def __init__(self, imgPath):
self.path = imgPath
def graphicsEnhance(self):
img_gray = cv2.imread(self.path, 0)
h, w = img_gray.shape
gradient = np.zeros((h, w))
# 计算图像梯度
img_gray = img_gray.astype('float')
for i in range(h - 1):
for j in range(w - 1):
gx = abs(img_gray[i + 1, j] - img_gray[i, j])
gy = abs(img_gray[i, j + 1] - img_gray[i, j])
gradient[i, j] = gx + gy
# sharp为结果
sharp = img_gray + gradient
sharp = np.where(sharp > 255, 255, sharp)
sharp = np.where(sharp < 0, 0, sharp)
cv2.imwrite("saved Img/sharp.bmp", sharp)
def roberts(self):
img = cv2.imread(self.path)
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
kernelx = np.array([[-1, 0], [0, 1]], dtype=int)
kernely = np.array([[0, -1], [1, 0]], dtype=int)
x = cv2.filter2D(img, cv2.CV_16S, kernelx)
y = cv2.filter2D(img, cv2.CV_16S, kernely)
absX = cv2.convertScaleAbs(x)
absY = cv2.convertScaleAbs(y)
Roberts = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)
cv2.imwrite("saved Img/roberts.bmp", Roberts)
def sobel(self):
Sobel = cv2.imread(self.path)
Sobel = cv2.cvtColor(Sobel, cv2.COLOR_BGR2GRAY)
x = cv2.Sobel(Sobel, cv2.CV_16S, 1, 0)
y = cv2.Sobel(Sobel, cv2.CV_16S, 0, 1)
absX = cv2.convertScaleAbs(x)
absY = cv2.convertScaleAbs(y)
Sobel = cv2.addWeighted(absX, 0.5, absY, 0.5, 0)
cv2.imwrite("saved Img/sobel.bmp", Sobel)
def laplacian(self):
img = cv2.imread(self.path)
grayImage = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
dst = cv2.Laplacian(grayImage, cv2.CV_16S, ksize=3)
Laplacian = cv2.convertScaleAbs(dst)
cv2.imwrite("saved Img/laplacian.bmp", Laplacian)
def LoG(self):
img = cv2.imread(self.path)
grayImage = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
img = cv2.copyMakeBorder(grayImage, 2, 2, 2, 2, borderType=cv2.BORDER_REPLICATE)
img = cv2.GaussianBlur(img, (3, 3), 0, 0)
m1 = np.array(
[[0, 0, -1, 0, 0], [0, -1, -2, -1, 0], [-1, -2, 16, -2, -1], [0, -1, -2, -1, 0], [0, 0, -1, 0, 0]],
dtype=np.int32)
image1 = np.zeros(img.shape).astype(np.int32)
h, w, _ = img.shape
for i in range(2, h - 2):
for j in range(2, w - 2):
image1[i, j] = np.sum(m1 * img[i - 2:i + 3, j - 2:j + 3, 1])
image1 = cv2.convertScaleAbs(image1)
cv2.imwrite("saved Img/log.bmp", image1)
def canny(self):
src = cv2.imread(self.path)
blur = cv2.GaussianBlur(src, (3, 3), 0)
grayImage = cv2.cvtColor(blur, cv2.COLOR_BGR2GRAY)
gradx = cv2.Sobel(grayImage, cv2.CV_16SC1, 1, 0)
grady = cv2.Sobel(grayImage, cv2.CV_16SC1, 0, 1)
edge_output = cv2.Canny(gradx, grady, 50, 150)
cv2.imwrite("saved Img/canny.bmp", edge_output)

@ -0,0 +1,66 @@
import cv2
import numpy as np
import matplotlib.pyplot as plt
class frequency_filter:
def __init__(self, img_path):
self.path = img_path
def Ideal_low_pass_filtering_smooth(self):
img = cv2.imread(self.path)
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img = np.float32(img)
dft = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)
dft = np.fft.fftshift(dft)
rows, cols = img.shape
mask = np.zeros((rows, cols, 2), dtype=np.uint8)
mask[int(rows / 2) - 20:int(rows / 2) + 20, int(cols / 2) - 20:int(cols / 2) + 20] = 1
f = dft * mask
f = np.fft.ifftshift(f)
img = cv2.idft(f)
img = cv2.magnitude(img[:, :, 0], img[:, :, 1])
filename = "saved Img/ideal_low_pass.bmp"
plt.imsave(filename, img, cmap='gray')
def butterworth(self, D0, N):
D0 = int(D0)
N = int(N)
img = cv2.imread(self.path)
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img = np.float32(img)
dft = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)
dft = np.fft.fftshift(dft)
rows, cols = img.shape
mask = np.zeros((rows, cols, 2))
for i in range(rows):
for j in range(cols):
D = np.sqrt((i - rows / 2) ** 2 + (j - cols / 2) ** 2)
mask[i, j, 0] = mask[i, j, 1] = 1.0 / (1.0 + ((D / D0) ** (2 * N)))
f = dft * mask
f = np.fft.ifftshift(f)
img = cv2.idft(f)
img = cv2.magnitude(img[:, :, 0], img[:, :, 1])
filename = "saved Img/butterworth.bmp"
plt.imsave(filename, img, cmap='gray')
def gauss(self, D0):
D0 = int(D0)
img = cv2.imread(self.path)
img = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
img = np.float32(img)
dft = cv2.dft(img, flags=cv2.DFT_COMPLEX_OUTPUT)
dft = np.fft.fftshift(dft)
rows, cols = img.shape
crow, ccol = int(rows / 2), int(cols / 2)
mask = np.zeros((rows, cols, 2))
for i in range(rows):
for j in range(cols):
D = np.sqrt((i - crow) ** 2 + (j - ccol) ** 2)
mask[i, j, 0] = mask[i, j, 1] = np.exp(-(D * D) / (2 * D0 * D0))
f = dft * mask
f = np.fft.ifftshift(f)
img = cv2.idft(f)
img = cv2.magnitude(img[:, :, 0], img[:, :, 1])
filename = "saved Img/gauss.bmp"
plt.imsave(filename, img, cmap='gray')

@ -0,0 +1,47 @@
import cv2
import numpy as np
class GeoChange:
def __init__(self, imgPath):
self.path = imgPath
def extend(self, size):
img = cv2.imread(self.path)
img = cv2.resize(img, (0, 0), fx=size, fy=size, interpolation=cv2.INTER_LINEAR)
cv2.imwrite("saved Img/size.bmp", img)
def move(self, x, y):
img = cv2.imread(self.path)
height, width, channel = img.shape
# 构建平移矩阵
matrix = np.float32([[1, 0, x], [0, 1, y]])
img = cv2.warpAffine(img, matrix, (width, height))
cv2.imwrite("saved Img/move.bmp", img)
def horizon_flip(self):
img = cv2.imread(self.path)
horizon = cv2.flip(img, 1, dst=None)
cv2.imwrite("saved Img/horizon.bmp", horizon)
def vertical_flip(self):
img = cv2.imread(self.path)
vertical = cv2.flip(img, 0, dst=None)
cv2.imwrite("saved Img/vertical.bmp", vertical)
def rotation(self, degree):
img = cv2.imread(self.path)
rows, cols, depth = img.shape
matrix = cv2.getRotationMatrix2D((cols / 2, rows / 2), degree, 1)
img = cv2.warpAffine(img, matrix, (cols, rows))
cv2.imwrite("saved Img/rotation.bmp", img)
def affine(self):
img = cv2.imread(self.path)
img = cv2.resize(img, (256, 256))
rows, cols = img.shape[: 2]
post1 = np.float32([[50, 50], [200, 50], [50, 200]])
post2 = np.float32([[10, 100], [200, 50], [100, 250]])
M = cv2.getAffineTransform(post1, post2)
result = cv2.warpAffine(img, M, (rows, cols))
cv2.imwrite("saved Img/affine.bmp", result)

@ -0,0 +1,74 @@
import cv2
import matplotlib.pyplot as plt
import numpy as np
class Histogram:
def __init__(self, imgPath):
self.path = imgPath
def histGrey(self):
img1 = cv2.imread(self.path)
img = cv2.cvtColor(img1, cv2.COLOR_RGB2GRAY)
hist = cv2.calcHist([img], [0], None, [256], [0, 255])
plt.plot(hist)
plt.xlim([0, 255])
plt.show()
def histRGB(self):
src = cv2.imread(self.path)
color = ["r", "g", "b"]
b, g, r = cv2.split(src)
src = cv2.merge([r, g, b])
for index, c in enumerate(color):
hist = cv2.calcHist([src], [index], None, [256], [0, 255])
plt.plot(hist, color=c)
plt.xlim([0, 255])
plt.show()
def hist(self):
src = cv2.imread(self.path)
b, g, r = cv2.split(src)
src = cv2.merge([r, g, b])
histr = cv2.calcHist([src], [0], None, [256], [0, 256])
plt.plot(histr, color='r')
plt.xlim([0, 256])
histr = cv2.calcHist([src], [1], None, [256], [0, 256])
plt.plot(histr, color='g')
plt.xlim([0, 256])
histr = cv2.calcHist([src], [2], None, [256], [0, 256])
plt.plot(histr, color='b')
plt.xlim([0, 256])
plt.show()
def editHist(self):
img = cv2.imread(self.path, 0)
h, w = img.shape[:2]
out = np.zeros(img.shape, np.uint8)
for i in range(h):
for j in range(w):
pix = img[i][j]
if pix < 50:
out[i][j] = 0.5 * pix
elif pix < 150:
out[i][j] = 3.6 * pix - 310
else:
out[i][j] = 0.238 * pix + 194
out = np.around(out)
out = out.astype(np.uint8)
plt.subplot(121)
plt.imshow(img, 'gray')
plt.subplot(122)
pixelSequence = img.ravel()
numberBins = 256
histogram, bins, patch = plt.hist(pixelSequence, numberBins)
plt.axis([0, 255, 0, np.max(histogram)])
plt.show()
plt.subplot(121)
plt.imshow(out, 'gray')
plt.subplot(122)
pixelSequence = out.ravel()
numberBins = 256
histogram, bins, patch = plt.hist(pixelSequence, numberBins)
plt.axis([0, 255, 0, np.max(histogram)])
plt.show()

@ -0,0 +1,41 @@
import cv2
import numpy as np
import matplotlib.pyplot as plt
class Hough:
def __init__(self, imgPath):
self.path = imgPath
def line_change_detection(self):
img = cv2.imread(self.path)
img = cv2.GaussianBlur(img, (3, 3), 0)
edges = cv2.Canny(img, 50, 150, apertureSize=3)
lines = cv2.HoughLines(edges, 1, np.pi / 2, 118)
result = img.copy()
for i_line in lines:
for line in i_line:
rho = line[0]
theta = line[1]
if (theta < (np.pi / 4.)) or (theta > (3. * np.pi / 4.0)): # 垂直直线
pt1 = (int(rho / np.cos(theta)), 0)
pt2 = (int((rho - result.shape[0] * np.sin(theta)) / np.cos(theta)), result.shape[0])
cv2.line(result, pt1, pt2, (0, 0, 255))
else:
pt1 = (0, int(rho / np.sin(theta)))
pt2 = (result.shape[1], int((rho - result.shape[1] * np.cos(theta)) / np.sin(theta)))
cv2.line(result, pt1, pt2, (0, 0, 255), 1)
cv2.imwrite('saved Img/result.bmp', result)
def line_change_detection_P(self):
img = cv2.imread(self.path)
img = cv2.GaussianBlur(img, (3, 3), 0)
edges = cv2.Canny(img, 50, 150, apertureSize=3)
minLineLength = 200
maxLineGap = 15
linesP = cv2.HoughLinesP(edges, 1, np.pi / 180, 80, minLineLength, maxLineGap)
result_P = img.copy()
for i_P in linesP:
for x1, y1, x2, y2 in i_P:
cv2.line(result_P, (x1, y1), (x2, y2), (0, 255, 0), 3)
cv2.imwrite('saved Img/result_p.bmp', result_P)

@ -0,0 +1,61 @@
import cv2
import numpy as np
class logicalAlgorithm:
def __init__(self, img_path1, img_path2):
self.path1 = img_path1
self.path2 = img_path2
def alAnd(self):
x = cv2.imread(self.path1, 1)
y = cv2.imread(self.path2, 1)
rows, cols = x.shape[:2]
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
result = (x & y_dst)
cv2.imwrite("saved Img/And.bmp", result)
def alOr(self):
x = cv2.imread(self.path1, 1)
y = cv2.imread(self.path2, 1)
rows, cols = x.shape[:2]
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
result = (x | y_dst)
cv2.imwrite("saved Img/Or.bmp", result)
def alNegation(self):
x = cv2.imread(self.path1, 1)
result = (~x)
cv2.imwrite("saved Img/Negation.bmp", result)
def alAdd(self):
x = cv2.imread(self.path1, 1)
y = cv2.imread(self.path2, 1)
rows, cols = x.shape[:2]
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
result = cv2.add(x, y_dst)
cv2.imwrite("saved Img/Add.bmp", result)
def alSubtract(self):
x = cv2.imread(self.path1, 1)
y = cv2.imread(self.path2, 1)
rows, cols = x.shape[:2]
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
result = cv2.subtract(x, y_dst)
cv2.imwrite("saved Img/Subtract.bmp", result)
def alMulty(self):
x = cv2.imread(self.path1, 1).astype(np.float64)/255
y = cv2.imread(self.path2, 1).astype(np.float64)/255
rows, cols = x.shape[:2]
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
result = cv2.multiply(x, y_dst) * 255
cv2.imwrite("saved Img/Multiply.bmp", result)
def alDivide(self):
x = cv2.imread(self.path1, 1).astype(np.float64)/255
y = cv2.imread(self.path2, 1).astype(np.float64)/255
rows, cols = x.shape[:2]
y_dst = cv2.resize(y, (cols, rows), interpolation=cv2.INTER_CUBIC)
result = cv2.divide(x, y_dst) * 255
cv2.imwrite("saved Img/Divide.bmp", result)

@ -0,0 +1,78 @@
import random
import cv2
import numpy as np
class noiseCanceller:
def __init__(self, imgPath):
self.path = imgPath
def noiseDescriber(self):
image = cv2.imread(self.path, cv2.IMREAD_GRAYSCALE)
output = np.zeros(image.shape, np.uint8)
prob = 0.2
thres = 1 - prob
# 遍历图像,获取叠加噪声后的图像
for i in range(image.shape[0]):
for j in range(image.shape[1]):
rdn = random.random()
if rdn < prob:
# 添加胡椒噪声
output[i][j] = 0
elif rdn > thres:
# 添加食盐噪声
output[i][j] = 255
else:
# 不添加噪声
output[i][j] = image[i][j]
cv2.imwrite("saved Img/out.bmp", output)
def meanFilter(self):
image = cv2.imread(self.path, cv2.IMREAD_GRAYSCALE)
output = np.zeros(image.shape, np.uint8)
for i in range(image.shape[0]):
for j in range(image.shape[1]):
ij = 1
for m in range(-1, 2):
if 0 <= j + m < image.shape[1]:
ij *= image[i][j + m]
output[i][j] = ij ** (1 / 3)
cv2.imwrite("saved Img/mean filter.bmp", output)
def sortFilter(self):
def get_max(array):
length = len(array)
for i in range(length):
for j in range(i + 1, length):
if array[j] > array[i]:
temp = array[j]
array[j] = array[i]
array[i] = temp
return array[0]
image = cv2.imread(self.path, cv2.IMREAD_GRAYSCALE)
output = np.zeros(image.shape, np.uint8)
array = []
for i in range(image.shape[0]):
for j in range(image.shape[1]):
array.clear()
for m in range(-1, 2):
for n in range(-1, 2):
if 0 <= i + m < image.shape[0] and 0 <= j + n < image.shape[1]:
array.append(image[i + m][j + n])
output[i][j] = get_max(array)
cv2.imwrite("saved Img/sort filter.bmp", output)
def selectiveFilter(self):
image = cv2.imread(self.path, cv2.IMREAD_GRAYSCALE)
output = np.zeros(image.shape, np.uint8)
minimum = 200
for i in range(image.shape[0]):
for j in range(image.shape[1]):
if minimum < image[i][j]:
output[i][j] = image[i][j]
else:
output[i][j] = 0
cv2.imwrite("saved Img/selective filter.bmp", output)

@ -0,0 +1,18 @@
import cv2
class spatial:
def __init__(self, img_path):
self.path = img_path
def average_blur(self, ksize):
ksize = int(ksize)
img = cv2.imread(self.path)
avg_blur = cv2.blur(img, (ksize, ksize))
cv2.imwrite("saved Img/avg_blur.bmp", avg_blur)
def mid_blur(self, ksize):
ksize = int(ksize)
img = cv2.imread(self.path)
mid_blur = cv2.medianBlur(img, ksize)
cv2.imwrite("saved Img/mid_blur.bmp", mid_blur)

Binary file not shown.

Binary file not shown.

@ -0,0 +1,324 @@
import sys
from PyQt5 import QtWidgets, QtGui
from PyQt5.QtWidgets import *
from DIP import Ui_DigitalImageProcessing
from GeometricalChange import GeoChange
from LogicalAlgorithm import logicalAlgorithm
from Histogram import Histogram
from Hough import Hough
from EdgeDetection import edgeDetect
from morphology import morphology
from NoiseCanceller import noiseCanceller
from SpatialSmoothing import spatial
from FrequencySmoothing import frequency_filter
class run(QtWidgets.QMainWindow, Ui_DigitalImageProcessing):
def __init__(self):
super(run, self).__init__()
self.setupUi(self)
# 原图像路径,后面将作为图像处理的参数,表示对哪张图片进行图像处理。
self.img_path = ""
# 打开图像函数
def openImg(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
self.img_path = imgName
# 展示选中的图片
jpg = QtGui.QPixmap(imgName).scaled(self.original_img.width(), self.original_img.height())
self.original_img.setPixmap(jpg)
# 展示修改后图片
def showImg(self, pic_path):
jpg = QtGui.QPixmap(pic_path).scaled(self.fixed_img.width(), self.fixed_img.height())
self.fixed_img.setPixmap(jpg)
# 此处开始处理图像逻辑运算的槽函数, alAnd为图像与操作
def alAnd(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
al = logicalAlgorithm(self.img_path, imgName)
al.alAnd()
self.showImg("saved Img/And.bmp")
# 图像或操作槽函数
def alOr(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
al = logicalAlgorithm(self.img_path, imgName)
al.alOr()
self.showImg("saved Img/Or.bmp")
# 图像非操作槽函数
def alNegation(self):
al = logicalAlgorithm(self.img_path, self.img_path)
al.alNegation()
self.showImg("saved Img/Negation.bmp")
# 图像加法操作槽函数
def alAdd(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
al = logicalAlgorithm(self.img_path, imgName)
al.alAdd()
self.showImg("saved Img/Add.bmp")
# 图像减法操作槽函数
def alSubtract(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
al = logicalAlgorithm(self.img_path, imgName)
al.alSubtract()
self.showImg("saved Img/Subtract.bmp")
# 图像乘法操作槽函数
def alMulty(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
al = logicalAlgorithm(self.img_path, imgName)
al.alMulty()
self.showImg("saved Img/Multiply.bmp")
# 图像除法操作槽函数
def alDivide(self):
imgName, imgType = QFileDialog.getOpenFileName(self, "打开图片", "", "All Files(*);")
al = logicalAlgorithm(self.img_path, imgName)
al.alDivide()
self.showImg("saved Img/Divide.bmp")
# 此处开始处理图像几何变化的槽函数extend是图像放缩槽函数
def extend(self):
size, _ = QInputDialog.getText(self, "放缩倍数", "请输入放缩倍数, 倍数应为非负数。\n由于修改后图片预览是固定大小的,因此无法体现放缩效果\n请前往图片保存地址进行查看。", QLineEdit.Normal, "2")
try:
size = float(size)
geo = GeoChange(self.img_path)
geo.extend(size)
self.showImg("saved Img/size.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 图像平移槽函数
def moveImg(self):
xny, _ = QInputDialog.getText(self, "平移参数", "请输入平移参数\n输入格式为a,b其中a与b以英文逗号隔开。\n", QLineEdit.Normal, "20,20")
try:
ipt = xny.split(",")
a, b = [float(x) for x in ipt]
geo = GeoChange(self.img_path)
geo.move(a, b)
self.showImg("saved Img/move.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 图像旋转槽函数
def rotation(self):
degree, _ = QInputDialog.getText(self, "旋转角度", "请输入旋转角度,角度应为实数", QLineEdit.Normal, "90")
try:
degree = float(degree)
geo = GeoChange(self.img_path)
geo.rotation(degree)
self.showImg("saved Img/rotation.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 图像水平翻折槽函数
def horizonal(self):
geo = GeoChange(self.img_path)
geo.horizon_flip()
self.showImg("saved Img/horizon.bmp")
# 图像垂直翻折槽函数
def vertical(self):
geo = GeoChange(self.img_path)
geo.vertical_flip()
self.showImg("saved Img/vertical.bmp")
# 仿射变换槽函数
def affine(self):
geo = GeoChange(self.img_path)
geo.affine()
self.showImg("saved Img/affine.bmp")
# 下面开始对数字图像的直方图进行绘制histGrey为绘制灰度直方图的槽函数
def histGrey(self):
hist = Histogram(self.img_path)
hist.histGrey()
self.showImg(self.img_path)
# 彩色直方图绘制
def histRGB(self):
hist = Histogram(self.img_path)
hist.histRGB()
self.showImg(self.img_path)
# 绘制直方图
def histD(self):
hist = Histogram(self.img_path)
hist.hist()
self.showImg(self.img_path)
# 修改灰度直方图
def editHist(self):
hist = Histogram(self.img_path)
hist.editHist()
self.showImg(self.img_path)
# 以下是使用opencv实现线条变化检测的函数
def houghLines(self):
hough = Hough(self.img_path)
hough.line_change_detection()
self.showImg("saved Img/result.bmp")
# 使用Hough P实现线条变化检测
def houghLinesP(self):
hough = Hough(self.img_path)
hough.line_change_detection_P()
self.showImg('saved Img/result_p.bmp')
# 图像边缘检测部分
def basic_of_edge_detection(self):
edge = edgeDetect(self.img_path)
edge.graphicsEnhance()
self.showImg('saved Img/sharp.bmp')
# Roberts算子
def roberts(self):
edge = edgeDetect(self.img_path)
edge.roberts()
self.showImg("saved Img/roberts.bmp")
# Prewitt & sobel
def sobel(self):
edge = edgeDetect(self.img_path)
edge.sobel()
self.showImg("saved Img/sobel.bmp")
# laplacian
def laplacian(self):
edge = edgeDetect(self.img_path)
edge.laplacian()
self.showImg("saved Img/laplacian.bmp")
# LoG
def LoG(self):
edge = edgeDetect(self.img_path)
edge.LoG()
self.showImg("saved Img/log.bmp")
# canny
def canny(self):
edge = edgeDetect(self.img_path)
edge.canny()
self.showImg("saved Img/canny.bmp")
# 以下为图像形态学
# 腐蚀
def corrode(self):
struct_size, _ = QInputDialog.getText(self, "结构元大小", "请输入结构元大小,大小应为实数", QLineEdit.Normal, "5")
try:
morph = morphology(self.img_path)
morph.corrode(struct_size)
self.showImg("saved Img/erosion.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 膨胀
def dilation(self):
struct_size, _ = QInputDialog.getText(self, "结构元大小", "请输入结构元大小,大小应为实数", QLineEdit.Normal, "5")
try:
morph = morphology(self.img_path)
morph.dilation(struct_size)
self.showImg("saved Img/dilate.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 开运算
def open(self):
struct_size, _ = QInputDialog.getText(self, "结构元大小", "请输入结构元大小,大小应为实数", QLineEdit.Normal, "5")
try:
morph = morphology(self.img_path)
morph.open(struct_size)
self.showImg("saved Img/open.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 闭运算
def close(self):
struct_size, _ = QInputDialog.getText(self, "结构元大小", "请输入结构元大小,大小应为实数", QLineEdit.Normal, "5")
try:
morph = morphology(self.img_path)
morph.close(struct_size)
self.showImg("saved Img/close.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
# 接下来的部分是图像噪声处理
# describe是噪声描述器的槽函数
def describe(self):
noise = noiseCanceller(self.img_path)
noise.noiseDescriber()
self.showImg("saved Img/out.bmp")
# mean filter是均值滤波器的槽函数
def meanFilter(self):
noise = noiseCanceller(self.img_path)
noise.meanFilter()
self.showImg("saved Img/mean filter.bmp")
# 排序类滤波器的槽函数
def sortFilter(self):
noise = noiseCanceller(self.img_path)
noise.sortFilter()
self.showImg("saved Img/sort filter.bmp")
# 选择性滤波器槽函数
def selectiveFilter(self):
noise = noiseCanceller(self.img_path)
noise.selectiveFilter()
self.showImg("saved Img/selective filter.bmp")
# 以下为图像空域的平滑
# 均值
def avg_blur(self):
ksize, _ = QInputDialog.getText(self, "滤波核大小", "请输入滤波核的大小", QLineEdit.Normal, "3")
try:
blur = spatial(self.img_path)
blur.average_blur(ksize)
self.showImg("saved Img/avg_blur.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
def mid_blur(self):
ksize, _ = QInputDialog.getText(self, "滤波核大小", "请输入滤波核的大小", QLineEdit.Normal, "3")
try:
blur = spatial(self.img_path)
blur.mid_blur(ksize)
self.showImg("saved Img/mid_blur.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
def low_pass(self):
fre = frequency_filter(self.img_path)
fre.Ideal_low_pass_filtering_smooth()
self.showImg("saved Img/ideal_low_pass.bmp")
def butterworth(self):
D0, _ = QInputDialog.getText(self, "截止频率", "请输入截止频率", QLineEdit.Normal, "20")
n, _ = QInputDialog.getText(self, "阶数", "请输入阶数", QLineEdit.Normal, "2")
try:
fre = frequency_filter(self.img_path)
fre.butterworth(D0, n)
self.showImg("saved Img/butterworth.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
def gauss(self):
D0, _ = QInputDialog.getText(self, "截止频率", "请输入截止频率", QLineEdit.Normal, "20")
try:
fre = frequency_filter(self.img_path)
fre.gauss(D0)
self.showImg("saved Img/gauss.bmp")
except Exception as error:
QMessageBox.about(self.window(), "提示", f"{error}\n输入有误!请检查输入格式与内容。")
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
now_Status = run()
now_Status.show()
sys.exit(app.exec_())

@ -0,0 +1,34 @@
import cv2
class morphology:
def __init__(self, img_path):
self.path = img_path
def corrode(self, struct_size):
struct_size = int(struct_size)
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
erosion = cv2.erode(src, kernel)
cv2.imwrite("saved Img/erosion.bmp", erosion)
def dilation(self, struct_size):
struct_size = int(struct_size)
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
dilation = cv2.dilate(src, kernel)
cv2.imwrite("saved Img/dilate.bmp", dilation)
def open(self, struct_size):
struct_size = int(struct_size)
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
open = cv2.morphologyEx(src, cv2.MORPH_OPEN, kernel)
cv2.imwrite("saved Img/open.bmp", open)
def close(self, struct_size):
struct_size = int(struct_size)
src = cv2.imread(self.path, cv2.IMREAD_UNCHANGED)
kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (struct_size, struct_size))
close = cv2.morphologyEx(src, cv2.MORPH_CLOSE, kernel)
cv2.imwrite("saved Img/close.bmp", close)

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.9 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 83 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 366 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 657 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 71 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 394 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 476 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 668 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 65 KiB

@ -0,0 +1,39 @@
self.pushButton.clicked.connect(DigitalImageProcessing.openImg)
self.actionyu.triggered.connect(DigitalImageProcessing.alAnd)
self.actionhuo.triggered.connect(DigitalImageProcessing.alOr)
self.actionfei.triggered.connect(DigitalImageProcessing.alNegation)
self.actionjiafa.triggered.connect(DigitalImageProcessing.alAdd)
self.actionjianfa.triggered.connect(DigitalImageProcessing.alSubtract)
self.actionchengfa.triggered.connect(DigitalImageProcessing.alMulty)
self.actionchufa.triggered.connect(DigitalImageProcessing.alDivide)
self.actiontuxiangfanzhuan.triggered.connect(DigitalImageProcessing.horizonal)
self.actionchuizhifanzhuan.triggered.connect(DigitalImageProcessing.vertical)
self.actiontuxiangpingyi.triggered.connect(DigitalImageProcessing.moveImg)
self.actiontuxiangxuanzhuan.triggered.connect(DigitalImageProcessing.rotation)
self.actionkuozhansuofang.triggered.connect(DigitalImageProcessing.extend)
self.actionfangshebianhuan.triggered.connect(DigitalImageProcessing.affine)
self.actionhuiduzhifangtu.triggered.connect(DigitalImageProcessing.histGrey)
self.actioncaisezhifangtu.triggered.connect(DigitalImageProcessing.histRGB)
self.actionhuizhizhifangtu.triggered.connect(DigitalImageProcessing.histD)
self.actionfenduanxianxingbianhuanduizhifangtuxiugai.triggered.connect(DigitalImageProcessing.editHist)
self.actionHough.triggered.connect(DigitalImageProcessing.houghLines)
self.actionHoughP.triggered.connect(DigitalImageProcessing.houghLinesP)
self.actionbianyuanjiancedejibenyuanli.triggered.connect(DigitalImageProcessing.basic_of_edge_detection)
self.actionRoberts.triggered.connect(DigitalImageProcessing.roberts)
self.actionPrewitt_Sobel.triggered.connect(DigitalImageProcessing.sobel)
self.actionLaplacian.triggered.connect(DigitalImageProcessing.laplacian)
self.actionLoG.triggered.connect(DigitalImageProcessing.LoG)
self.actionCanny.triggered.connect(DigitalImageProcessing.canny)
self.actionfushi.triggered.connect(DigitalImageProcessing.corrode)
self.actionpengzhang.triggered.connect(DigitalImageProcessing.dilation)
self.actionkaiyunsuan.triggered.connect(DigitalImageProcessing.open)
self.actionbiyunsuan.triggered.connect(DigitalImageProcessing.close)
self.actionzao_sheng_miaoshuqi.triggered.connect(DigitalImageProcessing.describe)
self.actionjunzhileilvboqi.triggered.connect(DigitalImageProcessing.meanFilter)
self.actionpaixutongjileilvboqi.triggered.connect(DigitalImageProcessing.sortFilter)
self.actionxuanzexinglvboqi.triggered.connect(DigitalImageProcessing.selectiveFilter)
self.actionlingyupingjunfa.triggered.connect(DigitalImageProcessing.avg_blur)
self.actionzhongzhilvbo.triggered.connect(DigitalImageProcessing.mid_blur)
self.actionlixiang.triggered.connect(DigitalImageProcessing.low_pass)
self.actionButterworth.triggered.connect(DigitalImageProcessing.butterworth)
self.actionGauss.triggered.connect(DigitalImageProcessing.gauss)

@ -0,0 +1,46 @@
一、数字图像的计算处理:
1. 与运算
2. 或运算
3. 非运算
4. 加法运算
5. 减法运算
6. 乘法运算
7. 除法运算
二、数字图像的几何变换:
1. 图形扩展缩放
2. 图形平移
3. 图形旋转
4. 图形翻转
5. 仿射变换
三、数字图像直方图
1. 灰度直方图计算
2. 彩色直方图计算
3. 绘制直方图
4. 分段线性变换对直方图修改
四、使用Hough变换实现线条变化检测
五、边缘检测
1. 边缘检测的基本原理与图像增强
2. Roberts算子
3. Prewitt算子与Sobel算子
4. Laplacian算子
5. LoG边缘算子
6. Canny边缘检测
六、数字图像形态学
1. 图像形态学操作
2. 结构元
3. 结构元的分类
4. 腐蚀
5. 膨胀
6. 开运算
7. 闭运算
七、噪声滤除
1. 噪声描述器
2. 均值类滤波器
3. 排序统计类滤波器
4. 选择性滤波器
Loading…
Cancel
Save