skimage 学习笔记

目录

安装:

图像分割:

裁剪图像并缩放:

彩色图像相似度:


安装:

conda install scikit-image

img_as_ubyte转为uint8格式,0-255,转为普通图像,举例:

>>> from skimage import img_as_ubyte
>>> image = np.array([0, 0.5, 1], dtype=float)
>>> img_as_ubyte(image)
WARNING:dtype_converter:Possible precision loss when converting from
float64 to uint8
array([  0, 128, 255], dtype=uint8)

图像分割:

能区分比别的地方黑的物体,但是老鼠排除不了:

import matplotlib.pyplot as plt
from skimage import io, filters

# skimage提供了io模块,顾名思义,这个模块是用来图片输入输出操作的。
img = io.imread(r"E:\new\01.jpg")

val = filters.threshold_otsu(img)
mask=(img <= val*0.9)*1.0

# io.imsave("aa.jpg",mask)
plt.figure("lena.jpg")
plt.imshow(mask)
plt.axis('off')
plt.show()

裁剪图像并缩放:

    def process(self, image, bbox):
        ''' process image with crop operation.
        Args:
            input: (h,w,3) array or str(image path). image value range:1~255.
            image_info(optional): the bounding box information of faces. if None, will use dlib to detect face.

        Returns:
            pos: the 3D position map. (256, 256, 3).
        '''
        if image.ndim < 3:
            image = np.tile(image[:, :, np.newaxis], [1, 1, 3])

        left = bbox[0]
        right = bbox[2]
        top = bbox[1]
        bottom = bbox[3]
        old_size = (right - left + bottom - top) / 2
        center = np.array([right - (right - left) / 2.0, bottom - (bottom - top) / 2.0 + old_size * 0.14])
        size = int(old_size * 1.318)

        # crop image
        src_pts = np.array([[center[0] - size / 2, center[1] - size / 2], [center[0] - size / 2, center[1] + size / 2],
                            [center[0] + size / 2, center[1] - size / 2]])
        DST_PTS = np.array([[0, 0], [0, self.resolution_inp - 1], [self.resolution_inp - 1, 0]])
        tform = estimate_transform('similarity', src_pts, DST_PTS)

彩色图像相似度:

import cv2
from skimage.metrics import structural_similarity as compare_ssim

image1 = cv2.imread(r'F:\194536.jpg')
image2 = cv2.imread(r'F:\194536.jpg')

ssim_value = compare_ssim(image1, image2, multichannel=True,channel_axis=2)

print("SSIM value:", ssim_value)

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

AI算法网奇

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值