当前位置: 首页 > news >正文

电商代运营公司十强福州短视频seo平台

电商代运营公司十强,福州短视频seo平台,wordpress自定义上传头像,手机百度收录提交入口文章目录 常用图像增强技术调整大小灰度变换标准化随机旋转中心剪切随机裁剪高斯模糊亮度、对比度和饱和度调节水平翻转垂直翻转高斯噪声随机块中心区域 常用图像增强技术 图像增强技术是常用于数据增强的方法#xff0c;可以帮助增加数据集中图像的多样性#xff0c;提高深… 文章目录 常用图像增强技术调整大小灰度变换标准化随机旋转中心剪切随机裁剪高斯模糊亮度、对比度和饱和度调节水平翻转垂直翻转高斯噪声随机块中心区域 常用图像增强技术 图像增强技术是常用于数据增强的方法可以帮助增加数据集中图像的多样性提高深度学习模型的性能和泛化能力。 调整大小Resize 调整图像的尺寸通常用于将图像缩放到模型输入的期望尺寸。 灰度变换Grayscale Transformation 将彩色图像转换为灰度图像降低图像的复杂度常用于处理黑白图像。 标准化Normalization 对图像的像素值进行标准化处理将像素值缩放到一个特定的范围例如[0, 1]或[-1, 1]有助于加速模型的训练。 随机旋转Random Rotation 在一定角度范围内对图像进行随机旋转增加模型对旋转变换的鲁棒性。 中心裁剪Center Crop 将图像从中心位置裁剪到指定的尺寸常用于处理物体识别任务。 随机裁剪Random Crop 在图像的随机位置进行裁剪增加模型对位置变换的适应性。 高斯模糊Gaussian Blur 对图像进行高斯模糊操作模糊图像降低图像中的噪声有助于模型学习更鲁棒的特征。 亮度、对比度调节Brightness and Contrast Adjustment 调整图像的亮度和对比度增加图像的光照变化提高模型的鲁棒性。 水平翻转Horizontal Flip 将图像水平翻转增加模型对图像翻转的适应性。 垂直翻转Vertical Flip 将图像垂直翻转增加模型对图像垂直翻转的适应性。 高斯噪声Gaussian Noise 向图像中添加高斯噪声增加图像的复杂性提高模型的鲁棒性。 随机块Random Patch 将图像的随机区域替换为随机像素值或者另外一幅图像的随机区域增加图像的多样性。 中心区域裁剪Center Area Crop 与中心裁剪类似但是不仅仅是将图像的中心裁剪出来还可以选择图像的其他区域进行裁剪增加多样性。 这些技术可以单独应用也可以组合使用根据具体任务和数据集的特点选择合适的增强方法以增加数据的多样性提高模型的性能和泛化能力。 调整大小 在开始图像大小的调整之前我们需要导入数据图像以眼底图像为例。 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(image/000001.tif)) torch.manual_seed(0) # 设置 CPU 生成随机数的 种子 方便下次复现实验结果 print(np.asarray(orig_img).shape) #(800, 800, 3)#图像大小的调整 resized_imgs [T.Resize(sizesize)(orig_img) for size in [128,256]] # plt.figure(resize:128*128) ax1 plt.subplot(131) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(132) ax2.set_title(resize:128*128) ax2.imshow(resized_imgs[0])ax3 plt.subplot(133) ax3.set_title(resize:256*256) ax3.imshow(resized_imgs[1])plt.show()首先导入了必要的Python库包括PILPython Imaging Library也叫Pillow用于图像处理、Pathlib用于操作文件路径、Matplotlib用于绘制图表以及NumPy和PyTorch用于数学计算和深度学习任务的库。 接着通过Image.open(Path(‘image/000001.tif’))语句从指定路径读取了一张tif格式的原始图像并将其存储在orig_img变量中。 然后通过torch.manual_seed(0)设置了PyTorch的随机数种子确保在每次运行代码时生成的随机数相同以便实验结果能够被复现。 接下来代码使用了PIL库中的Image类和torchvision.transforms模块中的T.Resize方法对原始图像进行了尺寸调整。具体地说它将原始图像分别调整为128x128和256x256两种不同大小的图像并将处理后的图像分别存储在resized_imgs列表的两个元素中。 最后使用Matplotlib库代码创建了一个包含三个子图subplot的图表。第一个子图ax1显示了原始图像第二个子图ax2显示了调整大小后的128x128图像第三个子图ax3显示了调整大小后的256x256图像。每个子图的标题用中文标注通过ax1.set_title(‘original’)、ax2.set_title(‘resize:128128’)和ax3.set_title(resize:256256’)语句分别设置。 最后通过plt.show()语句将这三个子图显示在屏幕上。 灰度变换 此操作将RGB图像转化为灰度图像。 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import torch import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png)) torch.manual_seed(0) # 设置 CPU 生成随机数的 种子 方便下次复现实验结果 print(np.asarray(orig_img).shape) #(800, 800, 3)gray_img T.Grayscale()(orig_img)# 将灰度图像转换为NumPy数组并确保数据类型为np.uint8 gray_array np.array(gray_img, dtypenp.uint8)# 显示灰度图像 plt.imshow(gray_array, cmapgray) plt.title(Grayscale Image) plt.axis(off) # 隐藏坐标轴 plt.show() 标准化 标准化可以加快基于神经网络结构的模型的计算速度加快学习速度。 从每个输入通道中减去通道平均值 将其除以通道标准差。 from PIL import Image import torch import torchvision.transforms as T# 打开并转换图像为RGB模式 orig_img Image.open(img_2.png).convert(RGB)# 使用torchvision.transforms.ToTensor()将PIL图像转换为PyTorch张量 tensor_img T.ToTensor()(orig_img)# 对图像进行归一化 normalized_img T.Normalize(mean(0.5, 0.5, 0.5), std(0.5, 0.5, 0.5))(tensor_img) normalized_img [T.ToPILImage()(normalized_img)]# 以下是您的绘图和显示代码 import matplotlib.pyplot as pltplt.rcParams[savefig.bbox] tightax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(normalize) ax2.imshow(normalized_img[0])plt.show() 随机旋转 设计角度旋转图像 from PIL import Image import torch import torchvision.transforms as T# 打开并转换图像为RGB模式 orig_img Image.open(img_2.png).convert(RGB)# 随机旋转角度范围为±30度 random_rotation T.RandomRotation(degrees30)# 使用torchvision.transforms.ToTensor()将PIL图像转换为PyTorch张量 tensor_img T.ToTensor()(orig_img)# 对图像进行随机旋转和归一化 transform T.Compose([random_rotation,T.ToTensor(),T.Normalize(mean(0.5, 0.5, 0.5), std(0.5, 0.5, 0.5)) ])transformed_img transform(orig_img) transformed_img_pil T.ToPILImage()(transformed_img)# 以下是您的绘图和显示代码 import matplotlib.pyplot as pltplt.rcParams[savefig.bbox] tightax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(transformed) ax2.imshow(transformed_img_pil)plt.show() 中心剪切 剪切图像的中心区域 from PIL import Image import torch import torchvision.transforms as T# 打开并转换图像为RGB模式 orig_img Image.open(img_2.png).convert(RGB)# 定义中心剪切的目标尺寸 crop_size (200, 200)# 随机旋转角度范围为±30度 random_rotation T.RandomRotation(degrees30)# 中心剪切 center_crop T.CenterCrop(crop_size)# 使用torchvision.transforms.ToTensor()将PIL图像转换为PyTorch张量 tensor_img T.ToTensor()(orig_img)# 对图像进行随机旋转、中心剪切和归一化 transform T.Compose([random_rotation,center_crop,T.ToTensor(),T.Normalize(mean(0.5, 0.5, 0.5), std(0.5, 0.5, 0.5)) ])transformed_img transform(orig_img) transformed_img_pil T.ToPILImage()(transformed_img)# 以下是您的绘图和显示代码 import matplotlib.pyplot as pltplt.rcParams[savefig.bbox] tightax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(transformed) ax2.imshow(transformed_img_pil)plt.show()随机裁剪 随机剪切图像的某一部分 from PIL import Image import torch import torchvision.transforms as T# 打开并转换图像为RGB模式 orig_img Image.open(img_2.png).convert(RGB)# 定义随机剪切的目标尺寸 crop_size (200, 200)# 随机剪切和随机旋转的组合 random_crop T.RandomResizedCrop(crop_size, scale(0.8, 1.0)) random_rotation T.RandomRotation(degrees30)# 使用torchvision.transforms.ToTensor()将PIL图像转换为PyTorch张量 tensor_img T.ToTensor()(orig_img)# 对图像进行随机剪切、随机旋转和归一化 transform T.Compose([random_crop,random_rotation,T.ToTensor(),T.Normalize(mean(0.5, 0.5, 0.5), std(0.5, 0.5, 0.5)) ])transformed_img transform(orig_img) transformed_img_pil T.ToPILImage()(transformed_img)# 以下是您的绘图和显示代码 import matplotlib.pyplot as pltplt.rcParams[savefig.bbox] tightax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(transformed) ax2.imshow(transformed_img_pil)plt.show() 高斯模糊 使用高斯核对图像进行模糊变换 from PIL import Image import torch import torchvision.transforms as T# 打开并转换图像为RGB模式 orig_img Image.open(img_2.png).convert(RGB)# 定义高斯模糊的卷积核大小 blur_radius 5# 高斯模糊和随机剪切的组合 gaussian_blur T.GaussianBlur(blur_radius) random_crop T.RandomResizedCrop((200, 200), scale(0.8, 1.0))# 使用torchvision.transforms.ToTensor()将PIL图像转换为PyTorch张量 tensor_img T.ToTensor()(orig_img)# 对图像进行高斯模糊、随机剪切和归一化 transform T.Compose([gaussian_blur,random_crop,T.ToTensor(),T.Normalize(mean(0.5, 0.5, 0.5), std(0.5, 0.5, 0.5)) ])transformed_img transform(orig_img) transformed_img_pil T.ToPILImage()(transformed_img)# 以下是您的绘图和显示代码 import matplotlib.pyplot as pltplt.rcParams[savefig.bbox] tightax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(transformed) ax2.imshow(transformed_img_pil)plt.show() 亮度、对比度和饱和度调节 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png)) # random_crops [T.RandomCrop(sizesize)(orig_img) for size in (832,704, 256)] colorjitter_img [T.ColorJitter(brightness(2,2), contrast(0.5,0.5), saturation(0.5,0.5))(orig_img)]plt.figure(resize:128*128) ax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img) ax2 plt.subplot(122) ax2.set_title(colorjitter_img) ax2.imshow(np.array(colorjitter_img[0])) plt.show()水平翻转 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png))HorizontalFlip_img [T.RandomHorizontalFlip(p1)(orig_img)]plt.figure(resize:128*128) ax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(colorjitter_img) ax2.imshow(np.array(HorizontalFlip_img[0]))plt.show()垂直翻转 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png))VerticalFlip_img [T.RandomVerticalFlip(p1)(orig_img)]plt.figure(resize:128*128) ax1 plt.subplot(121) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(122) ax2.set_title(VerticalFlip) ax2.imshow(np.array(VerticalFlip_img[0]))# ax3 plt.subplot(133) # ax3.set_title(sigma7) # ax3.imshow(np.array(blurred_imgs[1]))plt.show()高斯噪声 向图像中加入高斯噪声。通过设置噪声因子噪声因子越高图像的噪声越大 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png))def add_noise(inputs, noise_factor0.3):noisy inputs torch.randn_like(inputs) * noise_factornoisy torch.clip(noisy, 0., 1.)return noisynoise_imgs [add_noise(T.ToTensor()(orig_img), noise_factor) for noise_factor in (0.3, 0.6)] noise_imgs [T.ToPILImage()(noise_img) for noise_img in noise_imgs]plt.figure(resize:128*128) ax1 plt.subplot(131) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(132) ax2.set_title(noise_factor0.3) ax2.imshow(np.array(noise_imgs[0]))ax3 plt.subplot(133) ax3.set_title(noise_factor0.6) ax3.imshow(np.array(noise_imgs[1]))plt.show()随机块 正方形补丁随机应用在图像中。这些补丁的数量越多神经网络解决问题的难度就越大 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png))def add_random_boxes(img,n_k,size64):h,w size,sizeimg np.asarray(img).copy()img_size img.shape[1]boxes []for k in range(n_k):y,x np.random.randint(0,img_size-w,(2,))img[y:yh,x:xw] 0boxes.append((x,y,h,w))img Image.fromarray(img.astype(uint8), RGB)return imgblocks_imgs [add_random_boxes(orig_img,n_k10)]plt.figure(resize:128*128) ax1 plt.subplot(131) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(132) ax2.set_title(10 black boxes) ax2.imshow(np.array(blocks_imgs[0]))plt.show()中心区域 和随机块类似只不过在图像的中心加入补丁。 from PIL import Image from pathlib import Path import matplotlib.pyplot as plt import numpy as np import sys import torch import numpy as np import torchvision.transforms as Tplt.rcParams[savefig.bbox] tight orig_img Image.open(Path(img_2.png))def add_central_region(img, size32):h, w size, sizeimg np.asarray(img).copy()img_size img.shape[1]img[int(img_size / 2 - h):int(img_size / 2 h), int(img_size / 2 - w):int(img_size / 2 w)] 0img Image.fromarray(img.astype(uint8), RGB)return imgcentral_imgs [add_central_region(orig_img, size128)]plt.figure(resize:128*128) ax1 plt.subplot(131) ax1.set_title(original) ax1.imshow(orig_img)ax2 plt.subplot(132) ax2.set_title() ax2.imshow(np.array(central_imgs[0])) # # ax3 plt.subplot(133) # ax3.set_title(20 black boxes) # ax3.imshow(np.array(blocks_imgs[1]))plt.show()
http://www.pierceye.com/news/871472/

相关文章:

  • 有什么网站可以做一起作业什么网站可以兼职做效果图
  • 工程中标查询网站长沙网站制作作
  • 免费网站下载直播软件企业品牌网站建设类型
  • 建立网站并以此为基础从事经营活动的企业称为什么免费销售网站模板
  • 成都市建设质监站网站微信企业网站html5模板
  • 福建工程建设管理中心网站仙桃做企业网站的
  • 孝感做网站的公司建网站是永久的吗
  • 厦门手机建站php网站开发推荐书籍
  • 属于c2c网站的有哪几个方庄网站制作
  • 建设局网站模板iis 网站没有上传权限
  • 建设网站龙华怎么用自己的电脑搭建网站
  • 分析网站的网站福建交科建设有限公司官方网站
  • 深圳南园网站建设网站域名怎么设置方法
  • 网站的内链是什么意思网页布局有哪几种方法
  • 网站优化公司上海山东电力建设河北分公司网站
  • 甘肃省住房和城乡建设部网站首页专门网页制作工具有
  • 网站用vps做dns做网站的叫什么职位
  • 网站开发业务流程图网站商城与网站区别吗
  • 用新浪微博做网站百度找不到 网站
  • 哪个网站做照片书最好seo投放是什么意思
  • 书店网站开发目的和意义深圳网建公司
  • 餐饮网站方案wordpress 微论坛主题
  • 上海建筑网站设计多用户商城数据库设计
  • 网站做301将重定向到新域名深圳seo优化外包公司
  • 做视频导航网站有哪些天津西青区离哪个火车站近
  • 福州网站建设技术支持公司培训课程有哪些
  • 保定网站制作域名注册商查询
  • 医院网站建设公司价格低天津建设工程信息网 塘沽一中
  • 建设机械网站案例建国外网站需要多少钱
  • 比特币简易网站开发电商网站大全