#!/usr/bin/env python # coding: utf-8 # In[1]: import cv2 as cv import numpy as np # In[2]: img = cv.imread('reflections.jpg') # In[3]: squarechunk = img[100:200,100:200] # In[4]: cv.imshow('image', img) cv.waitKey(0) cv.destroyAllWindows() # In[5]: squarechunk[:,:,2] = 200 # In[6]: cv.imshow('image', img) cv.waitKey(0) cv.destroyAllWindows() # In[7]: cv.imshow('image', squarechunk) cv.waitKey(0) cv.destroyAllWindows() # In[9]: blurmask = np.array([[0.1, 0.1, 0.1],[0.1, 0.2, 0.1],[0.1, 0.1, 0.1]]) # In[10]: help(cv.filter2D) # In[11]: blurimg = cv.filter2D(img, -1, blurmask) # In[12]: cv.imshow('image', blurimg) cv.waitKey(0) cv.destroyAllWindows() # In[13]: cv.imshow('image', img) cv.waitKey(0) cv.destroyAllWindows() # In[15]: blurimg2 = cv.GaussianBlur(img, [11, 11], 4) # In[16]: cv.imshow('image', blurimg2) cv.waitKey(0) cv.destroyAllWindows() # In[17]: smoothmask2 = cv.getGaussianKernel(11,4) # In[18]: smoothmask2 # In[19]: smoothmask2.transpose() # In[21]: smoothmask2 = smoothmask2.transpose() * smoothmask2 # In[22]: smoothmask2 # In[23]: blurimg5 = cv.filter2D(img, -1, smoothmask2) # In[24]: cv.imshow('image', blurimg5) cv.waitKey(0) cv.destroyAllWindows() # In[25]: np.sctypeDict.keys() # In[26]: np.sctypes # In[27]: help(np.ones) # In[28]: help(np.zeros) # In[29]: help(np.empty) # In[30]: np.ones([2,2], np.float32) # In[31]: np.zeros([2,2], np.float32) # In[32]: np.empty([2,2], np.float32) # In[33]: img.shape # In[34]: img.dtype # In[40]: def BGR2YCbCr(bgrimg): ycbcrimg = np.empty(bgrimg.shape, np.float32) for r in range(bgrimg.shape[0]): for c in range(bgrimg.shape[1]): #ycbcrimg[r,c,0] = bgrimg[r,c,0]*0.114 + bgrimg[r,c,1]*0.587 + bgimg[r,c,2]*0.299 ycbcrimg[r,c,0] = sum(bgrimg[r,c]*np.array([0.114,0.587,0.299])) ycbcrimg[r,c,1] = 128 + sum(bgimg[r,c] * np.array([0.5, -0.331264,-0.168736])) ycbcrimg[r,c,2] = 128 + sum(bgimg[r,c] * np.array([-0.08132, -0.418688,0.5])) return ycbcrimg # In[36]: img.shape # In[38]: img[0,0] * np.array([0.114, 0.587, 0.299]) # In[39]: sum(img[0,0] * np.array([0.114, 0.587, 0.299])) # In[ ]: