#!/usr/bin/python3
# -*- coding: utf-8 -*-
import sys
import os
from PyQt5.QtGui import *
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5 import QtCore, QtGui, QtWidgets
from mainWindowLayout import MainLayout
import cv2
import numpy as np
from scipy import ndimage
from matplotlib import pyplot as plt
class MainWindow(QMainWindow, MainLayout):
imagePaths = []
originImages=[]
imageList = [] #二维的图像列表
hideLayoutTag=-1
def __init__(self,parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
self.signalSlots()
#button与具体方法关联
def signalSlots(self):
#文件按钮相关方法
#打开
self.openAct.triggered.connect(lambda : importImage(self))
#保存
self.saveAct.triggered.connect(lambda : importImage(self))
#退出
self.exitAct.triggered.connect(self.close)
#编辑按钮相关方法
#放大
self.largeAct.triggered.connect(lambda : largeImage(self))
#缩小
self.smallAct.triggered.connect(lambda : smallImage(self))
#灰度
self.grayAct.triggered.connect(lambda : grayImage(self))
#亮度
self.brightAct.triggered.connect(lambda : brightImage(self))
#旋转
self.rotateAct.triggered.connect(lambda : rotateImage(self))
#截图
self.screenshotAct.triggered.connect(lambda : screenshotImage(self))
#变换按钮相关方法
#傅里叶变换
self.change1Act.triggered.connect(lambda : change1Image(self))
#离散余弦变换
self.change2Act.triggered.connect(lambda : change2Image(self))
#Radon变换
self.change3Act.triggered.connect(lambda : change3Image(self))
#噪声按钮相关方法
#高斯噪声
self.noise1Act.triggered.connect(lambda : noise1Image(self))
#椒盐噪声
self.noise2Act.triggered.connect(lambda : noise2Image(self))
#斑点噪声
self.noise3Act.triggered.connect(lambda : importImage(self))
#泊松噪声
self.noise4Act.triggered.connect(lambda : importImage(self))
#滤波按钮相关方法
#高通滤波
self.smoothing1Act.triggered.connect(lambda : smoothing1Image(self))
#低通滤波
self.smoothing2Act.triggered.connect(lambda : smoothing2Image(self))
#平滑滤波
self.smoothing3Act.triggered.connect(lambda : smoothing3Image(self))
#锐化滤波
self.smoothing4Act.triggered.connect(lambda : smoothing4Image(self))
#直方图统计按钮相关方法
#R直方图
self.hist1Act.triggered.connect(lambda : hist1Image(self))
#G直方图
self.hist2Act.triggered.connect(lambda : importImage(self))
#B直方图
self.hist3Act.triggered.connect(lambda : importImage(self))
#图像增强按钮相关方法
#伪彩色增强
self.enhance1Act.triggered.connect(lambda : enhance1Image(self))
#真彩色增强
self.enhance2Act.triggered.connect(lambda : enhance2Image(self))
#直方图均衡
self.enhance3Act.triggered.connect(lambda : histNormalized(self))
#NTSC颜色模型
self.enhance4Act.triggered.connect(lambda : enhance4Image(self))
#YCbCr颜色模型
self.enhance5Act.triggered.connect(lambda : enhance5Image(self))
#HSV颜色模型
self.enhance6Act.triggered.connect(lambda : enhance6Image(self))
#阈值分割方法
self.threButton.clicked.connect(lambda : threImage(self))
#形态学处理方法
self.morphologyProcessButton.clicked.connect(lambda : morphologyProcessImage(self))
#特征提取方法
self.featureButton.clicked.connect(lambda : featureImage(self))
#图像分类与识别方法
self.imgButton.clicked.connect(lambda : layoutChange(self))
#底部
#上一张
self.preButton.clicked.connect(lambda : preImage(self))
#下一张
self.nextButton.clicked.connect(lambda : nextImage(self))
#退出
self.exitButton.clicked.connect(self.close)
#编辑按钮相关方法
#放大
def largeImage(window):
imageList=[]
for img in window.originImages:
imgs=[]
img_info=img[0].shape
image_height=img_info[0]
image_weight=img_info[1]
dstHeight=int(2*image_height)
dstWeight=int(2*image_weight)
result=cv2.resize(img[0],(dstHeight,dstWeight))
imgs.extend([img[0],result])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','放大后'])
#缩小
def smallImage(window):
imageList=[]
for img in window.originImages:
imgs=[]
img_info=img[0].shape
image_height=img_info[0]
image_weight=img_info[1]
dstHeight=int(0.5*image_height)
dstWeight=int(0.5*image_weight)
result=cv2.resize(img[0],(dstHeight,dstWeight))
imgs.extend([img[0],result])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','缩小后'])
#灰度
def grayImage(window):
imageList=[]
for img in window.originImages:
imgs=[]
result = cv2.cvtColor(img[0], cv2.COLOR_BGR2RGB)
imgs.extend([img[0],result])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','灰度处理后'])
#亮度
def brightImage(window):
imageList=[]
for img in window.originImages:
imgs=[]
rows, cols, chunnel = img[0].shape
blank = np.zeros([rows, cols, chunnel], img[0].dtype)
result = cv2.addWeighted(img[0], 1.3, blank, 1-1.3, 3)
imgs.extend([img[0],result])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','调整亮度后'])
#旋转
def rotateImage(window):
imageList=[]
for img in window.originImages:
imgs=[]
img_info=img[0].shape
image_height=img_info[0]
image_weight=img_info[1]
mat_rotate=cv2.getRotationMatrix2D((image_height*0.5,image_weight*0.5),90,1) #center angle 3scale
result=cv2.warpAffine(img[0],mat_rotate,(image_height,image_weight))
imgs.extend([img[0],result])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','旋转后'])
#截图
def screenshotImage(window):
imageList=[]
for img in window.originImages:
imgs=[]
result = img[0][70:170, 440:540]
imgs.extend([img[0],result])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','截图后'])
#变换按钮相关方法
#傅里叶变换
def change1Image(window):
imageList=[]
for img in window.originImages:
imgs=[]
b,g,r=cv2.split(img[0])
b_freImg,b_recImg=oneChannelDft(b)
g_freImg, g_recImg = oneChannelDft(g)
r_freImg, r_recImg = oneChannelDft(r)
freImg=cv2.merge([b_freImg,g_freImg,r_freImg])
imgs.extend([img[0],freImg])
imageList.append(imgs)
resizeFromList(window, imageList)
showImage(window,['原图','傅里叶变换后'])
def oneChannelDft(img):
width, height = img.shape
nwidth = cv2.getOptimalDFTSize(width)
nheigth = cv2.getOptimalDFTSize(height)
nimg = np.zeros((nwidth, nheigth))
nimg[:width, :height] = img
dft = cv2.dft(np.float32(nimg), flags=cv2.DFT_COMPLEX_OUTPUT)
ndft = dft[:width, :height]
ndshift = np.fft.fftshift(ndft)
magnitude = np.log(cv2.magnitude(ndshift[:, :, 0], ndshift[:
.whl
- 粉丝: 3842
- 资源: 4699
最新资源
- 技术资料分享MP2359 AN很好的技术资料.zip
- 天翼云迁移工具RDA用户指南-资源迁移与配置实践
- 技术资料分享MP2359很好的技术资料.zip
- 技术资料分享MultiMediaCard Product Manual很好的技术资料.zip
- (入门不当可能导致入狱) 基于linux的企业级别社会工程学渗透测试、轻量级别Web渗透辅助 内置的钓鱼网站可以获取主要的个人信息账户网站克隆模块可以把白宫网站给克隆下来内置的各种Web终端完.zip
- 技术资料分享NES Specifications很好的技术资料.zip
- 技术资料分享Nintendo Entertainment System Documentation Version 1.0很好的技术资料.zip
- java微服务框架源码数据库 MySQL源码类型 WebForm
- 基于Python+Django可视化的学习系统的设计与实现
- An automated penetration testing information collection tool , 一款自动化渗透测试信息搜集类工具.zip
- 技术资料分享nRF24L01P(新版无线模块控制IC)很好的技术资料.zip
- 技术资料分享NRF24L01功能使用文档很好的技术资料.zip
- Android、iOS渗透测试工具收集.zip
- 技术资料分享NRF24l01模块说明书很好的技术资料.zip
- 技术资料分享nRF24L01中文说明书很好的技术资料.zip
- Android渗透测试drozer自动化.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈