commit ce2420b6409d3a7e8353871ccd385d4081060428 Author: XIE <2598330413@qq.com> Date: Fri Jul 29 20:30:38 2022 +0800 first commit diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -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 diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..001cba9 --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +driver.py \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..d0a1ee7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,35 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2517932 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..69bb3a4 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/数字图像处理.iml b/.idea/数字图像处理.iml new file mode 100644 index 0000000..8ad733e --- /dev/null +++ b/.idea/数字图像处理.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/DIP.py b/DIP.py new file mode 100644 index 0000000..981c0a8 --- /dev/null +++ b/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", "高斯低通滤波")) diff --git a/DIP.ui b/DIP.ui new file mode 100644 index 0000000..2a535fe --- /dev/null +++ b/DIP.ui @@ -0,0 +1,412 @@ + + + DigitalImageProcessing + + + + 0 + 0 + 975 + 614 + + + + 数字图像处理 + + + + + + 30 + 40 + 421 + 321 + + + + + Agency FB + 14 + + + + 原始图片 + + + + + 40 + 30 + 351 + 261 + + + + background : rgb(0, 170, 255) + + + + + + + + + + 520 + 40 + 411 + 321 + + + + + Agency FB + 14 + + + + 修改后图片 + + + + + 30 + 30 + 361 + 261 + + + + background : rgb(0, 170, 255) + + + + + + + + + + 390 + 410 + 191 + 91 + + + + 打开图片 + + + + + + + 0 + 0 + 975 + 21 + + + + + 数字图像的计算 + + + + + + + + + + + + 数字图像的几何变换 + + + + + + + + + + + 数字图像直方图 + + + + + + + + + 使用Hough变换实现线条变换检测 + + + + + + + 边缘检测 + + + + + + + + + + + 数字图像形态学 + + + + + + + + + 噪声滤除 + + + + + + + + + 空域的平滑 + + + + + + + 频域的平滑 + + + + + + + + + + + + + + + + + + + 与运算 + + + + + 或运算 + + + + + 非运算 + + + + + 加法运算 + + + + + 减法运算 + + + + + 乘法运算 + + + + + 除法运算 + + + + + 扩展缩放 + + + + + 图像平移 + + + + + 图像旋转 + + + + + 图像水平翻转 + + + + + 图像垂直翻转 + + + + + 灰度直方图 + + + + + 彩色直方图 + + + + + 绘制直方图 + + + + + 分段线性变换对直方图修改 + + + + + 边缘检测的基本原理与图像增强 + + + + + Roberts + + + + + Prewitt & Sobel + + + + + Laplacian + + + + + LoG + + + + + Canny + + + + + 图像形态学操作 + + + + + + + + + + jiegouyuandefenlei + + + + + 腐蚀 + + + + + 膨胀 + + + + + 开运算 + + + + + 闭运算 + + + + + 噪声描述器 + + + + + 均值滤波器 + + + + + 排序统计类滤波器 + + + + + 选择性滤波器 + + + + + 仿射变换 + + + + + 使用Hough变换实现线条变化检测 + + + + + HoughP + + + + + 邻域平均法 + + + + + 中值滤波法 + + + + + 理想低通滤波 + + + + + 巴特沃斯低通滤波 + + + + + 高斯低通滤波 + + + + + + diff --git a/EdgeDetection.py b/EdgeDetection.py new file mode 100644 index 0000000..84095b4 --- /dev/null +++ b/EdgeDetection.py @@ -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) diff --git a/FrequencySmoothing.py b/FrequencySmoothing.py new file mode 100644 index 0000000..c514e56 --- /dev/null +++ b/FrequencySmoothing.py @@ -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') diff --git a/GeometricalChange.py b/GeometricalChange.py new file mode 100644 index 0000000..939acae --- /dev/null +++ b/GeometricalChange.py @@ -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) diff --git a/Histogram.py b/Histogram.py new file mode 100644 index 0000000..14134ed --- /dev/null +++ b/Histogram.py @@ -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() diff --git a/Hough.py b/Hough.py new file mode 100644 index 0000000..e0b5d07 --- /dev/null +++ b/Hough.py @@ -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) diff --git a/LogicalAlgorithm.py b/LogicalAlgorithm.py new file mode 100644 index 0000000..2ff0b15 --- /dev/null +++ b/LogicalAlgorithm.py @@ -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) diff --git a/NoiseCanceller.py b/NoiseCanceller.py new file mode 100644 index 0000000..71fa3ff --- /dev/null +++ b/NoiseCanceller.py @@ -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) diff --git a/SpatialSmoothing.py b/SpatialSmoothing.py new file mode 100644 index 0000000..b053e22 --- /dev/null +++ b/SpatialSmoothing.py @@ -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) diff --git a/__pycache__/DIP.cpython-36.pyc b/__pycache__/DIP.cpython-36.pyc new file mode 100644 index 0000000..fc5297a Binary files /dev/null and b/__pycache__/DIP.cpython-36.pyc differ diff --git a/__pycache__/EdgeDetection.cpython-36.pyc b/__pycache__/EdgeDetection.cpython-36.pyc new file mode 100644 index 0000000..605caeb Binary files /dev/null and b/__pycache__/EdgeDetection.cpython-36.pyc differ diff --git a/__pycache__/FrequencySmoothing.cpython-36.pyc b/__pycache__/FrequencySmoothing.cpython-36.pyc new file mode 100644 index 0000000..20c1116 Binary files /dev/null and b/__pycache__/FrequencySmoothing.cpython-36.pyc differ diff --git a/__pycache__/GeometricalChange.cpython-36.pyc b/__pycache__/GeometricalChange.cpython-36.pyc new file mode 100644 index 0000000..0d2dd04 Binary files /dev/null and b/__pycache__/GeometricalChange.cpython-36.pyc differ diff --git a/__pycache__/Histogram.cpython-36.pyc b/__pycache__/Histogram.cpython-36.pyc new file mode 100644 index 0000000..d5ff98c Binary files /dev/null and b/__pycache__/Histogram.cpython-36.pyc differ diff --git a/__pycache__/Hough.cpython-36.pyc b/__pycache__/Hough.cpython-36.pyc new file mode 100644 index 0000000..b7982d4 Binary files /dev/null and b/__pycache__/Hough.cpython-36.pyc differ diff --git a/__pycache__/LogicalAlgorithm.cpython-36.pyc b/__pycache__/LogicalAlgorithm.cpython-36.pyc new file mode 100644 index 0000000..ff2c317 Binary files /dev/null and b/__pycache__/LogicalAlgorithm.cpython-36.pyc differ diff --git a/__pycache__/NoiseCanceller.cpython-36.pyc b/__pycache__/NoiseCanceller.cpython-36.pyc new file mode 100644 index 0000000..8edb3d2 Binary files /dev/null and b/__pycache__/NoiseCanceller.cpython-36.pyc differ diff --git a/__pycache__/SpatialSmoothing.cpython-36.pyc b/__pycache__/SpatialSmoothing.cpython-36.pyc new file mode 100644 index 0000000..2ee1f36 Binary files /dev/null and b/__pycache__/SpatialSmoothing.cpython-36.pyc differ diff --git a/__pycache__/morphology.cpython-36.pyc b/__pycache__/morphology.cpython-36.pyc new file mode 100644 index 0000000..005d0be Binary files /dev/null and b/__pycache__/morphology.cpython-36.pyc differ diff --git a/driver.py b/driver.py new file mode 100644 index 0000000..f976747 --- /dev/null +++ b/driver.py @@ -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_()) diff --git a/morphology.py b/morphology.py new file mode 100644 index 0000000..e98ef1a --- /dev/null +++ b/morphology.py @@ -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) diff --git a/test Img/123.png b/test Img/123.png new file mode 100644 index 0000000..578e575 Binary files /dev/null and b/test Img/123.png differ diff --git a/test Img/20220712152435.jpg b/test Img/20220712152435.jpg new file mode 100644 index 0000000..468221e Binary files /dev/null and b/test Img/20220712152435.jpg differ diff --git a/test Img/a.png b/test Img/a.png new file mode 100644 index 0000000..97bccd2 Binary files /dev/null and b/test Img/a.png differ diff --git a/test Img/edu.png b/test Img/edu.png new file mode 100644 index 0000000..cafb020 Binary files /dev/null and b/test Img/edu.png differ diff --git a/test Img/ex_1.jpg b/test Img/ex_1.jpg new file mode 100644 index 0000000..1084bed Binary files /dev/null and b/test Img/ex_1.jpg differ diff --git a/test Img/image (1).bmp b/test Img/image (1).bmp new file mode 100644 index 0000000..258f3f0 Binary files /dev/null and b/test Img/image (1).bmp differ diff --git a/test Img/image (2).bmp b/test Img/image (2).bmp new file mode 100644 index 0000000..5dd8d6b Binary files /dev/null and b/test Img/image (2).bmp differ diff --git a/test Img/image (3).bmp b/test Img/image (3).bmp new file mode 100644 index 0000000..64320f7 Binary files /dev/null and b/test Img/image (3).bmp differ diff --git a/test Img/image (4).bmp b/test Img/image (4).bmp new file mode 100644 index 0000000..a04114c Binary files /dev/null and b/test Img/image (4).bmp differ diff --git a/test Img/image (5).bmp b/test Img/image (5).bmp new file mode 100644 index 0000000..411eef3 Binary files /dev/null and b/test Img/image (5).bmp differ diff --git a/test Img/image (6).png b/test Img/image (6).png new file mode 100644 index 0000000..c13b431 Binary files /dev/null and b/test Img/image (6).png differ diff --git a/test Img/image (7).png b/test Img/image (7).png new file mode 100644 index 0000000..1d41317 Binary files /dev/null and b/test Img/image (7).png differ diff --git a/test Img/image.bmp b/test Img/image.bmp new file mode 100644 index 0000000..76037bc Binary files /dev/null and b/test Img/image.bmp differ diff --git a/test Img/test.png b/test Img/test.png new file mode 100644 index 0000000..8fc1da4 Binary files /dev/null and b/test Img/test.png differ diff --git a/test Img/zao.png b/test Img/zao.png new file mode 100644 index 0000000..ce5ae7a Binary files /dev/null and b/test Img/zao.png differ diff --git a/test Img/zero.bmp b/test Img/zero.bmp new file mode 100644 index 0000000..06d46a4 Binary files /dev/null and b/test Img/zero.bmp differ diff --git a/test Img/zero1.bmp b/test Img/zero1.bmp new file mode 100644 index 0000000..2d24cca Binary files /dev/null and b/test Img/zero1.bmp differ diff --git a/信号.txt b/信号.txt new file mode 100644 index 0000000..99e1200 --- /dev/null +++ b/信号.txt @@ -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) \ No newline at end of file diff --git a/数字图像处理大类.txt b/数字图像处理大类.txt new file mode 100644 index 0000000..e5ef978 --- /dev/null +++ b/数字图像处理大类.txt @@ -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. 选择性滤波器 \ No newline at end of file