python制作图像数据集_python_增加图像数据集方法

1.旋转

dir_path='/Users/xxxx/Desktop/Share Folder/png&dat/timg.jpeg‘

img=cv2.imread(dir_path)

imgInfo = img.shape

height= imgInfo[0]

width = imgInfo[1]

deep = imgInfo[2]

matRotate = cv2.getRotationMatrix2D((height*0.5, width*0.5), 45, 1)

dst = cv2.warpAffine(img, matRotate, (height, width))

原图:

4e62e6d6b7955efb38393a1f929b1d02.png

旋转后的图像:

547b7527d88586733bab2b2ac494a2b8.png

2.翻转

dir_path='/Users/xxxx/Desktop/Share Folder/png&dat/timg.jpeg‘

img=cv2.imread(dir_path)

imgInfo = img.shape

height= imgInfo[0]

width = imgInfo[1]

deep = imgInfo[2]

matRotate = cv2.getRotationMatrix2D((height*0.5, width*0.5), 180, 1)

dst = cv2.warpAffine(img, matRotate, (height, width))

得到图像为:

efe731288e8eeca2dcff17069fb0697e.png

3.缩放

dir_path='/Users/xxxx/Desktop/Share Folder/png&dat/timg.jpeg‘

img=cv2.imread(dir_path)

dstHeight = int(height * 0.5)

dstWeight = int(width * 0.5)

dst = cv2.resize(img, (dstWeight,dstHeight))

得到图像为:

12a67350231bec67a420d730671435c5.png

4.裁剪:

dir_path='/Users/xxxx/Desktop/Share Folder/png&dat/xiaoya.png'

img=cv2.imread(dir_path)

dst = img[100:400,50:500]

原图:

130f4641a4d53ab11b231d7d491495aa.png

生成图像:

59994e9097741a4eaceb8ae34e7f7f04.png

5:平移:

dir_path='/Users/xxxxx/Desktop/Share Folder/png&dat/xiaoya.png'

img=cv2.imread(dir_path)

imgInfo = img.shape

height= imgInfo[0]

width = imgInfo[1]

deep = imgInfo[2]

dst = np.zeros(imgInfo, np.uint8)

for i in range( height ):

for j in range( width - 100 ):

dst[i, j + 100] = img[i, j]

得到图像:

cc90bdc6ac8e16b9343f61f4b078309c.png

6:加噪_椒盐噪声盐点

def salt(src,percentage):

NoiseImg=src

rows,cols,_=NoiseImg.shape

NoiseNum=int(percentage*rows*cols)

for i in range(NoiseNum):

randX=np.random.randint(0,rows-1)

randY=np.random.randint(0,cols-1)

if random.randint(0,1)<=0.5:

NoiseImg[randX,randY]=255

else:

NoiseImg[randX,randY]=NoiseImg[randX,randY]

return NoiseImg

dir_path='/Users/xxxxx/Desktop/Share Folder/png&dat/xiaoya.png'

img=cv2.imread(dir_path)

img=salt(img,0.01)

得到图像为:

4019f250191413cee0db4352d0ee1299.png

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值