diff --git a/Blue_noise_sampling.py b/Blue_noise_sampling.py index a21ca86..5d9cbd8 100644 --- a/Blue_noise_sampling.py +++ b/Blue_noise_sampling.py @@ -4,13 +4,17 @@ # @Email : derighoid@gmail.com # @File : Blue_noise_sampling.py # @Software: PyCharm +from pathlib import Path - +import matplotlib import matplotlib.pyplot as plt import numpy as np from PIL import Image ''' +最近邻插值法: +在放大图像时,多出来的像素点由最近邻的像素点构成 +计算新图形(放大后或缩小后)的坐标点像素值对应于原图像中哪一个像素点填充的。 srcX=newX*(srcW/newW) srcY=newY*(srcH/newH) src是原图,dst是新图,原来的图像宽度/高度除以新图像的宽度/高度可以得到缩放比例, @@ -57,3 +61,6 @@ def showImage(picPath): plt.imshow(image1) plt.show() return image1 + + + diff --git a/GUI.py b/GUI.py index 59580a1..7695399 100644 --- a/GUI.py +++ b/GUI.py @@ -7,7 +7,6 @@ import os import tkinter import tkinter.filedialog -import tkinter.messagebox # 弹窗库 import PIL import numpy as np @@ -15,16 +14,18 @@ import requests from PIL import Image, ImageTk root = tkinter.Tk() -root.title = 'new' -root.geometry('640x500') +root.title("基于Python的图像处理") + +root.geometry('640x500') +root.resizable(width=0, height=0) # 文件选择 def choose_fiel(): selectFileName = tkinter.filedialog.askopenfilename(title='选择文件') # 选择文件 e.set(selectFileName) - +#文件选择标签 label1 = tkinter.Label(root, text="文件路径:") label1.place(x=40, y=0) @@ -37,12 +38,13 @@ lable2.place(x=40, y=30) # 设置输入框 entry = tkinter.Entry(root, width=60) +#设置默认值 entry.insert(0, "https://tse2-mm.cn.bing.net/th/id/OIP-C.fT7uKiT7V7YO2PPINFeOdQHaJ4?w=186&h=248&c=7&r=0&o=5&dpr=1.25&pid=1.7") entry.place(x=100, y=30) # 选择文件按钮 -submit_button = tkinter.Button(root, text="选择文件", command=choose_fiel) +submit_button = tkinter.Button(root, text="选择文件", command=choose_fiel,activeforeground="red") submit_button.place(x=520, y=0) @@ -68,7 +70,7 @@ def pictureCrawl(url): # 爬取按钮 -imgCrawling_button = tkinter.Button(root, text="开始爬取", command=lambda: pictureCrawl(entry.get())) +imgCrawling_button = tkinter.Button(root, text="开始爬取", command=lambda: pictureCrawl(entry.get()),activeforeground="red") imgCrawling_button.place(x=520, y=30) @@ -83,7 +85,7 @@ def grayPic(e_entry): # 灰色图按钮 -grayPic_button = tkinter.Button(root, text="灰色图", command=lambda: grayPic(e_entry)) +grayPic_button = tkinter.Button(root, text="灰色图", command=lambda: grayPic(e_entry),activeforeground="red") grayPic_button.place(x=110, y=75) @@ -100,17 +102,15 @@ def mirrorSymmetry(e_entry): # 镜面按钮 -mirrorSymmetry_button = tkinter.Button(root, text="镜面对称", command=lambda: mirrorSymmetry(e_entry)) +mirrorSymmetry_button = tkinter.Button(root, text="镜面对称", command=lambda: mirrorSymmetry(e_entry),activeforeground="red") mirrorSymmetry_button.place(x=170, y=75) # 右旋转 def verticalSummetry_right(e_tery): img = Image.open(e_entry.get()) - img = np.array(img) - img1 = img.swapaxes(1, 0) - img2 = img1[:, ::-1] - img2 = Image.fromarray(img2) + + img2 = img.transpose(Image.ROTATE_270) pic = ImageTk.PhotoImage(img2) img = tkinter.Label(image=pic) @@ -119,19 +119,15 @@ def verticalSummetry_right(e_tery): # 右旋转按钮 -verticalSummetry_right_button = tkinter.Button(root, text="右旋转", command=lambda: verticalSummetry_right(e_entry)) +verticalSummetry_right_button = tkinter.Button(root, text="右旋转", command=lambda: verticalSummetry_right(e_entry),activeforeground="red") verticalSummetry_right_button.place(x=240, y=75) # 左旋转 def verticalSummetry_lift(e_entry): img = Image.open(e_entry.get()) - img = np.array(img) - img1 = img.transpose(1, 0, 2) # x,y轴转置 - img2 = img1[::-1] - - img2 = Image.fromarray(img2) + img2 = img.transpose(Image.ROTATE_90) pic = ImageTk.PhotoImage(img2) img = tkinter.Label(image=pic) img.image = pic @@ -139,7 +135,7 @@ def verticalSummetry_lift(e_entry): # 左旋转按钮 -verticalSummetry_lift_button = tkinter.Button(root, text="左旋转", command=lambda: verticalSummetry_lift(e_entry)) +verticalSummetry_lift_button = tkinter.Button(root, text="左旋转", command=lambda: verticalSummetry_lift(e_entry),activeforeground="red") verticalSummetry_lift_button.place(x=300, y=75) @@ -155,7 +151,7 @@ def pixInversion(e_entry): # 像素反转 -pixInversion_button = tkinter.Button(root, text="像素反转", command=lambda: pixInversion(e_entry)) +pixInversion_button = tkinter.Button(root, text="像素反转", command=lambda: pixInversion(e_entry),activeforeground="red") pixInversion_button.place(x=360, y=75) @@ -171,7 +167,7 @@ def redImage(e_entry): # 红色图按钮 -red_button = tkinter.Button(root, text="红色图", command=lambda: redImage(e_entry)) +red_button = tkinter.Button(root, text="红色图", command=lambda: redImage(e_entry),activeforeground="red") red_button.place(x=430, y=75) @@ -187,10 +183,11 @@ def blueImage(e_entry): # 蓝色图按钮 -blue_button = tkinter.Button(root, text="蓝色图", command=lambda: blueImage(e_entry)) +blue_button = tkinter.Button(root, text="蓝色图", command=lambda: blueImage(e_entry),activeforeground="red") blue_button.place(x=490, y=75) -#绿色图函数 + +# 绿色图函数 def greenImage(e_entry): img = Image.open(e_entry.get()) img = np.array(img) @@ -203,7 +200,7 @@ def greenImage(e_entry): # 绿色按钮 -green_button = tkinter.Button(root, text='绿色图', command=lambda: greenImage(e_entry)) +green_button = tkinter.Button(root, text='绿色图', command=lambda: greenImage(e_entry),activeforeground="red") green_button.place(x=550, y=75) @@ -221,14 +218,14 @@ def imageMix(e_entry): # 图像混合按钮 -imageMix_button = tkinter.Button(root, text="图像混合", command=lambda: imageMix(e_entry)) +imageMix_button = tkinter.Button(root, text="图像混合", command=lambda: imageMix(e_entry),activeforeground="red") imageMix_button.place(x=40, y=105) # 图像剪切函数 -def imageCut(e_entry): +def imageCut(e_entry,Entrybutton): # 一个Entrybutton代表四个值(20, 10, 190, 190) img1 = Image.open(e_entry.get()) - part = (20, 10, 190, 190) + part = (eval(Entrybutton.get())) img2 = img1.crop(part) img3 = ImageTk.PhotoImage(img2) img = tkinter.Label(image=img3) @@ -237,13 +234,13 @@ def imageCut(e_entry): # 剪切按钮 -cut_button = tkinter.Button(root, text="剪 切", command=lambda: imageCut(e_entry)) +cut_button = tkinter.Button(root, text="剪 切", command=lambda: imageCut(e_entry,Entrybutton),activeforeground="red") cut_button.place(x=110, y=105) # 部分替换函数 -def imgReplace(e_entry): - part = (10, 50, 250, 250) +def imgReplace(e_entry,Entrybutton): # Entrybutton 代表4个值(10, 50, 250, 250) + part = (eval(Entrybutton.get())) img1 = Image.open(e_entry.get()) img2 = Image.open("./data/picture.png") img3 = img2.crop(part) @@ -256,23 +253,24 @@ def imgReplace(e_entry): # 部分替换按钮 -imgReplace_button = tkinter.Button(root, text="部分替换", command=lambda: imgReplace(e_entry)) +imgReplace_button = tkinter.Button(root, text="部分替换", command=lambda: imgReplace(e_entry,Entrybutton),activeforeground="red") imgReplace_button.place(x=170, y=105) # 输入框 Entrybutton = tkinter.Entry(root, width=15) -Entrybutton.insert(0, 2) +Entrybutton.insert(0, 0.5) Entrybutton.place(x=490, y=110) lab5 = tkinter.Label(root, text="Gamma:") lab5.place(x=430, y=110) - +lab6=tkinter.Label(root,text=":<-other") +lab6.place(x=585,y=110) # 伽马矫正函数(默认1/1,5) def gammaCorrect(e_entry, Entrybutton): img = Image.open(e_entry.get()) img = np.array(img) - img1 = np.power(img / float(np.max(img)), int(Entrybutton.get())) + img1 = np.power(img / float(np.max(img)), float(Entrybutton.get())) img2 = Image.fromarray(np.uint8(img1 * 255)) img3 = ImageTk.PhotoImage(img2) img = tkinter.Label(image=img3) @@ -281,7 +279,7 @@ def gammaCorrect(e_entry, Entrybutton): # 伽马矫正按钮 -gammaCorrect_button = tkinter.Button(root, text="伽马矫正", command=lambda: gammaCorrect(e_entry, Entrybutton)) +gammaCorrect_button = tkinter.Button(root, text="伽马矫正", command=lambda: gammaCorrect(e_entry, Entrybutton),activeforeground="red") gammaCorrect_button.place(x=240, y=105) @@ -308,7 +306,7 @@ def decrease_color(e_entry): # 减色按钮 -decrease_color_button = tkinter.Button(root, text="减色", command=lambda: decrease_color(e_entry)) +decrease_color_button = tkinter.Button(root, text="减色", command=lambda: decrease_color(e_entry),activeforeground="red") decrease_color_button.place(x=310, y=105) @@ -338,7 +336,7 @@ def showImage(e_entry): # 采样按钮 -picSampl_button = tkinter.Button(root, text='图片采样', command=lambda: showImage(e_entry)) +picSampl_button = tkinter.Button(root, text='图片采样', command=lambda: showImage(e_entry),activeforeground="red") picSampl_button.place(x=360, y=105) @@ -352,8 +350,9 @@ def showImg(e_entry): img.place(x=50, y=150) + # 图片展示按钮 -submit_button = tkinter.Button(root, text="显示原图", command=lambda: showImg(e_entry)) +submit_button = tkinter.Button(root, text="显示原图", command=lambda: showImg(e_entry),activeforeground="red") submit_button.place(x=40, y=75) lable3 = tkinter.Label(root, text='原图', bg='red') diff --git a/Image_Capture.py b/Image_Capture.py index 1183cc5..69c8f93 100644 --- a/Image_Capture.py +++ b/Image_Capture.py @@ -28,7 +28,7 @@ def imgCut(path, left, upper, right, lower): # print(img.size) Picture Size part = (left, upper, right, lower) # 设置剪切的大小 - # 剪切函数的调用 + # 函数的调用 cut_img = img.crop(part) # 展示图片 diff --git a/Image_Mix.py b/Image_Mix.py index 51535d4..96a27b6 100644 --- a/Image_Mix.py +++ b/Image_Mix.py @@ -16,7 +16,7 @@ alpha:透明度 ,取值范围为 0 到 1,当取值为 0 时,输出图像 则是 image2 的拷贝,只有当取值为 0.5 时,才为两个图像的中合。因此改值的大小决定了两个图像的混合程度''' -# 阿尔法图像混合 +# 图像混合 def imageMix(imagePath1, imagePath2): ''' diff --git a/Modify_Pixels.py b/Modify_Pixels.py index 2d6625b..f127c70 100644 --- a/Modify_Pixels.py +++ b/Modify_Pixels.py @@ -51,8 +51,11 @@ class modfifyImage(): x, y = plt.subplots(2, 2) x.set_size_inches(10, 10) y[0, 0].imshow(self.imageMatrix()) + y[0, 1].imshow(red) + y[1, 0].imshow(green) + y[1, 1].imshow(blue) # 图片保存 Image.fromarray(np.uint8(red)).save(root + 'picture1' + '.jpg') diff --git a/Orientation_Modification.py b/Orientation_Modification.py index 9e70418..666f1cf 100644 --- a/Orientation_Modification.py +++ b/Orientation_Modification.py @@ -42,26 +42,25 @@ class directionChanges(): # 图像水平镜面对称 def mirrorSymmetry(self): - plt6 = self.imageMatrix()[::-1] + # plt6 = self.imageMatrix()[::-1] + plt6=self.imageRead().transpose(Image.ROTATE_180) plt.imshow(plt6) plt.show() return plt6 - # 垂直对称(右旋转) def verticalSummetry_right(self): - plt5 = self.imageMatrix().swapaxes(1, 0) - plt.imshow(plt5[:, ::-1]) + + plt5=self.imageRead().transpose(Image.ROTATE_270) + + plt.imshow(plt5) plt.show() return plt5 - # 垂直镜面(左旋转) - # transpose函数的作用就是调换数组的行列值的索引值,类似于求矩阵的转置 def verticalSummetry_lift(self): - plt7 = self.imageMatrix().transpose(1, 0, 2) # x,y轴转置 - plt.imshow(plt7[::-1]) + plt7 = self.imageRead().transpose(Image.ROTATE_90) + plt.imshow(plt7) plt.show() return plt7 - # 保存图片 def img_Save(self): root = "E:\\桌面\\Python_Picture_Analysis\\data\\" # 图片保存地址 diff --git a/Picture _Crawling.py b/Picture _Crawling.py deleted file mode 100644 index ad7ccd3..0000000 --- a/Picture _Crawling.py +++ /dev/null @@ -1,36 +0,0 @@ -# -*- coding: utf-8 -*- -# @Time : 2022-7-24 0024 11:18 -# @Author : Qing -# @Email : derighoid@gmail.com -# @File : Picture _Crawling.py -# @Software: PyCharm - -# 导入库 -import os -import requests - - -# path = '(?<=