Last active
March 27, 2021 15:12
-
-
Save cydal/371a3fe98ef7a9ccd3eaff9aa05d7135 to your computer and use it in GitHub Desktop.
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
from PIL import Image | |
import numpy as np | |
from scipy import ndimage | |
from skimage import filters | |
from skimage.filters import laplace, sobel_h, sobel_v | |
from skimage.feature import canny | |
from skimage.color import rgb2hsv | |
img = np.array(Image.open(img_path)) | |
img_hsv = rgb2hsv(img) | |
episilon = 0.002 | |
img_exg = (2 * img[:, :, 1]) - (img[:, :, 2]) - (img[:, :, 0]) | |
img_exr = (1.4 * img[:, :, 2]) - (img[:, :, 1]) | |
img_cive = (0.881 * img[:, :, 1]) - (0.441 * img[:, :, 2]) - (0.385 * img[:, :, 0]) - 18.78745 | |
img_ndi = np.divide(((img[:, :, 1]) - (img[:, :, 2])), ((img[:, :, 1]) + (img[:, :, 2])) + episilon) | |
# Sobel X & Y | |
img_sobel_x = filters.sobel_h(img_exg) | |
img_sobel_y = filters.sobel_v(img_exg) | |
## Laplacian | |
gray = img.mean(axis=3) | |
noise_reduc = gaussian(gray, sigma=0, truncate=1/3) | |
laplacian = laplace(noise_reduc, ksize=3) | |
## Canny Edge Detection | |
canny = canny(gray) | |
channels = [img[:, :, 2], img[:, :, 1], img[:, :, 0], | |
img_hsv[:, :, 0], img_hsv[:, :, 1], img_hsv[:, :, 2], | |
img_exg, img_exr, img_cive, img_ndi, | |
img_sobel_x, img_sobel_y, laplacian, canny] | |
combined = np.stack(channels, axis=2) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment