import tensorflow as tf import os from tensorflow . python . ops . image_ops_impl import ResizeMethod import tensorflow as tf import matplotlib . pylab as plt path = 'C:\\Users\\Administrator\\Desktop\\girl.jpg' # 实验原图本地路径 target = 'C:\\Users\\Administrator\\Desktop\\girl.txt' # RGB数值对保存路径 # 读取图片数据 image = tf . compat . v1 . read_file ( path , 'r' ) # 将图像文件解码为Tensor image_tensor = tf . image . decode_jpeg ( image ) image_tensor_numpy = image_tensor . numpy ( ) print ( '#######################################################################' ) # 图像各 像素点 数值对 写入文件 try : # coding=UTF-8,写入多行取消注释即可 with open ( target , 'w' , encoding = "UTF-8" ) as file_object : for h in range ( image_tensor . shape [ 0 ] ) : for w in range ( image_tensor . shape [ 1 ] ) : for i in range ( image_tensor . shape [ 2 ] ) : file_object . write ( image_tensor_numpy [ h ] [ w ] [ i ] . astype ( np . str ) + '\t' ) file_object . write ( '\r\n' ) # 每输入一个像素点数值对(3个一对)后换一行 finally : file_object . close ( ) # 读取文件 像素点 数值对 file = open ( target , 'r' , encoding = "utf-8" ) image_tensor_init = tf . zeros ( shape = ( image_tensor . shape [ 0 ] , image_tensor . shape [ 1 ] , image_tensor . shape [ 2 ] ) ) tensor_string = None try : tensor_string = file . read ( ) finally : file . close ( ) # 将本地的字符串转换为numpy整数列表 tensor_string_str = tensor_string . replace ( '\n' , '' ) tensor_string_list = tensor_string_str . split ( '\t' ) array_numpy = np . array ( tensor_string_list [ : - 1 ] ) array_numpy = array_numpy . astype ( np . int ) # 将numpy形式整数列表转换为tensor形式整数张量向量 numpy_to_tensor = tf . convert_to_tensor ( array_numpy ) # image_numpy_to_tensor = tf.reshape(numpy_to_tensor,(image_tensor.shape[0], image_tensor.shape[1], image_tensor.shape[2])) image_numpy_to_tensor = tf . reshape ( numpy_to_tensor , ( 800 , 575 , 3 ) ) # 改变tensor向量形状 # image_numpy_to_tensor = tf.reshape(numpy_to_tensor,(500, 920, 3))# 改变tensor向量形状 print ( image_numpy_to_tensor ) print ( type ( image_numpy_to_tensor ) ) # # 显示图片 plt . imshow ( image_numpy_to_tensor ) plt . show ( )
三、结果展示:

1.1、 形状为(800, 575, 3)的后台展示:
在这里插入图片描述
1.2、 形状为(800, 575, 3)的matplotlib绘图展示:
在这里插入图片描述
1.3、 形状为(800, 575, 3)的写入本地文件内容展示:
注意: 由于文件行数(460000行)过于大,打开有点慢,静等!!!
在这里插入图片描述

2.1、 形状为(500, 920, 3)的matplotlib绘图展示:
在这里插入图片描述
特别提醒: 本代码基于TensorFlow2.3.0,所以读取图片数据时为了兼容版本:

image = tf.compat.v1.read_file(path, ‘r’)
用了 tf.compat.v1,如果你是TensorFlow1系列的版本,直接tf.read_file(path, ‘r’)即可

此外,为了好玩,改变tensor向量形状时,确保形状格式为:
(height, width, 3),其中height * width=460000;
同理,如果你用自定义图片,请确保最后一维3保持不变,而height * width要等于记事本中显示的行数即可!!!

看完标题,我们可以把这个任务当成两个子任务来实现:一是先批量 读取 指定 文件 夹下的 图像 ,二是对 读取 的每一 帧图形裁剪;再就是如何设置,才可以裁剪出多张指定的大小?三是如何对处理后的 图像 进行批量保存?现在让我们来 一探究竟。 step1:批量 读取 指定 文件 夹下的 图像 : file_path='F:\学术&工程\ObjectDetect\全景 图像 集\'; % 图像 文件 夹路径 img_path_list
首先是在某论坛上一位老师写的一个程序,这个不是用OpenCV写的,也很棒,放在这里,免得日后忘记。 这是用了微软提供的GDI写的,其实跟OpenCV也很像。如果没有安装OpenCV的话,是很好的选择。 #include #include #include #include #include //微软提供的图形设备接口图形模块 #pragma comment(lib, "gd
本文所使用的SVM分类器,功能主要是来分类和识别 图片 中的特定颜色特征。我用来 提取 的是 图像 的荧光特征区域。在训练前,你首先需要有一张需要训练的图和它对应的标签,训练的图可以是 RGB RGB RGB 或者BMPBMPBMP 图像 ,标签是一张黑白的二值图,形状与前面 图片 大小对应,白色区域对应你要 提取 的原图特征区域。 from sklearn import svm import os since = time.time() # 时间戳,用来记录时间 image_path = r' 图片 路径' label_path = r'
对于 图像 生成文本来说,除了预处理文本信息,还要对 图像 特征进行提前 提取 。这里单独编写一个脚本,对所有 图像 特征进行 提取 ,然后将 提取 出来的特征保存在一个目录中。 这里使用到了预训练好的 inception_v3 模型,并且是一个带有默认图的 inception_v3 模型。inception_v3_graph_def.pb 该模型不光带有模型参数,同时还带有计算图,将这个计算图载入到自己...
主要通过获取本地的一张 图片 ,分析 图片 每一 像素点 RGB 值,由此获得每一 像素点 的灰度值,并对这些灰度值进行熵的计算。 import java.awt.BorderLayout; import java.awt.Color; import java.awt.event.*; import java.awt.image.BufferedImage; import java.io.File;
提示:这里可以添加本文要记录的大概内容: 在拿到一张 图片 时,想使用matla 读取 图片 并做相应分析时,比如 提取 CCD获得的光强信息时,可以从bmp、tif或png 图片 格式中分解出 RGB 红绿蓝分量的 图片 ,分别进行分析,把分解出的R值图,导入matlab中作三维或者二维 图像 进行数据分析。 提示:以下是本篇文章正文内容,下面案例可供参考 一、pandas. #include "opencv2/videoio.hpp" #include "opencv2/highgui.hpp" #include "opencv2/imgproc/imgproc_c.h" #include <iostream> #include <fstream> #inc..
文章目录1、问题描述2、效果呈现3、思路3.1 HSV空间下 提取 3.2 使用掩膜与 RGB 三个通道分别做点乘3.3 使用 图像 与运算,比使用mask4、代码: 1、问题描述 使用opencv 提取 图像 红色 。 2、效果呈现 使用 python 提取 红色 总共遇到了三种,但是有效只有一种 有效方法 提取 出的结果 3.1 HSV空间下 提取 思路:让 RGB 图像 转化为HSV空间下 图像 ,使用 红色 图像 所在阈值进行 提取 。 事实 提取 出来的是二值化 图像 ,但是这里的二值化 图像 能够当成掩膜使用。 3.2 使用掩膜与
Python 快速 提取 RGB 图片 特定颜色作为mask(采用矩阵) PYTHON 新的改变功能快捷键合理的创建标题,有助于目录的生成如何改变文本的样式插入链接与 图片 如何插入一段漂亮的代码片生成一个适合你的列表创建一个表格设定内容居中、居左、居右SmartyPants创建一个自定义列表如何创建一个注脚注释也是必不可少的KaTeX数学公式新的甘特图功能,丰富你的文章UML 图表FLowchart流程图导出与导入导出导入 PYTHON 你好! 这是你第一次使用 Markdown编辑器 所展示的欢迎页。如果你想学习如何使