踩坑:skimage中对图像做的归一化处理

 skimage在读使用io.imread读取灰度图像时(as_grey=True / as_gray=True)会做归一化处理数据类型转化为float64;

图像缩放transform.resize同样会将uint8的图像转化为float64类型,这里注意的是!!!!!!!如果已经归一化,但是类型依然是uint8的图像,在缩放之后图像的范围将不再是(0-1)。

总结:skimage需要慎用,cv2,PIL都挺好用的!

import skimage
from skimage import io,transform
import numpy as np
image= io.imread('test.jpg',as_grey=False)
# 第一个参数是文件名可以是网络地址,第二个参数默认为False,True时为灰度图
print type(image) # out: numpy.ndarray
print image.dtype # out: dtype('uint8')
print image.shape # out: (300, 400, 3) (h,w,c)前面介绍了ndarray的特点
# mode也是RGB
print image
'''
注意此时image里都是整数uint8,范围[0-255]
array([
        [ [143, 198, 201 (dim=3)],[143, 198, 201],... (w=200)],
        [ [143, 198, 201],[143, 198, 201],... ],
        ...(h=100)
      ], dtype=uint8)

'''
image= io.imread('test.jpg',as_grey=True)
print image.shape # out: (300, 400)
print image
'''
此时image范围变为[0-1]
array([[ 0.73148549,  0.73148549,  0.73148549, ...,  0.73148549,
         0.73148549,  0.73148549],
       [ 0.73148549,  0.73148549,  0.73148549, ...,  0.73148549,
       .....]])
'''
print image.dtype # out: dtype('float64')

image = io.imread('test.jpg',as_grey=False) 
# h*w
image = transform.resize(image,(100, 200),order=1) # order默认是1,双线性
#resize后image范围又变成[0-1]
print image.dtype # out: dtype('float64')
print image.shape # out: (100, 200, 3)
print image
'''
array([[[ 0.56078431,  0.77647059,  0.78823529],
        [ 0.56078431,  0.77647059,  0.78823529],
        [ 0.56078431,  0.77647059,  0.78823529],
        ..., ...]])
'''
'''
resize函数接口
resize(image, output_shape, order=1, mode='constant', cval=0, clip=True, preserve_range=False)
order : int, optional
        The order of interpolation. The order has to be in the range 0-5:
         - 0: Nearest-neighbor
         - 1: Bi-linear (default)
         - 2: Bi-quadratic
         - 3: Bi-cubic
         - 4: Bi-quartic
         - 5: Bi-quintic

'''
print skimage.img_as_float(image).dtype # out: float64
# img_as_float可以把image转为double,即float64
--------------------- 
作者:爆米花好美啊 
来源:优快云 
原文:https://blog.youkuaiyun.com/u013010889/article/details/54347089 
版权声明:本文为博主原创文章,转载请附上博文链接!

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值