【发布时间】:2014-01-30 14:53:43
【问题描述】:
我正在编写一个脚本来使用 NumPy 和 CV2 修改 RGB 图像的亮度,方法是从 RGB 转换为 YCrCb 并再次转换回来。但是,我使用的循环需要一段时间才能执行,我想知道是否有更快的方法。
import cv2 as cv, numpy as np
threshold = 64
image = cv.imread("motorist.jpg", -1)
image.shape # Evaluates to (1000, 1500, 3)
im = cv.cvtColor(image, cv.COLOR_RGB2YCR_CB)
for row in image:
for col in row:
if col[0] > threshold:
col[0] = threshold
image = cv.cvtColor(im, cv.COLOR_YCR_CB2RGB)
cv.imwrite("motorist_filtered.jpg", image)
实现阈值比较的嵌套循环至少需要 5-7 秒才能执行。有没有更快的方法来实现这个功能?
【问题讨论】:
标签: python image-processing numpy