python的数字图像处理学习(2)
图像的重定义大小,图像的缩扩,图像的旋转:
from skimage import transform,data
import matplotlib.pyplot as plt
img = data.camera()
print(img.shape)
plt.subplot(221)
plt.imshow(img)
plt.subplot(222)
plt.imshow(transform.resize(img,(64,64)))
plt.subplot(223)
plt.imshow(transform.rescale(img,0.2))
plt.subplot(224)
plt.imshow(transform.rotate(img,30,resize=True))
plt.show()
产生高斯金字塔
import numpy as np
import matplotlib.pyplot as plt
from skimage import data,transform
image = data.astronaut() #载入宇航员图片
pyramid = transform.pyramid_gaussian(image, downscale=2) #产生高斯金字塔图像
#pyramid = transform.pyramid_laplacian(image, downscale=2)
#共生成了log(512)=9幅金字塔图像,加上原始图像共10幅,pyramid[0]-pyramid[1]
i = 1
for p in pyramid:
plt.subplot(2,5,i)
i+=1
#p[:,:,:]*=255
plt.title(p.shape)
plt.imshow(p)
plt.show()
gamma调整原理:I=Ig 如果gamma>1, 新图像比原图像暗。如果gamma<1,新图像比原图像亮
log对数调整I=log(I)
对比度是否偏低判断:exposure.is_low_contrast(img)
from skimage import data, exposure, img_as_float
import matplotlib.pyplot as plt
image = img_as_float(data.moon())
gam1= exposure.adjust_gamma(image, 4) #调暗
gam2= exposure.adjust_gamma(image, 0.7) #调亮
gam3= exposure.adjust_log(image) #对数调整
plt.figure('adjust_gamma',figsize=(10,10))
plt.subplot(141)
plt.imshow(image)
plt.subplot(142)
plt.imshow(gam1)
plt.subplot(143)
plt.imshow(gam2,plt.cm.gray)
plt.subplot(144)
plt.imshow(gam3)
plt.show() #原理:I=Ig
result=exposure.is_low_contrast(gam1)
result
调整图片强度,不是很懂参数...
import numpy as np
from skimage import exposure
image = data.moon()
mat=exposure.rescale_intensity(image,out_range=(0,100))
plt.subplot(121)
plt.imshow(mat)
print(image)
print(mat)
mat1=exposure.rescale_intensity(image, in_range=(0, 200))
plt.subplot(122)
plt.imshow(mat1)
print(mat1.min())
print(mat1)
绘制直方图
from skimage import data
import matplotlib.pyplot as plt
img=data.camera()
plt.figure("hist")
arr=img.flatten()
n, bins, patches = plt.hist(arr, bins=256, normed=1,facecolor='red')
plt.show()
彩色图片三通道直方图:
from skimage import data
import matplotlib.pyplot as plt
img=data.astronaut()
ar=img[:,:,0].flatten()
plt.hist(ar, bins=256, normed=1,facecolor='r',edgecolor='r',hold=1)
ag=img[:,:,1].flatten()
plt.hist(ag, bins=256, normed=1, facecolor='g',edgecolor='g',hold=1)
ab=img[:,:,2].flatten()
plt.hist(ab, bins=256, normed=1, facecolor='b',edgecolor='b')
plt.show()
直方图均衡化exposure.equalize_hist(img)
对图像中像素个数多的灰度级进行展宽,而对图像中像素个数少的灰度进行压缩,从而扩展取值的动态范围,提高了对比度和灰度色调的变化,使图像更加清晰。
from skimage import data,exposure
import matplotlib.pyplot as plt
img=data.moon()
plt.figure("hist",figsize=(8,8)) arr=img.flatten()
plt.subplot(221)
plt.imshow(img,plt.cm.gray) #原始图像
plt.subplot(222)
plt.hist(arr, bins=256, normed=1,edgecolor='None',facecolor='red') #原始图像直方图 img1=exposure.equalize_hist(img)
arr1=img1.flatten()
plt.subplot(223)
plt.imshow(img1,plt.cm.gray) #均衡化图像
plt.subplot(224)
arr1*=255
plt.hist(arr1, bins=256, normed=1,edgecolor='None',facecolor='red') #均衡化直方图 plt.show()
图像滤波:
平滑滤波,用来抑制噪声;微分算子,可以用来检测边缘和特征提取。
sobel、roberts、scharr、prewitt、canny算子
gabor、gaussian、median滤波
水平、垂直边缘检测
正负交叉边缘检测
from skimage import data,filters,feature
import matplotlib.pyplot as plt
from skimage.morphology import disk
img = data.camera()
edges = filters.sobel(img)
edges = filters.roberts(img)
edges = filters.scharr(img)
edges = filters.prewitt(img)
edges = feature.canny(img,sigma=3)
edges,filt_imag = filters.gabor(img, frequency=0.5)
edges = filters.gaussian(img,sigma=5)
edges = filters.median(img,disk(9))
edges = filters.sobel_h(img)
#水平边缘检测:sobel_h, prewitt_h, scharr_h
#垂直边缘检测: sobel_v, prewitt_v, scharr_v
edges = filters.roberts_neg_diag(img)
edges = filters.roberts_pos_diag(img)
plt.imshow(edges,plt.cm.gray)
图像阈值判断与分割的各种方法:
from skimage import data,filters
import matplotlib.pyplot as plt
image = data.camera()
thresh = filters.threshold_otsu(image)
thresh = filters.threshold_yen(image)
thresh = filters.threshold_li(image)
thresh = filters.threshold_isodata(image) dst =(image <= thresh)*1.0 #根据阈值进行分割
#dst =filters.threshold_adaptive(image, 31,'mean')
plt.subplot(121)
plt.title('original image')
plt.imshow(image,plt.cm.gray)
plt.subplot(122)
plt.title('binary image')
plt.imshow(dst,plt.cm.gray)
plt.show()
图形的绘制,与颜色。有各种各样的图形啊...
from skimage import draw,data
import matplotlib.pyplot as plt
img=data.chelsea()
rr, cc=draw.ellipse(150, 150, 30, 80) #返回像素坐标
draw.set_color(img,[rr,cc],[255,0,0])
plt.imshow(img,plt.cm.gray)
图像的膨胀,腐蚀
from skimage import data
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=data.checkerboard()
dst=sm.dilation(img,sm.square(5)) #用边长为15的正方形滤波器进行膨胀滤波
dst1=sm.erosion(img,sm.square(5)) #用边长为5的正方形滤波器进行膨胀滤波
plt.figure(figsize=(8,8))
plt.subplot(131)
plt.imshow(img,plt.cm.gray)
plt.subplot(132)
plt.imshow(dst,plt.cm.gray)
plt.subplot(133)
plt.imshow(dst1,plt.cm.gray)
#找到像素值为1的点,将它的邻近像素点都设置成这个值。1值表示白,0值表示黑,因此膨胀操作可以扩大白色值范围,压缩黑色值范围。一般用来扩充边缘或填充小的孔洞
#将0值扩充到邻近像素。扩大黑色部分,减小白色部分。可用来提取骨干信息,去掉毛刺,去掉孤立的像素。
图像开运算,图像闭运算:
from skimage import io,color,data
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=color.rgb2gray(data.camera())
dst=sm.opening(img,sm.disk(9)) #用边长为9的圆形滤波器进行膨胀腐蚀滤波
dst1=sm.closing(img,sm.disk(9)) #用边长为5的圆形滤波器进行腐蚀膨胀滤波
plt.figure(figsize=(10,10))
plt.subplot(131)
plt.imshow(img,plt.cm.gray)
plt.subplot(132)
plt.imshow(dst,plt.cm.gray)
plt.subplot(133)
plt.imshow(dst1,plt.cm.gray)
白帽(white-tophat)。黑帽(black-tophat)。
from skimage import io,color
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=color.rgb2gray(data.camera())
dst=sm.white_tophat(img,sm.square(21)) #将原图像减去它的开运算值,返回比结构化元素小的白点
dst1=sm.black_tophat(img,sm.square(21)) #将原图像减去它的闭运算值,返回比结构化元素小的黑点,且将这些黑点反色。
plt.figure('morphology',figsize=(10,10))
plt.subplot(131)
plt.imshow(img,plt.cm.gray)
plt.subplot(132)
plt.imshow(dst,plt.cm.gray)
plt.subplot(133)
plt.imshow(dst1,plt.cm.gray)
python的数字图像处理学习(2)的更多相关文章
- python的数字图像处理学习(3)
高级滤波: from skimage import data,color,data_dir import matplotlib.pyplot as plt from skimage.morpholog ...
- python的数字图像处理学习(1)
导入原有的测试图片,测试图片路径,和一些方法,显示出测试图像,测试图像路径. from skimage import io,data,data_dir img_rgb=data.chelsea() i ...
- 【笔记】基于Python的数字图像处理
[博客导航] [Python相关] 前言 基于Python的数字图像处理,离不开相关处理的第三方库函数.搜索网络资源,列出如下资源链接. Python图像处理库到底用哪家 python计算机视觉编程— ...
- 数字图像处理学习笔记之一 DIP绪论与MATLAB基础
写在前面的话 数字图像处理系列的学习笔记是作者结合上海大学计算机学院<数字图像处理>课程的学习所做的笔记,使用参考书籍为<冈萨雷斯数字图像处理(第二版)(MATLAB版)>,同 ...
- MATLAB数字图像处理学习笔记
我们都知道一幅图片就相当于一个二维数组,可以用一个矩阵来表示,而MATLAB可以说就是为矩阵运算而生的,所以学习图像处理,学习MATLAB势在必行! 一. MATLAB基础知识 1. 读取图像 %im ...
- 初始----python数字图像处理--:环境安装与配置
一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...
- 数字图像处理(一)之灰度转换和卷积python实现
使用Python实现数字图像处理中如下功能: 彩色图像转成灰度图像 实现图像的相关&卷积操作 实现图像的高斯核卷积 使用的库和python版本如下: imageio:2.9.0 用于读取磁盘中 ...
- python数字图像处理(17):边缘与轮廓
在前面的python数字图像处理(10):图像简单滤波 中,我们已经讲解了很多算子用来检测边缘,其中用得最多的canny算子边缘检测. 本篇我们讲解一些其它方法来检测轮廓. 1.查找轮廓(find_c ...
- python数字图像处理(1):环境安装与配置
一提到数字图像处理编程,可能大多数人就会想到matlab,但matlab也有自身的缺点: 1.不开源,价格贵 2.软件容量大.一般3G以上,高版本甚至达5G以上. 3.只能做研究,不易转化成软件. 因 ...
随机推荐
- as3.0用了视频组件,导致视频打开后就全屏,加一下代码就行
myFlv.fullScreenTakeOver = false; fullScreenTakeOver : Boolean 舞台进入全屏模式时,FLVPlayback 组件位于所有内容的顶部并占据整 ...
- Django2.1在根据models生成数据库表时报 __init__() missing 1 required positional argument: 'on_delete'
解决办法: a=models.ForeignKey('BookInfo',on_delete=models.CASCADE,) 即在外键值的后面加上 on_delete=models.CASCADE ...
- Codeforces Round #520 (Div. 2)
Codeforces Round #520 (Div. 2) https://codeforces.com/contest/1062 A #include<bits/stdc++.h> u ...
- Linux 有线 校园网
1.首先在ifconfig命令在终端查看自己的ip地址,然后记录下来 2.然后用sudo -i 命令转换到root权限下 3.在自己家目录下输入pppoeconf 4.遇到username时,讲自己的 ...
- express 学习札记
Enjoy yourself! 祝你玩得开心! I have no idea. 我没有头绪. I just made it! 我做到了! I’ll see to it 我会留意的. Express ...
- [Codeforces_713A]Sonya and Queries
题目链接 http://codeforces.com/problemset/problem/713/A 题意 三种操作: + ai 集合里加一个整数ai,相同数记为多个. - ai 集合里减一个 ...
- Java_5.2 数组应用:*的打印
1五行五列的* ************************* public static void main(String[] args) { for (int i = 1; i <= 5 ...
- gearman的持久化,以mysql的方式
1.为什么要持久化? gearman的job server中的工作队列存储在内存中,一旦服务器有未处理的任务时重启或者宕机,那么这些任务就会丢失.持久化存储队列可以允许添加后台任务,并将其存储在外部的 ...
- ListView的自定义适配器及其优化(listView序号混乱问题的处理)
ListView是最常使用的android组件之一,关于listView的优化问题刚刚了解了一些,在这里做出总结. PS:如果想让ListView中的item根据数据内容显示item的大小,需要在it ...
- 安全概念:DMZ(非军事化区,隔离区)
DMZ是英文“demilitarized zone”的缩写,中文名称为“隔离区”,也称“非军事化区”.它是为了解决安装防火墙后外部网络不能访问内部网络服务器的问题,而设立的一个非安全系统与安全系统之间 ...