生成一个图片序列,假设保存在 E:\kSource\blog\memoryimgback\target
目录,
命令方式为 0.jpg、1.jpg、2.jpg…
运行以下命令,把图片序列合成为一个 mp4 视频文件:
"C:\Program Files\ImageMagick-6.9.11-Q16-HDRI\ffmpeg.exe" -framerate 30 -f image2 -i E:\kSource\blog\memoryimgback\target\%06d.jpg E:\kSource\blog\memoryimgback\target.mp4
一些简单的 OpenCV 滤镜。
函数已定义,现在 beta 值将给出适当的结果。正值表示图像较亮,负值表示图像较暗。
\[\text { dst }(\mathrm{I}) = \text { saturate_cast<uchar> } (\mid \text { src }(\mathrm{I}) * \text { alpha } + \text { beta } \mid)\]cv2.convertScaleAbs(img, beta=beta_value)
我们将使用 OpenCV 中的 filter2D 方法进行适当的编辑。 锐化效果的内核将是:[[-1, -1, -1], [-1, 9.5, -1], [-1, -1, -1]]
# sharp effect
def sharpen(img):
kernel = np.array([[-1, -1, -1], [-1, 9.5, -1], [-1, -1, -1]])
imgSharpen = cv2.filter2D(img, -1, kernel)
return imgSharpen
棕褐色为照片增添了温暖的棕色效果。复古、平静和怀旧的效果被添加到图像中。
# sepia effect
def sepia(img):
# converting to float to prevent loss
imgSepia = np.array(img, dtype=np.float64)
# multipying image with special sepia matrix
imgSepia = cv2.transform(imgSepia, np.matrix([[0.272, 0.534, 0.131],
[0.349, 0.686, 0.168],
[0.393, 0.769, 0.189]]))
# normalizing values greater than 255 to 255
imgSepia[np.where(imgSepia > 255)] = 255
imgSepia = np.array(imgSepia, dtype=np.uint8)
return imgSepia
灰度版本:
# grey pencil sketch effect
def pencil_sketch_grey(img):
#inbuilt function to create sketch effect in colour and greyscale
sk_gray, sk_color = cv2.pencilSketch(img, sigma_s=60, sigma_r=0.07, shade_factor=0.1)
return sk_gray
彩色版本:
# colour pencil sketch effect
def pencil_sketch_col(img):
# inbuilt function to create sketch effect in colour and greyscale
sk_gray, sk_color = cv2.pencilSketch(img, sigma_s=60, sigma_r=0.07, shade_factor=0.1)
return sk_color
# HDR effect
def HDR(img):
hdr = cv2.detailEnhance(img, sigma_s=12, sigma_r=0.15)
return hdr
# invert filter
def invert(img):
inv = cv2.bitwise_not(img)
return inv
单变量插值 UnivariateSpline
UnivariateSpline(x,y,w=None,bbox=[None,None],k=3,s=None)
创建查找表:
# defining a function
from scipy.interpolate import UnivariateSpline
def LookupTable(x, y):
spline = UnivariateSpline(x, y)
return spline(range(256))
夏季效果滤镜 让我们实现一个夏季效果滤镜,它基本上增加了图像的温暖度。 为了实现这一点,我们将增加红色通道中的值并减少蓝色通道中的值。
# summer effect
def Summer(img):
increaseLookupTable = LookupTable([0, 64, 128, 256], [0, 80, 160, 256])
decreaseLookupTable = LookupTable([0, 64, 128, 256], [0, 50, 100, 256])
blue_channel, green_channel, red_channel = cv2.split(img)
red_channel = cv2.LUT(red_channel, increaseLookupTable).astype(np.uint8)
blue_channel = cv2.LUT(blue_channel, decreaseLookupTable).astype(np.uint8)
sum = cv2.merge((blue_channel, green_channel, red_channel ))
return sum
冬季效果滤镜 在冬季效果滤镜中,将进行相反的操作。图像的温暖度会降低。红色通道中的值将减少,蓝色通道中的值将增加。
# winter effect
def Winter(img):
increaseLookupTable = LookupTable([0, 64, 128, 256], [0, 80, 160, 256])
decreaseLookupTable = LookupTable([0, 64, 128, 256], [0, 50, 100, 256])
blue_channel, green_channel, red_channel = cv2.split(img)
red_channel = cv2.LUT(red_channel, decreaseLookupTable).astype(np.uint8)
blue_channel = cv2.LUT(blue_channel, increaseLookupTable).astype(np.uint8)
win = cv2.merge((blue_channel, green_channel, red_channel))
return win
edgePreservingFilter
风格化过滤器产生的输出看起来像使用水彩绘制的图像。
stylization(Mat src, Mat dst, float sigma_s=60, float sigma_r=0.45f)
cv2.xphoto.oilPainting(img, neighbouring, steps)
取正值时,调整平衡向主色靠近;取负值时调整平衡想补色靠近。