当前位置:网站首页>tensorflow实验十-----图片翻转与缩放
tensorflow实验十-----图片翻转与缩放
2022-06-10 06:32:00 【独宠。】
导入库
import matplotlib.pyplot as plt
import tensorflow as tf
import numpy as np
读取照片
这里的路径是自己存放图片的路径
image_data=tf.keras.preprocessing.image.load_img(r'E:\10\1.jpg','rb')
可视化
plt .imshow(image_data)
plt.show()

img_data=tf.keras.preprocessing.image.img_to_array(image_data)
resized=tf.image.resize(img_data,[256,256])
print("Digital type:",resized.dtype)
resized1=np.asarray(resized,dtype='uint8')
plt.imshow(resized1)
plt.show()
print("Digital type:",resized1.dtype)

resized2=tf.image.resize(img_data,[256,512],method='nearest')
resized2=np.asarray(resized2,dtype='uint8')
plt.imshow(resized2)
plt.show()

resized3=tf.image.resize(img_data,[256,256],method='bicubic')
resized3=np.asarray(resized3,dtype='uint8')
plt.imshow(resized3)
plt.show()

resized3=tf.image.resize(img_data,[256,256],method='area')
resized3=np.asarray(resized3,dtype='uint8')
plt.imshow(resized3)
plt.show()

croped=tf.image.resize_with_crop_or_pad(img_data,100,100)
croped=np.asarray(croped,dtype='uint8')
plt.imshow(croped)
plt.show()

padded=tf.image.resize_with_crop_or_pad(img_data,600,600)
padded=np.asarray(padded,dtype='uint8')
plt.imshow(padded)
plt.show()

random_croped1=tf.image.random_crop(img_data,[200,200,3])
random_croped1=np.asarray(random_croped1,dtype='uint8')
plt.imshow(random_croped1)
plt.show()

img_data=np.asarray(img_data,dtype='uint8')
plt.imshow(img_data)
plt.show()
flip_left_right=tf.image.flip_left_right(img_data)
flip_left_right=np.asarray(flip_left_right,dtype='uint8')
plt.imshow(flip_left_right)
plt.show()

img_data=np.asarray(img_data,dtype='uint8')
plt.imshow(img_data)
plt.show()
flip_up_down=tf.image.flip_up_down(img_data)
img_data=np.asarray(img_data,dtype='uint8')
plt.imshow(flip_up_down)
plt.show()

img_data=np.asarray(img_data,dtype='uint8')
plt.imshow(img_data)
plt.show()
contrast=tf.image.random_contrast(img_data,lower=0.2,upper=3)
contrast=np.asarray(contrast,dtype='uint8')
plt.imshow(contrast)
plt.show()

img_data=np.asarray(img_data,dtype='uint8')
plt.imshow(img_data)
plt.show()
standardization=tf.image.per_image_standardization(img_data)
standardization=np.asarray(standardization,dtype='uint8')
plt.imshow(np.asarray(standardization,dtype='uint8'))
plt.show()

import numpy as np
from PIL import Image
def imgConvolve(image_array,kernel):
'''参数说明:
image_array:原灰度图像矩阵
kernel :卷积核
返回值:原图像与算子进行卷积后的结果
'''
image_arr = image_array.copy()
img_dim1,img_dim2 = image_arr.shape
k_dim1,k_dim2 = kernel.shape
AddW = int((k_dim1-1)/2) AddH = int((k_dim2-1)/2) temp = np.zeros([img_dim1 + AddW*2,img_dim2 + AddH*2]) temp[AddW:AddW+img_dim1,AddH:AddH+img_dim2]= image_arr[:,:] output = np.zeros_like(a=temp) for i in range(AddW,AddW+img_dim1): for j in range(AddH,AddH+img_dim2): output[i][j]= int(np.sum(temp[i-AddW:i+AddW+1,j-AddW:j+AddW+1]*kernel))
return output[AddW:AddW+img_dim1,AddH:AddH+img_dim2]
kernel_1=np.array(
[[-1,0,1],
[-1,9,2],
[-1,0,1]])
kernel_2=np.array(
[[-1,-2,-1],
[0,0,0],
[1,2,1]])
kernel_3=np.array(
[[1,1,1],
[1,-8,1],
[1,1,1]])
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.cm as cm
%matplotlib inline
image = Image.open("E:/10/22.png").convert("L")
image_array = np.array(image)
sobel_x = imgConvolve(image_array,kernel_1)
sobel_y = imgConvolve(image_array,kernel_2)
laplace = imgConvolve(image_array,kernel_3)
plt.imshow(image_array,cmap=cm.gray)
plt.axis("off")
plt.show()
plt.imshow(sobel_x,cmap=cm.gray)
plt.axis("off")
plt.show()
plt.imshow(sobel_y,cmap=cm.gray)
plt.axis("off")
plt.show()
plt.imshow(laplace,cmap=cm.gray)
plt.axis("off")
plt.show()


边栏推荐
- 2022-2027 (New Edition) report on the prospect and future development of China's property rights trading industry
- Thoroughly conquer function pointer
- Will technology talk about alphacode affect programmers' jobs tonight?
- Print linked list from end to end of sword finger offer
- Detailed explanation of common methods of JS array
- Ytu - C language exercises half search
- Liuyongzhi: one code communication defect analysis and architecture design scheme - sound network developer entrepreneurship lecture VOL.02
- TeleyeControlor V8.47版本发布 更改Socket框架
- 基于对应点关系的——两片点云剔除(保留)重复点
- Xshell download, install and use simple tutorial
猜你喜欢

虚拟机网络连接方式
[email protected] Bankruptcy"/>[today in history] March 2: Yahoo was officially established; PC design pioneer was born; [email protected] Bankruptcy

LabVIEW host computer and factory MES docking case communication program, supporting server and client

Leetcode675. 为高尔夫比赛砍树:优先队列+广度优先找最短路径

Teleyecontroller v8.69 reconfiguration of keyboard recording function release by:yose

白加黑过360启动项工具源码发布 多文件过启动项代码
![[prepare for interview] punch in daily interview questions - Summary of MySQL related interview questions (I)](/img/17/44ceaf766836a38ee0176026a14d37.jpg)
[prepare for interview] punch in daily interview questions - Summary of MySQL related interview questions (I)

李宏毅老师《机器学习》课程笔记-4.2 Batch Normalization

Practical experience exchange meeting on digital transformation of manufacturing industry held in Yizhuang

618. How to prepare for the great promotion
随机推荐
原博客的地址
Print linked list from end to end of sword finger offer
PHP implementation keeps two decimal places
Detailed explanation of common methods of JS array
SQL practice: SQL window functions and real problems
Model learning comprehension in Multi-Agent Reinforcement Learning Based on Model
[today in history] March 2: Yahoo was officially established; PC design pioneer was born; [email protected] Bankruptcy
Principe de l'algorithme d'extraction de l'ensemble d'éléments fréquents associés à l'alarme dans le cadre de l'exploitation et de l'entretien intelligents
Déterminer si le processus a des privilèges d'administrateur
Fix a button in the lower right corner
Business topic: user growth analysis
刘勇智:一码通缺陷分析与架构设计方案丨声网开发者创业讲堂 Vol.02
Method of canceling automatic numbering
Solution to permission denied in pushing code to coding
Business topic: ab test experiment design and evaluation
What is ARP (address resolution protocol)?
ArcGIS application (19) ArcGIS statistical analysis and calculation of maximum, minimum and average values of multi band images
SQL Basics
What does network edge mean?
What to say and what not to say during the interview - May 23, 2022