当前位置:网站首页>flow_ x+flow_ y---RGB
flow_ x+flow_ y---RGB
2022-07-28 07:17:00 【Sauerkraut】
#coding:utf -8
import os
os.environ["CUDA_VISIBLE_DEVICES"] = "0"
from PIL import Image
import numpy as np
import math
from numba import jit
import cv2
import time
import glob
from sklearn.preprocessing import MinMaxScaler
np.seterr(divide='ignore',invalid='ignore')
def flow_rgb(x_img,y_img):
n,m=np.array(x_img).shape
fuzhi=np.zeros((n,m))
rgb = np.zeros((n,m,3))
i=0
j=0
while i <n:
while j<m:
fuzhi[i,j]=math.sqrt(math.pow(x_img[i,j],2)+math.pow(y_img[i,j],2))
j+=1
i+=1
j=0
#print fuzhi
#x_img.show()
# Turn into RGB picture , And normalize ( Subtract the maximum value of the changed channel pixels from the pixels of each channel )
rgb[:, :, 0] = (x_img- np.ones((n,m))*np.min(x_img)) *1.0 / ( np.ones((n,m))*np.max(x_img) - np.ones((n,m))*np.min(x_img) )
rgb[:, :, 1] = (y_img- np.ones((n,m))*np.min(y_img)) *1.0 / ( np.ones((n,m))*np.max(y_img) - np.ones((n,m))*np.min(y_img) )
rgb[:, :, 2] = (fuzhi- np.ones((n,m))*np.min(fuzhi)) *1.0 / ( np.ones((n,m))*np.max(fuzhi) - np.ones((n,m))*np.min(fuzhi) )
rgb_255=(rgb*225)
rgb_255 =rgb_255.astype(np.uint8)
rgb_255 = cv2.cvtColor(rgb_255, cv2.COLOR_BGR2RGB)
#cv2.imshow('rgb_quanju',rgb_255)
#cv2.waitKey()
return rgb_255
path='/media/xuguohan/Elements/shajie/dataset/IsoGD_flows/'
save_path='/media/xuguohan/E/shajie/image/GD/IsoGD/isogd_flow_rgb'
dataset='train'
path=os.path.join(path,dataset)
save_path=os.path.join(save_path,dataset)
if os.path.exists(save_path) is False:
os.makedirs(save_path)
wenjians=os.listdir(path)#'001'...'010'...'100'
for wenjian in wenjians:#'001'
wenjian_read=os.path.join(path,wenjian)#'/media/xuguohan/Elements/shajie/dataset/IsoGD_frames/train/001'
wenjain_save=os.path.join(save_path,wenjian)#'/media/xuguohan/E/shajie/image/GD/IsoGD/isogd_flow_rgb/train/001'
if os.path.exists(wenjain_save) is False:
os.makedirs(wenjain_save)
www=os.listdir(wenjian_read)#'K_00001'...'M_00121'...
for KM in www:
if KM.split('_')[0]=='M':#'M_00065'
M_path=os.path.join(wenjian_read,KM)#'./IsoGD_frames/train/001/M_00065'
M_path_save=os.path.join(wenjain_save,KM)#'./isogd_flow_rgb/train/001/M_00065'
if os.path.exists(M_path_save) is False:
os.makedirs(M_path_save)
frame_name=os.listdir(M_path)#'flow_y_0005.jpg'...'img_0011.jpg'...'flow_x_0002.jpg'
for frame_one in frame_name:
if frame_one.split('_')[1]=='x':#frame_one.split('_')=['flow', 'x', '0001.jpg']
x_split=frame_one.split('x')#['flow_', '_0001.jpg']
flow_y=x_split[0]+'y'+x_split[-1]
flow_x_path = os.path.join(M_path,frame_one)#'./train/001/M_00065/flow_x_0001.jpg'
flow_y_path = os.path.join(M_path, flow_y)#'./train/001/M_00065/flow_y_0001.jpg'
flow_x = cv2.imread(flow_x_path, 0)
flow_y = cv2.imread(flow_y_path, 0)
rgb=flow_rgb(flow_x, flow_y)
rgb_name='img_{}'.format(x_split[-1])
rgb_path = os.path.join(M_path_save, rgb_name)
print rgb_path
if os.path.exists(rgb_path):
print 'rgb_path exists'
pass
else:
print 'rgb_path save'
cv2.imwrite(rgb_path, rgb)
边栏推荐
- Standard C language learning summary 3
- Shell--第一天作业
- Softmax multi classification gradient derivation
- 起点中文网 字体反爬技术 网页可以显示数字字母 网页代码是乱码或空格
- Group management and permission management
- MySQL查询父节点下面的所有子孙节点,查询用户列表时多级(公司)部门处理,根据反射,递归树形结构工具类
- Standard C language learning summary 8
- Svg understanding and drawing application
- OJ questions about fast and slow pointers in linked lists
- 分布式系分发展概览
猜你喜欢

Freemaker merges cells, uses if and else tags, and processes null and empty strings

爬虫学习总结

VLAN configuration

VNC Timed out waiting for a response from the computer

Shell -- first day homework

Generate create table creation SQL statement according to excel

OJ questions about fast and slow pointers in linked lists

最早截止时间优先(EDF)

Add, delete, check and modify linked lists

Starting point Chinese website font anti crawling technology web page can display numbers and letters, and the web page code is garbled or blank
随机推荐
shell---条件语句练习
Standard C language summary 4
[a little knowledge] AQS
Freemaker exports word with tables and multiple pictures to solve the repetition and deformation of pictures
How did tensor leak your memory / video memory
Detailed explanation of active scanning technology nmap
Redis sentinel mode and cluster
Group management and permission management
Basic knowledge of video format: let you know MKV, MP4, h.265, bit rate, color depth, etc
GFS分布式文件系统
分解路径为目录名和文件名的方法
高响应比优先
Raspberry pie serial port
Joern's code uses -devign
Deployment of elk log analysis system
NoSQL之Redis配置与优化
Review of C language (variable parameters)
Install Nessus under win
Softmax multi classification gradient derivation
Open virtual machine kali2022.2 and install GVM