Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravindra Parmar authored and Ravindra Parmar committed Aug 24, 2018
0 parents commit c6d1bdc
Show file tree
Hide file tree
Showing 9 changed files with 145 additions and 0 deletions.
25 changes: 25 additions & 0 deletions edge_detection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Canny Edge Detection.
import cv2
import numpy as np
import glob
import os
from matplotlib import pyplot as plt
from PIL import Image

DIR_PATH = '../Images/*'

# Read all images.
all_files_dir = glob.glob(DIR_PATH)

for file_item in all_files_dir:
try:
# Read image from disk.
img = cv2.imread(file_item)

# Canny edge detection.
edges = cv2.Canny(img, 100, 200)

filename = os.path.basename(file_item).split('.')[0]
cv2.imwrite(filename + '_l.jpg', edges)
except IOError:
print ('Error while reading files!!!')
Binary file added edges.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions laplacian_gradient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Image Processing.
import cv2
import numpy as np
import glob
import os
from matplotlib import pyplot as plt
from PIL import Image

DIR_PATH = '../Images/*'

# Read all images.
all_files_dir = glob.glob(DIR_PATH)

for file_item in all_files_dir:
try:
# Read image from disk.
img = cv2.imread(file_item)

# Laplacian filter.
laplacian = cv2.Laplacian(img, cv2.CV_64F)
# Sobel : Derivative along 'x' direction.
sobelx = cv2.Sobel(img, cv2.CV_64F, 1, 0, ksize=5)
# Sobel : Derivative along 'y' direction.
sobely = cv2.Sobel(img, cv2.CV_64F, 0, 1, ksize=5)

filename = os.path.basename(file_item).split('.')[0]
cv2.imwrite(filename + '_l.jpg', laplacian)
cv2.imwrite(filename + '_sx.jpg', sobelx)
cv2.imwrite(filename + '_sy.jpg', sobely)
except IOError:
print ('Error while reading files!!!')
Binary file added rotate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
29 changes: 29 additions & 0 deletions rotation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Image Rotation.
import cv2
import numpy as np
import glob
import os
from PIL import Image

DIR_PATH = '../Images/*'

# Read all images.
all_files_dir = glob.glob(DIR_PATH)

for file_item in all_files_dir:
try:
# Read image from disk.
img = cv2.imread(file_item)
(rows, cols) = img.shape[:2]

# Rotation w.r.t center to 45 without scaling.
M = cv2.getRotationMatrix2D((cols/2, rows/2), 45, 1)
res = cv2.warpAffine(img, M, (cols, rows))

# Write image back to disk.
filename = os.path.basename(file_item).split('.')[0]
cv2.imwrite(filename + '_r.jpg', res)
except IOError:
print ('Error while reading files!!!')


Binary file added scale.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions scaling.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Image Processing.
import cv2
import numpy as np
import glob
import os
from PIL import Image

DIR_PATH = '../Images/*'

# Read all images.
all_files_dir = glob.glob(DIR_PATH)

for file_item in all_files_dir:
try:
# Read image from disk.
img = cv2.imread(file_item)
filename = os.path.basename(file_item).split('.')[0]
(height, width) = img.shape[:2]
res = cv2.resize(img, (2*width, 2*height), interpolation=cv2.INTER_CUBIC)
# Write image back to disk.
cv2.imwrite(filename + '_.jpg' ,res)
except IOError:
print ('Error while reading files!!!')


Binary file added translate.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 35 additions & 0 deletions translation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Image Translation (Shifting the object).
import cv2
import numpy as np
import glob
import os
from PIL import Image

DIR_PATH = '../Images/*'

# Read all images.
all_files_dir = glob.glob(DIR_PATH)

# Create translation matrix.
# If the shift is (x, y) then matrix would be
# M = [1 0 x]
# [0 1 y]

# Let's shift by (100, 50).
M = np.float32([[1, 0, 100], [0, 1, 50]])

for file_item in all_files_dir:
try:
# Read image from disk.
img = cv2.imread(file_item)
(rows, cols) = img.shape[:2]

filename = os.path.basename(file_item).split('.')[0]

res = cv2.warpAffine(img, M, (cols, rows))
# Write image back to disk.
cv2.imwrite(filename + '_t.jpg', res)
except IOError:
print ('Error while reading files!!!')


0 comments on commit c6d1bdc

Please sign in to comment.