1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
| import cv2 img = cv2.imread(r'x.jpg',0)
cv2.imshow('tupian',img) cv2.waitKey()
cv2.imwrite('tupian,jpg',img)
print(img.shape) print(img.size) print(img.dtype)
B = img[:,:,0] G = img[:,:,1] R = img[:,:,2]
B,G,R = cv2.split(img)
bgr = cv2.merge([b,g,r])
import cv2 import numpy as np bgr=np.random.randint(0,256,size=[2,4,3],dtype=np.uint8) gray=cv2.cvtColor(bgr,cv2.COLOR_BGR2GRAY) rgb=cv2.cvtColor(gray,cv2.COLOR_GRAY2RGB) print('bgr=\n',bgr) print('gray=\n',gray) print('rgb=\n',rgb)
import cv2 import numpy as np img=np.random.randint(0,256,size=[2,3,3],dtype=np.uint8) bgra=cv2.cvtColor(img,cv2.COLOR_BGR2BGRA) print('img=\n',img) print('bgra=\n',bgra) b,g,r,a=cv2.split(bgra) print('a=\n',a) a[:,:]=125 bgra=cv2.merge([b,g,r,a]) print('bgra=\n',bgra)
img = cv2.imread(r"x.jpg",0)
img_float32 = np.float32(img)
dft = cv2.dft(img_float32,flags = cv2.DFT_COMPLEX_OUTPUT)
dft_shift = np.fft.fftshift(dft)
magnitude = 20*np.log(cv2.magnitude(dft_shift[:,:,0],dft_shift[:,:,1])) plt.subplot(121),plt.imshow(img,cmap = 'gray') plt.subplot(122),plt.imshow(magnitude,cmap='gray') plt.show()
|