我正在尝试增加灰度图像的亮度.cv2.imread()返回一个numpy数组.我正在为数组的每个元素添加整数值.从理论上讲,这会增加每一个.之后,我可以将上限阈值设为255,并获得更高亮度的图像.
这是代码:
grey = cv2.imread(path+file,0)
print type(grey)
print grey[0]
new = grey + value
print new[0]
res = np.hstack((grey, new))
cv2.imshow('image', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
Run Code Online (Sandbox Code Playgroud)
但是,内部OpenCV例程显然是这样的:
new_array = old_array % 255
Run Code Online (Sandbox Code Playgroud)
高于255的每个像素强度值变为除以255的余数.
结果,我变得黑暗而不是完全变白.
这是输出:
<type 'numpy.ndarray'>
[115 114 121 ..., 170 169 167]
[215 214 221 ..., 14 13 11]
Run Code Online (Sandbox Code Playgroud)
这是图像:
如何关闭此余数机制?有没有更好的方法来提高OpenCV的亮度?
我正在尝试构建一个最简单的LSTM网络.只是希望它预测序列中的下一个值np_input_data.
import tensorflow as tf
from tensorflow.python.ops import rnn_cell
import numpy as np
num_steps = 3
num_units = 1
np_input_data = [np.array([[1.],[2.]]), np.array([[2.],[3.]]), np.array([[3.],[4.]])]
batch_size = 2
graph = tf.Graph()
with graph.as_default():
tf_inputs = [tf.placeholder(tf.float32, [batch_size, 1]) for _ in range(num_steps)]
lstm = rnn_cell.BasicLSTMCell(num_units)
initial_state = state = tf.zeros([batch_size, lstm.state_size])
loss = 0
for i in range(num_steps-1):
output, state = lstm(tf_inputs[i], state)
loss += tf.reduce_mean(tf.square(output - tf_inputs[i+1]))
with tf.Session(graph=graph) as session:
tf.initialize_all_variables().run()
feed_dict={tf_inputs[i]: np_input_data[i] for i in range(len(np_input_data))} …Run Code Online (Sandbox Code Playgroud)