栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Python

pytorch 图像前处理

Python 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

pytorch 图像前处理

记录一些常用的前处理,每次都重写也是很费劲。。

```python

import cv2
import numpy as np

# 不失真resize 在resize时加上黑边
def distortionless_resize(img_org,target_size = (112,112)):
	h,w,c = img_org.shape
	target_w,target_h = target_size
	if target_h==target_w:
	    if h==w:
	    	new_img = cv2.resize(img_org,target_size)
		elif h>w:
			new_img = np.zeros((h,h,3),np.uint8)
			new_img[:,int(h-w)//2:int(h-w)//2+w,:]=img_org
			new_img = cv2.resize(new_img,target_size)

		else:
			new_img = np.zeros((w,w,3),np.uint8)
			new_img[int(w-h)//2:int(w-h)//2+w,:,:]
			new_img = cv2.resize(new_img,target_size)
	else:
		scale = h/w
		target_scale = target_h/target_w
		if scale-target_scale<1e-3:
			new_img = cv2.resize(img_org,target_size)
		elif scale 
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/487449.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号