网站首页 > 精选文章 / 正文
使用Python可以方便的开发一些图像处理的小工具 ,比如图片常做的对比度提高、边缘检测、立体感增强 ,话不多说直接肝代码!!
对比度提高:
使用Python中的OpenCV库可以实现对比度的调整
import cv2
# 加载图像
image = cv2.imread('example.jpg')
# 增加对比度
alpha = 1.5
adjusted_image = cv2.convertScaleAbs(image, alpha=alpha, beta=0)
# 显示结果
cv2.imshow('Adjusted Image', adjusted_image)
cv2.waitKey(0)
边缘检测
使用Python中的OpenCV库可以实现常见的边缘检测算法
import cv2
# 加载图像
image = cv2.imread('example.jpg')
# 边缘检测
canny = cv2.Canny(image, 100, 200)
# 显示结果
cv2.imshow('Canny Edge Detection', canny)
cv2.waitKey(0)
立体感增强:
使用Python中的Pillow库可以实现图像的立体感增强
from PIL import Image, ImageFilter
# 加载图像
image = Image.open('example.jpg')
# 应用滤镜
blur_radius = 10
blurred_image = image.filter(ImageFilter.GaussianBlur(radius=blur_radius))
# 将原图像和模糊图像进行融合
alpha = 0.5
merged_image = Image.blend(image, blurred_image, alpha)
# 显示结果
merged_image.show()
Envelope Plot
画包络图(Envelope Plot)可以用于显示数据点的范围,常用于信号处理和数据分析中。在Python中,可以使用Matplotlib库绘制包络图
import numpy as np
import matplotlib.pyplot as plt
# 生成数据
t = np.linspace(0, 2*np.pi, 100)
x = np.sin(t) + np.random.normal(0, 0.1, size=100)
y = np.cos(t) + np.random.normal(0, 0.1, size=100)
# 绘制数据点
plt.plot(x, y, '.', color='blue', markersize=5, label='Data')
# 计算包络线
from scipy.signal import savgol_filter
window_length = 21
polyorder = 2
x_envelope = savgol_filter(x, window_length, polyorder, deriv=0)
y_envelope = savgol_filter(y, window_length, polyorder, deriv=0)
# 绘制包络线
plt.plot(x_envelope, y_envelope, color='red', linewidth=2, label='Envelope')
# 设置图例和标题
plt.legend()
plt.title('Envelope Plot')
# 显示图像
plt.show()
Tags:deriv
- 上一篇:神经网络算法入门
- 下一篇:Python 数据分析——NumPy 函数库
猜你喜欢
- 2025-01-13 Python 数据分析——NumPy 函数库
- 2025-01-13 神经网络算法入门
- 2025-01-13 OpenCV4 中各模块函数整理
- 2025-01-13 一篇文章让你了解Elasticsearch搜索
- 2025-01-13 神经网络(BP)算法Python实现及应用!
- 2025-01-13 边缘检测(Canny、Sobel、Scharr)
- 2025-01-13 栅格着色器:最完善的实现
- 2025-01-13 【源码】效果最好的网格Shader(迄今为止)