-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathExercise1.py
63 lines (62 loc) · 1.79 KB
/
Exercise1.py
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
63
# from cv2 import *
# from numpy import *
# I = imread("D:\\GIA DINH\\LONG\\C4T2\\Lesson6\\Image\\Lenna.png")
# gray = cvtColor(I,COLOR_RGB2GRAY)
# ret,bin = threshold(gray,127.5,255,THRESH_BINARY)
# imshow("",bin)
# waitKey()
import numpy as np
import cv2
# Load Image RGB
I = cv2.imread("D:\\GIA DINH\\LONG\\C4T2\\Lesson6\\Image\\shape.jpg")
cv2.imshow("I", I);
cv2.waitKey()
# convert Whiter color to black
[rows, cols, c] = I.shape;
for i in range(rows):
for j in range(cols):
if I[i,j,0] >200 and I[i,j,1] >200 and I[i,j,2] >200 :
I[i,j,:] = 0;
cv2.imshow("Inew", I);
cv2.waitKey()
# Extract chanel B
B = I[:,:,0]
# Extract chanel G
G = I[:,:,1]
# Extract chanel R
R = I[:,:,2]
# Thresold for chanel B
threshB,binB = cv2.threshold(B,100,255,cv2.THRESH_BINARY)
cv2.imshow("B",binB)
threshG,binG = cv2.threshold(G,100,255,cv2.THRESH_BINARY)
cv2.imshow("G",binG)
threshR,binR = cv2.threshold(R,100,255,cv2.THRESH_BINARY)
cv2.imshow("R",binR)
cv2.imshow("binaryImage", binR+binB+binG);
cv2.waitKey()
# I = cv2.imread("D:\\GIA DINH\\LONG\\C4T2\\Lesson6\\Image\\test2.png")
# cv2.imshow("I", I);
# cv2.waitKey()
# # convert Whiter color to black
# [rows, cols, c] = I.shape;
# for i in range(rows):
# for j in range(cols):
# if I[i,j,0] >200 and I[i,j,1] >200 and I[i,j,2] >200 :
# I[i,j,:] = 0;
# cv2.imshow("Inew", I);
# cv2.waitKey()
# # Extract chanel B
# B = I[:,:,0]
# # Extract chanel G
# G = I[:,:,1]
# # Extract chanel R
# R = I[:,:,2]
# # Thresold for chanel B
# threshB,binB = cv2.threshold(B,100,255,cv2.THRESH_BINARY)
# cv2.imshow("B",binB)
# threshG,binG = cv2.threshold(G,100,255,cv2.THRESH_BINARY)
# cv2.imshow("G",binG)
# threshR,binR = cv2.threshold(R,100,255,cv2.THRESH_BINARY)
# cv2.imshow("R",binR)
# cv2.imshow("binaryImage", binR+binB+binG);
# cv2.waitKey()