scipy之图像处理

import matplotlib.pyplot as plt
from skimage import io,img_as_ubyte
from scipy import ndimage
import numpy as np 
import cv2 


img = io.imread("lena.jpg",as_gray=True)
img1 = cv2.imread("lena.jpg")

# 查看图像类型,大小,位
# print(type(img),img.shape,img.dtype)

# 查看(0,0)出的rgb像素
# print(img[0,0])

# 图像显示
# io.imshow(img[10:35,20:45])
# plt.show()

# 图像中灰度的平均值,最大值,最小值
# gray_mean = img.mean()
# gray_max = img.max()
# gray_min = img.min()
# print("平均值","最大值","最小值",gray_mean,gray_max,gray_min)

# 图像镜像
# img = img_as_ubyte(img)
# print(img)
# flippedLR = np.fliplr(img)
# flippedUd = np.flipud(img)
# flipped = np.flip(img)

# plt.subplot(221)
# plt.imshow(img)
# plt.subplot(222)
# plt.imshow(flippedLR)
# plt.subplot(223)
# plt.imshow(flippedUd)
# plt.subplot(224)
# # numpy中的镜像会把颜色通道RGB翻转为BGR,可以通过cv转换回RGB
# flipped = cv2.cvtColor(flipped,cv2.COLOR_BGR2RGB)
# plt.imshow(flipped)
# plt.show()

# 图像旋转
# rotated = ndimage.rotate(img,45,reshape=True)
# plt.imshow(rotated)
# plt.show()

# 均值滤波,高斯滤波,中值滤波,最大值滤波,最小值滤波
uniform_filtered = ndimage.uniform_filter(img,size=9)
gaussian_filtered = ndimage.gaussian_filter(img,sigma=3)
median_filtered = ndimage.median_filter(img,size=3)
maximum_filtered = ndimage.maximum_filter(img,size=3)
minimum_filtered = ndimage.minimum_filter(img,size=3)
sobel_img = ndimage.sobel(img,axis=0)


plt.subplot(231)
plt.imshow(img,cmap="gray")
plt.subplot(232)
plt.imshow(uniform_filtered,cmap="gray")
plt.subplot(233)
plt.imshow(gaussian_filtered,cmap="gray")
plt.subplot(234)
plt.imshow(median_filtered,cmap="gray")
plt.subplot(235)
plt.imshow(maximum_filtered,cmap="gray")
plt.subplot(236)
plt.imshow(minimum_filtered,cmap="gray")
plt.show()

在这里插入图片描述

发布了59 篇原创文章 · 获赞 26 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/qq_28368377/article/details/104271864