- 图像处理的几种方法 1.使用skimage
name details name details name details astronaut 宇航员图片 coffee 一杯咖啡图片 lena lena图片 camera 拿相机的人图片 coins 硬币 moon 月亮 checkerboard 棋盘 horse 马 page 一页书 chelsea 小猫图片 hubble_deep_field 星空 text 文字 clock 时钟 immunohistochemistry 结肠 import numpy as np import scipy import matplotlib.pyplot as plt from skimage import io,data img=data.chelsea() img=io.imread('d:/python/loli.jpg') #读取图片 # img=io.imread('d:/python/loli.jpg',as_grey=True) #图片变换 [m,n,l]=img.shape img1=skimage.transform.resize(img,(int(m*0.6),int(n*0.6),l),mode='reflect') #保存图片 io.imsave('d:/python/loli1.jpg',img1) io.imshow(img1) plt.show() # 显示图片信息 print (type(img)) #显示类型 print (img.shape) #显示尺寸 print (img.shape[0]) #图片宽度 print (img.shape[1]) #图片高度 print (img.shape[2]) #图片通道数 print (img.size) #显示总像素个数 print (img.max()) #最大像素值 print (img.min()) #最小像素值 print (img.mean()) #像素平均值
C:ProgramDataAnaconda2libsite-packagesskimageutildtype.py:122: UserWarning: Possible precision loss when converting from float64 to uint8 .format(dtypeobj_in, dtypeobj_out))
2 使用scipy.misc(miscellaneous routines)不推荐,很多已经deprecated<type 'numpy.ndarray'> (415L, 518L, 3L) 415 518 3 644910 255 0 111.793140128
Various utilities that don’t have another home.
Note that Pillow (https://python-pillow.org/) is not a dependency of SciPy, but the image manipulation functions indicated in the list below are not available without it.Deprecated functions:
col 1 col 2 bytescale(*args, **kwds) bytescale is deprecated! fromimage(*args, **kwds) fromimage is deprecated! imfilter(*args, **kwds) imfilter is deprecated! imread(*args, **kwds) imread is deprecated! imresize(*args, **kwds) imresize is deprecated! imrotate(*args, **kwds) imrotate is deprecated! imsave(*args, **kwds) imsave is deprecated! imshow(*args, **kwds) imshow is deprecated! toimage(*args, **kwds) toimage is deprecated! from scipy import misc import matplotlib.pyplot as plt import numpy as np # 读取图片 img=misc.imread('d:/python/loli.jpg',mode='RGB') # 改变大小 img1=scipy.misc.imresize(img,(111,80),interp='nearest') # 显示图片 #misc.imshow(img) have been deprecated plt.imshow(img) plt.show() misc.imsave('d:/python/loli1.jpg',img)
3 使用PIL做图像处理3.1 Reading and Writing Images : open( infilename ) , save( outfilename )
3.2 Cutting and Pasting and Merging Images :
crop() : 从图像中提取出某个矩形大小的图像。它接收一个四元素的元组作为参数,各元素为(left, upper, right, lower),坐标系统的原点(0, 0)是左上角。
paste() :
merge()3.3 几何变换
box = (100, 100, 200, 200) region = im.crop(box) region.show() region = region.transpose(Image.ROTATE_180) region.show() im.paste(region, box) im.show()
#旋转一幅图片 def roll(image, delta): "Roll an image sideways" xsize, ysize = image.size delta = delta % xsize if delta == 0: return image part1 = image.crop((0, 0, delta, ysize)) part2 = image.crop((delta, 0, xsize, ysize)) image.paste(part2, (0, 0, xsize-delta, ysize)) image.paste(part1, (xsize-delta, 0, xsize, ysize)) return image
#简单的几何变换 out = im.resize((128, 128)) # out = im.rotate(45) #逆时针旋转 45 度角。 out = im.transpose(Image.FLIP_LEFT_RIGHT) #左右对换。 out = im.transpose(Image.FLIP_TOP_BOTTOM) #上下对换。 out = im.transpose(Image.ROTATE_90) #旋转 90 度角。 out = im.transpose(Image.ROTATE_180) #旋转 180 度角。 out = im.transpose(Image.ROTATE_270) #旋转 270 度角。
from PIL import Image im=Image.open('d:/python/loli.jpg') print im.format,im.size,im.mode im.show()
JPEG (518, 415) RGB
box = (100, 100, 200, 200) region = im.crop(box) region.show() region = region.transpose(Image.ROTATE_180) region.show() im.paste(region, box) im.show()
out = im.resize((128, 128)) # out = im.rotate(45) #逆时针旋转 45 度角。 out = im.transpose(Image.FLIP_LEFT_RIGHT) #左右对换。 out = im.transpose(Image.FLIP_TOP_BOTTOM) #上下对换。 out = im.transpose(Image.ROTATE_90) #旋转 90 度角。 out = im.transpose(Image.ROTATE_180) #旋转 180 度角。 out = im.transpose(Image.ROTATE_270) out.show()
- 以上是图像处理的几种方法的内容,更多 图像处理 python 的内容,请您使用右上方搜索功能获取相关信息。