-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ravindra Parmar
authored and
Ravindra Parmar
committed
Aug 24, 2018
0 parents
commit c6d1bdc
Showing
9 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!!') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!!') |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!!') | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!!') | ||
|
||
|
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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!!!') | ||
|
||
|