From 079dd34037771c768d817f402ca52ce0576a2832 Mon Sep 17 00:00:00 2001 From: lan daiqing <3517283258@qq.com> Date: Tue, 26 Jul 2022 21:27:11 +0800 Subject: [PATCH] Third commit --- Blue_noise_sampling.py | 50 ++++++++++++++++++++++++ GUI.py | 12 ++++++ GammaCorrection.py | 39 +++++++++++++++++++ Image_Capture.py | 69 +++++++++++++++++++++++++++++++++ Image_Mix.py | 25 ++++++++++++ Modify_Pixels.py | 65 +++++++++++++++++++++++++++++++ Orientation_Modification.py | 76 +++++++++++++++++++++++++++++++++++++ Picture _Crawling.py | 36 ++++++++++++++++++ Picture_Reading.py | 73 +++++++++++++++++++++++++++++++++++ Subtractive_Algorithm.py | 60 +++++++++++++++++++++++++++++ main.py | 49 ++++++++++++++++++++++++ 11 files changed, 554 insertions(+) create mode 100644 Blue_noise_sampling.py create mode 100644 GUI.py create mode 100644 GammaCorrection.py create mode 100644 Image_Capture.py create mode 100644 Image_Mix.py create mode 100644 Modify_Pixels.py create mode 100644 Orientation_Modification.py create mode 100644 Picture _Crawling.py create mode 100644 Picture_Reading.py create mode 100644 Subtractive_Algorithm.py create mode 100644 main.py diff --git a/Blue_noise_sampling.py b/Blue_noise_sampling.py new file mode 100644 index 0000000..01cf7fe --- /dev/null +++ b/Blue_noise_sampling.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-26 0026 19:09 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : Blue_noise_sampling.py +# @Software: PyCharm + +''' +计算新图形(放大后或缩小后)的坐标点像素值对应于原图像中哪一个像素点填充的。 +src是原图,dst是新图,原来的图像宽度/高度除以新图像的宽度/高度可以得到缩放比例,假如是缩小图片括号内的数字小于1,放大则大于1,相当于系数,再乘以新图片的宽度/高度,就实现了缩放。 +''' + +from PIL import Image +import matplotlib.pyplot as plt +import numpy as np +import math + + +# # 最近邻插值算法 +# # dstH为新图的高;dstW为新图的宽 +# def blueNoiseSampl(img, dstH, dstW): +# scrH, scrW, t = img.shape # src原图的长宽 +# retimg = np.zeros((dstH, dstW, 3), dtype=np.uint8) +# for i in range(dstH - 1): +# for j in range(dstW - 1): +# scrx = round(i * (scrH / dstH)) +# scry = round(j * (scrW / dstW)) +# retimg[i, j] = img[scrx, scry] +# +# return retimg +# +# +# im_path = './data/th.png' +# image = np.array(Image.open(im_path)) +# +# plt.figure(figsize=(16, 8)) +# +# plt.subplot(1, 2, 1) +# plt.imshow(image) +# +# image1 = blueNoiseSampl(image, image.shape[0] * 2, image.shape[1] * 2) +# # 从array转换成image +# image1 = Image.fromarray(image1.astype('uint8')).convert('RGB') +# image1.save('./data/picture13.png') +# plt.subplot(1, 2, 2) +# plt.imshow(image1) +# plt.show() + + + diff --git a/GUI.py b/GUI.py new file mode 100644 index 0000000..d147813 --- /dev/null +++ b/GUI.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-25 0025 15:03 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : GUI.py +# @Software: PyCharm +import tkinter + +# git checkout -b "main" + +import tkinter +root =tkinter.Tk() diff --git a/GammaCorrection.py b/GammaCorrection.py new file mode 100644 index 0000000..dbea8a1 --- /dev/null +++ b/GammaCorrection.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-26 0026 11:41 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : GammaCorrection.py +# @Software: PyCharm +''' +gamma矫正公式: +f(x)=xγ +即输出是输入的幂函数,指数为γ. +''' +import matplotlib.pyplot as plt +import numpy as np +from PIL import Image + +root = "E:\\桌面\\Python_Picture_Analysis\\data\\" + + +def gammaCorrect(filePath,val): + im = Image.open(filePath) + img = np.array(im) + + img1 = np.power(img / float(np.max(img)), 1 / 1.5) + img2 = np.power(img / float(np.max(img)), val) + + plt.subplot(131) + plt.imshow(img) + plt.title("origin") + plt.subplot(132) + plt.imshow(img1) + plt.title("gammar=1/1.5") + plt.subplot(133) + plt.imshow(img2) + plt.title("user-defined") + plt.show() + Image.fromarray(np.uint8(img2)).save(root + 'picture10' + '.jpg') + return img2 + + diff --git a/Image_Capture.py b/Image_Capture.py new file mode 100644 index 0000000..5094d2f --- /dev/null +++ b/Image_Capture.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-26 0026 15:46 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : Image_Capture.py +# @Software: PyCharm + +import matplotlib.pyplot as plt +import numpy as np +from PIL import Image + +root = "E:\\桌面\\Python_Picture_Analysis\\data\\" + + +def imgCut(path, left, upper, right, lower): + """ + :param path: 图片路径 + :param left:与左边界的距离 + :param upper:与上边界的距离 + :param right:与有边界的距离 + :param lower:与底部边界的距离 + :return: + """ + img = Image.open(path) + print(img.size) + part = (left, upper, right, lower) + + cut_img = img.crop(part) + + plt.figure("image Cut") + plt.subplot(121) + plt.title("origin") + plt.imshow(img) + + plt.subplot(122) + plt.title("CUT part") + plt.imshow(cut_img) + plt.show() + + Image.fromarray(np.uint8(cut_img)).save(root + "picture11.jpg") + + return cut_img + + +def imgReplace(path1, path2, left2, upper2, right2, lower2): + """ + :param path1: 被替换图片的路径 + :param path2: 替换的图片路径 + :param left2, upper2, right2, lower2:替换图片的大小 + :return: + """ + + img1 = Image.open(path1) + img2 = Image.open(path2) + + part2 = (left2, upper2, right2, lower2) + cut_img2 = img2.crop(part2) + + img1.paste(cut_img2, (10, 50, 250, 250)) + + plt.figure("picture replace") + plt.subplot(121) + plt.imshow(img2) + + plt.subplot(122) + plt.imshow(img1) + plt.show() + Image.fromarray(np.uint8(img1)).save(root + 'picture12.jpg') + return img1 diff --git a/Image_Mix.py b/Image_Mix.py new file mode 100644 index 0000000..e55f103 --- /dev/null +++ b/Image_Mix.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-26 0026 17:44 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : Image_Mix.py +# @Software: PyCharm + +from PIL import Image +import matplotlib.pyplot as plt +import numpy as np +import cv2 +# 阿尔法图像混合 +def imageMix(imagePath1, imagePath2): + img1 = Image.open(imagePath1) + im1 = np.array(img1) + img2 = Image.open(imagePath2) + im2 = np.array(img2) + + img3 = cv2.addWeighted(im1, 0.8, im2, 0.3, 0) + + plt.imshow(img3) + Image.fromarray(np.uint8(img3)).save("./data/picture14.png") + plt.show() + + diff --git a/Modify_Pixels.py b/Modify_Pixels.py new file mode 100644 index 0000000..72d5687 --- /dev/null +++ b/Modify_Pixels.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-24 0024 16:42 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : Modify_Pixels.py +# @Software: PyCharm + +import os + +# 导入库 +import matplotlib.pyplot as plt +import numpy as np +from PIL import Image + + +class modfifyImage(): + def __init__(self, filePath): + self.filePath = filePath + + # 图片读取 + def imageRead(self): + if self.filePath == " ": + print("Please full in the file path") + else: + face = Image.open(self.filePath) + return face + + # 图片转矩阵 + def imageMatrix(self): + im = np.array(self.imageRead()) + return im + + # 图片像素反转 + def pixInversion(self): + im2 = 255 - self.imageMatrix() + plt.figure() + plt.imshow(im2) + plt.show() + return im2 + + # 显示图像三通道颜色 + def img_RGB(self): + root="E:\\桌面\\Python_Picture_Analysis\\data\\" # 图片保存地址 + red = self.imageMatrix().copy() + red[:, :, 1:3] = 0 + green = self.imageMatrix().copy() + green[:, :, ::2] = 0 + blue = self.imageMatrix().copy() + blue[:, :, :2] = 0 + 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') + Image.fromarray(np.uint8(blue)).save(root + 'picture2' + '.jpg') + Image.fromarray(np.uint8(green)).save(root + 'picture3' + '.jpg') + plt.show() + return red,green,blue + + # 获得该点的类型 + def get_imgType(self, x, y): + return type(self.imageMatrix()[x, y]) \ No newline at end of file diff --git a/Orientation_Modification.py b/Orientation_Modification.py new file mode 100644 index 0000000..22e11c3 --- /dev/null +++ b/Orientation_Modification.py @@ -0,0 +1,76 @@ +# -*- coding: utf-8 -*- +# @Time : 2022-7-25 0025 10:46 +# @Author : Qing +# @Email : derighoid@gmail.com +# @File : Orientation_Modification.py +# @Software: PyCharm + +import os + +# 导入库 +import matplotlib.pyplot as plt +import numpy as np +from PIL import Image + +class directionChanges(): + def __init__(self, filePath): + self.filePath = filePath + + # 图片读取 + def imageRead(self): + face3 = Image.open(self.filePath) + return face3 + + # 图片上矩阵化 + def imageMatrix(self): + im3 = np.array(self.imageRead()) + return im3 + + def imageRepetition(self): + # 图像重复 + # 先水平方向两次,再垂直方向3次 + plt1 = np.concatenate((self.imageMatrix(), self.imageMatrix()), axis=1) + plt2 = np.concatenate((plt1, plt1, plt1), axis=0) + plt.imshow(plt2) + plt.show() + # # 先垂直方向转3次,再水平方向转4次 + plt3 = np.concatenate((self.imageMatrix(), self.imageMatrix(), self.imageMatrix()), axis=0) + plt4 = np.concatenate((plt3, plt3, plt3, plt3), axis=1) + plt.imshow(plt4) + plt.show() + return plt2 + + # 图像水平镜面对称 + def mirrorSymmetry(self): + plt6 = self.imageMatrix()[::-1] + plt.imshow(plt6) + plt.show() + return plt6 + + # 垂直对称(右旋转) + def verticalSummetry_right(self): + plt5 = self.imageMatrix().swapaxes(1, 0) + plt.imshow(plt5[:, ::-1]) + plt.show() + return plt5 + + # 垂直镜面(左旋转) + # transpose函数的作用就是调换数组的行列值的索引值,类似于求矩阵的转置 + def verticalSummetry_lift(self): + plt7 = self.imageMatrix().transpose(1, 0, 2) # x,y轴转置 + plt.imshow(plt7[::-1]) + plt.show() + return plt7 + + # 保存图片 + def img_Save(self): + root = "E:\\桌面\\Python_Picture_Analysis\\data\\" + if not os.path.exists(root): + os.mkdir(root) + else: + Image.fromarray(np.uint8(self.imageRepetition())).save(root+'picture4'+'.jpg') + Image.fromarray(np.uint8(self.mirrorSymmetry())).save(root+'picture5'+'.jpg') + Image.fromarray(np.uint8(self.verticalSummetry_right())).save(root+'picture6'+'.jpg') + Image.fromarray(np.uint8(self.verticalSummetry_lift())).save(root+'picture7'+'.jpg') + + diff --git a/Picture _Crawling.py b/Picture _Crawling.py new file mode 100644 index 0000000..ad7ccd3 --- /dev/null +++ b/Picture _Crawling.py @@ -0,0 +1,36 @@ +# -*- 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 = '(?<=