mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Merge pull request #19336 from kyshel:patch-1
This commit is contained in:
commit
291dbdfbe6
@ -88,27 +88,27 @@ B = cv.imread('orange.jpg')
|
|||||||
# generate Gaussian pyramid for A
|
# generate Gaussian pyramid for A
|
||||||
G = A.copy()
|
G = A.copy()
|
||||||
gpA = [G]
|
gpA = [G]
|
||||||
for i in xrange(6):
|
for i in range(6):
|
||||||
G = cv.pyrDown(G)
|
G = cv.pyrDown(G)
|
||||||
gpA.append(G)
|
gpA.append(G)
|
||||||
|
|
||||||
# generate Gaussian pyramid for B
|
# generate Gaussian pyramid for B
|
||||||
G = B.copy()
|
G = B.copy()
|
||||||
gpB = [G]
|
gpB = [G]
|
||||||
for i in xrange(6):
|
for i in range(6):
|
||||||
G = cv.pyrDown(G)
|
G = cv.pyrDown(G)
|
||||||
gpB.append(G)
|
gpB.append(G)
|
||||||
|
|
||||||
# generate Laplacian Pyramid for A
|
# generate Laplacian Pyramid for A
|
||||||
lpA = [gpA[5]]
|
lpA = [gpA[5]]
|
||||||
for i in xrange(5,0,-1):
|
for i in range(5,0,-1):
|
||||||
GE = cv.pyrUp(gpA[i])
|
GE = cv.pyrUp(gpA[i])
|
||||||
L = cv.subtract(gpA[i-1],GE)
|
L = cv.subtract(gpA[i-1],GE)
|
||||||
lpA.append(L)
|
lpA.append(L)
|
||||||
|
|
||||||
# generate Laplacian Pyramid for B
|
# generate Laplacian Pyramid for B
|
||||||
lpB = [gpB[5]]
|
lpB = [gpB[5]]
|
||||||
for i in xrange(5,0,-1):
|
for i in range(5,0,-1):
|
||||||
GE = cv.pyrUp(gpB[i])
|
GE = cv.pyrUp(gpB[i])
|
||||||
L = cv.subtract(gpB[i-1],GE)
|
L = cv.subtract(gpB[i-1],GE)
|
||||||
lpB.append(L)
|
lpB.append(L)
|
||||||
@ -122,7 +122,7 @@ for la,lb in zip(lpA,lpB):
|
|||||||
|
|
||||||
# now reconstruct
|
# now reconstruct
|
||||||
ls_ = LS[0]
|
ls_ = LS[0]
|
||||||
for i in xrange(1,6):
|
for i in range(1,6):
|
||||||
ls_ = cv.pyrUp(ls_)
|
ls_ = cv.pyrUp(ls_)
|
||||||
ls_ = cv.add(ls_, LS[i])
|
ls_ = cv.add(ls_, LS[i])
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ ret,thresh5 = cv.threshold(img,127,255,cv.THRESH_TOZERO_INV)
|
|||||||
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
|
titles = ['Original Image','BINARY','BINARY_INV','TRUNC','TOZERO','TOZERO_INV']
|
||||||
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
|
images = [img, thresh1, thresh2, thresh3, thresh4, thresh5]
|
||||||
|
|
||||||
for i in xrange(6):
|
for i in range(6):
|
||||||
plt.subplot(2,3,i+1),plt.imshow(images[i],'gray',vmin=0,vmax=255)
|
plt.subplot(2,3,i+1),plt.imshow(images[i],'gray',vmin=0,vmax=255)
|
||||||
plt.title(titles[i])
|
plt.title(titles[i])
|
||||||
plt.xticks([]),plt.yticks([])
|
plt.xticks([]),plt.yticks([])
|
||||||
@ -98,7 +98,7 @@ titles = ['Original Image', 'Global Thresholding (v = 127)',
|
|||||||
'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
|
'Adaptive Mean Thresholding', 'Adaptive Gaussian Thresholding']
|
||||||
images = [img, th1, th2, th3]
|
images = [img, th1, th2, th3]
|
||||||
|
|
||||||
for i in xrange(4):
|
for i in range(4):
|
||||||
plt.subplot(2,2,i+1),plt.imshow(images[i],'gray')
|
plt.subplot(2,2,i+1),plt.imshow(images[i],'gray')
|
||||||
plt.title(titles[i])
|
plt.title(titles[i])
|
||||||
plt.xticks([]),plt.yticks([])
|
plt.xticks([]),plt.yticks([])
|
||||||
@ -153,7 +153,7 @@ titles = ['Original Noisy Image','Histogram','Global Thresholding (v=127)',
|
|||||||
'Original Noisy Image','Histogram',"Otsu's Thresholding",
|
'Original Noisy Image','Histogram',"Otsu's Thresholding",
|
||||||
'Gaussian filtered Image','Histogram',"Otsu's Thresholding"]
|
'Gaussian filtered Image','Histogram',"Otsu's Thresholding"]
|
||||||
|
|
||||||
for i in xrange(3):
|
for i in range(3):
|
||||||
plt.subplot(3,3,i*3+1),plt.imshow(images[i*3],'gray')
|
plt.subplot(3,3,i*3+1),plt.imshow(images[i*3],'gray')
|
||||||
plt.title(titles[i*3]), plt.xticks([]), plt.yticks([])
|
plt.title(titles[i*3]), plt.xticks([]), plt.yticks([])
|
||||||
plt.subplot(3,3,i*3+2),plt.hist(images[i*3].ravel(),256)
|
plt.subplot(3,3,i*3+2),plt.hist(images[i*3].ravel(),256)
|
||||||
@ -196,7 +196,7 @@ bins = np.arange(256)
|
|||||||
fn_min = np.inf
|
fn_min = np.inf
|
||||||
thresh = -1
|
thresh = -1
|
||||||
|
|
||||||
for i in xrange(1,256):
|
for i in range(1,256):
|
||||||
p1,p2 = np.hsplit(hist_norm,[i]) # probabilities
|
p1,p2 = np.hsplit(hist_norm,[i]) # probabilities
|
||||||
q1,q2 = Q[i],Q[255]-Q[i] # cum sum of classes
|
q1,q2 = Q[i],Q[255]-Q[i] # cum sum of classes
|
||||||
if q1 < 1.e-6 or q2 < 1.e-6:
|
if q1 < 1.e-6 or q2 < 1.e-6:
|
||||||
|
@ -268,7 +268,7 @@ fft_filters = [np.fft.fft2(x) for x in filters]
|
|||||||
fft_shift = [np.fft.fftshift(y) for y in fft_filters]
|
fft_shift = [np.fft.fftshift(y) for y in fft_filters]
|
||||||
mag_spectrum = [np.log(np.abs(z)+1) for z in fft_shift]
|
mag_spectrum = [np.log(np.abs(z)+1) for z in fft_shift]
|
||||||
|
|
||||||
for i in xrange(6):
|
for i in range(6):
|
||||||
plt.subplot(2,3,i+1),plt.imshow(mag_spectrum[i],cmap = 'gray')
|
plt.subplot(2,3,i+1),plt.imshow(mag_spectrum[i],cmap = 'gray')
|
||||||
plt.title(filter_name[i]), plt.xticks([]), plt.yticks([])
|
plt.title(filter_name[i]), plt.xticks([]), plt.yticks([])
|
||||||
|
|
||||||
|
@ -108,7 +108,7 @@ from matplotlib import pyplot as plt
|
|||||||
cap = cv.VideoCapture('vtest.avi')
|
cap = cv.VideoCapture('vtest.avi')
|
||||||
|
|
||||||
# create a list of first 5 frames
|
# create a list of first 5 frames
|
||||||
img = [cap.read()[1] for i in xrange(5)]
|
img = [cap.read()[1] for i in range(5)]
|
||||||
|
|
||||||
# convert all to grayscale
|
# convert all to grayscale
|
||||||
gray = [cv.cvtColor(i, cv.COLOR_BGR2GRAY) for i in img]
|
gray = [cv.cvtColor(i, cv.COLOR_BGR2GRAY) for i in img]
|
||||||
|
Loading…
Reference in New Issue
Block a user