图像分割函数

#图片分割函数
import cv2
import matplotlib.pyplot as plt
img=cv2.imread("test.png")
#转换成RGB格式
img=img[:,:,::-1]
#arr接受原图像 shape接受一个元组或者列表 如分割成2x3 
def parte(arr,shape):
	#算出横向和纵向步长
    width=int(arr.shape[1]/shape[1])
    height=int(arr.shape[0]/shape[0])
    print(height,width)
    
    #分图列表
    arrs=[]
    for i in range(shape[0]):
        for j in range(shape[1]):
        	#制作分图
            temp_array=arr[i*height:(i+1)*height,j*width:(j+1)*width]
            arrs.append(temp_array)
            
    plt.figure(dpi=160)
    for i in range(shape[0]*shape[1]):
        plt.subplot(shape[0],shape[1],i+1)
        plt.imshow(arrs[i])
    plt.show()
 #调用函数   
arr_part=parte(img,[2,3])

查看效果
在这里插入图片描述

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值