计算两张图片的IOU

import cv2
import os
import numpy as np
from pathlib import Path
import time
from PIL import Image
import numpy as np

#Read images
img1 = np.array(Image.open(032439.413.jpg"))#标注图
img2 = np.array(Image.open(32439.413.png"))#pytorch图片
#print(img1.shape)
#print(img2.shape)


#convert unit8 to int numbers, then subtract, then 2D to 1D array
#subArr = np.subtract(img1[:, :, 0].tolist(), img2.tolist()).flatten()

intersection = np.sum(np.logical_and(img1, img2[:, :, 0]))
union = np.sum(np.logical_or(img1, img2[:, :, 0]))


#Intersection over Union
iou_score = intersection / union

print(iou_score)

报错:


Img1 should be the .jpg file that has 3 channels

If your image is 2D, just delete one of the ,: from the code

Or just delete the [:,:,0]

If it's 2D, just img1, if it's 3D img1[:, :, 0]

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值