Skip to content

Commit f890ea3

Browse files
authored
Add files via upload
1 parent c6b33b4 commit f890ea3

File tree

12 files changed

+199
-0
lines changed

12 files changed

+199
-0
lines changed

ch3/contours.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
from PIL import Image
2+
from pylab import *
3+
import matplotlib.pyplot as plt
4+
5+
6+
im = array(Image.open('newport.png').convert('L'))
7+
im2 = array(Image.open('newport.png'))
8+
9+
plt.figure(figsize=(10, 3.6))
10+
11+
plt.subplot(131)
12+
plt.imshow(im2, cmap=plt.cm.gray)
13+
plt.title('Original', fontsize=12)
14+
plt.axis('off')
15+
16+
plt.subplot(132)
17+
plt.imshow(im, cmap=plt.cm.gray, vmin=0, vmax=255)
18+
plt.title('Low Contrast', fontsize=12)
19+
plt.axis('off')
20+
21+
plt.subplot(133)
22+
plt.imshow(im, cmap=plt.cm.gray, vmin=100, vmax=200)
23+
plt.title('High Contrast', fontsize=12)
24+
plt.axis('off')
25+
26+
plt.subplots_adjust(wspace=0, hspace=0., top=0.99, bottom=0.01, left=0.05,
27+
right=0.99)
28+
29+
figure('Contours')
30+
31+
gray()
32+
contour(im, origin='image')
33+
axis('equal')
34+
axis('off')
35+
show()
36+

ch3/cv2_display.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/usr/bin/env python
2+
3+
import cv2
4+
5+
original = cv2.imread('home_tree.png')
6+
7+
gray = cv2.imread('home_tree.png', 0)
8+
9+
cv2.imshow('Original', original)
10+
cv2.imshow('Gray', gray)
11+
12+
cv2.waitKey(0)
13+
cv2.destroyAllWindows()

ch3/gaussian_filter.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
from PIL import Image
3+
import scipy
4+
from scipy.ndimage import gaussian_filter, label
5+
from pylab import *
6+
7+
8+
9+
image = Image.open(sys.argv[1]).convert('L')
10+
img = np.array(image)
11+
12+
im_g = gaussian_filter(img, 3)
13+
im_norm = (im_g - im_g.min()) / (float(im_g.max()) - im_g.min())
14+
im_norm[im_norm < 0.5] = 0
15+
im_norm[im_norm >= 0.5] = 1
16+
17+
out = 255 - (im_norm * 255).astype(np.uint8)
18+
print u"\n\n********** Cells Counted: %d **********\n\n" % label(out)[1]
19+
20+
print out
21+
22+
figure()
23+
gray()
24+
imshow(out)
25+
26+
27+
show()

ch3/hough.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import cv2
2+
import cv2.cv as cv
3+
import numpy as np
4+
5+
6+
7+
img = cv2.imread('yeast2.png',0)
8+
9+
cimg = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
10+
11+
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,67,
12+
param1=5,param2=1,minRadius=4,maxRadius=20)
13+
14+
circles = np.uint16(np.around(circles))
15+
ret2,th2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
16+
for i in circles[0,:]:
17+
cv2.circle(cimg,(i[0],i[1]),i[2],(0,255,0),2)
18+
19+
#cv2.imshow('Detected cells',cimg)
20+
cv2.imshow('detected circles',th2)
21+
cv2.waitKey(0)
22+
cv2.destroyAllWindows()

ch3/hough2.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import cv2
2+
import cv2.cv as cv
3+
import numpy as np
4+
5+
6+
7+
img = cv2.imread('yeast2.png',0)
8+
9+
c_img = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR)
10+
11+
circles = cv2.HoughCircles(img,cv.CV_HOUGH_GRADIENT,1,67,
12+
param1=5,param2=1,minRadius=4,maxRadius=20)
13+
14+
circles = np.uint16(np.around(circles))
15+
16+
for i in circles[0,:]:
17+
cv2.circle(c_img,(i[0],i[1]),i[2],(0,0,0),2)
18+
19+
cv2.imshow('Detected Cells',c_img)
20+
cv2.waitKey(0)
21+
cv2.destroyAllWindows()

ch3/matplot_pil.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python
2+
3+
import cv2
4+
from matplotlib import pyplot as plt
5+
import matplotlib.image as mpimg
6+
7+
original = mpimg.imread('home_tree.png')
8+
gray = cv2.imread('home_tree.png',0)
9+
10+
plt.subplot(131),plt.imshow(gray, cmap = 'gray'),plt.title('Grayscale Image')
11+
plt.xticks([]), plt.yticks([])
12+
13+
plt.subplot(133),plt.imshow(original, cmap='gray'),plt.title('Original Image')
14+
plt.xticks([]), plt.yticks([])
15+
16+
plt.show()

ch3/numpy_array.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import numpy as np
2+
import cv2
3+
4+
5+
6+
img = np.zeros((500,500), dtype=np.float)
7+
img[0:500, 0:500] = 1
8+
9+
cv2.imshow('image',img)
10+
11+
cv2.waitKey(0)
12+
cv2.destroyAllWindows()

ch3/numpy_mask.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import numpy as np
2+
import cv2
3+
4+
5+
6+
img = np.zeros((500,500), dtype=np.float)
7+
img[150:350, 150:350] = 1
8+
9+
cv2.imshow('image',img)
10+
11+
cv2.waitKey(0)
12+
cv2.destroyAllWindows()

ch3/numpy_mask2.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import numpy as np
2+
import cv2
3+
from matplotlib import pyplot as plt
4+
5+
6+
img2 = np.zeros((500,500), np.int8)
7+
random = np.random.rand(500, 500)
8+
9+
plt.subplot(131),plt.imshow(img2,'gray'),plt.title('Mask-0')
10+
plt.xticks([]),plt.yticks([])
11+
12+
plt.subplot(133),plt.imshow(random,'gray'),plt.title('Random')
13+
plt.xticks([]),plt.yticks([])
14+
15+
plt.show()

ch3/otsu2.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import cv2
2+
3+
img = cv2.imread('yeast2.png',0)
4+
5+
ret2,th2 = cv2.threshold(img,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU)
6+
7+
cv2.imshow('Detected Cells',th2)
8+
cv2.waitKey(0)
9+
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)