Spaces:
Sleeping
Sleeping
tathagata
#1
by
Ritabrata04
- opened
- transforms.py +2 -8
transforms.py
CHANGED
|
@@ -24,10 +24,8 @@ def sobel_edge_detection(image):
|
|
| 24 |
sobel_x = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=3)
|
| 25 |
sobel_y = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=3)
|
| 26 |
sobel_combined = np.sqrt(sobel_x**2 + sobel_y**2)
|
| 27 |
-
sobel_combined = cv2.normalize(sobel_combined, None, 0, 255, cv2.NORM_MINMAX) # Added normalization
|
| 28 |
return sobel_combined
|
| 29 |
|
| 30 |
-
|
| 31 |
# 3. Gaussian Blur
|
| 32 |
def gaussian_blur(image, kernel_size=5):
|
| 33 |
blurred_img = cv2.GaussianBlur(image, (kernel_size, kernel_size), 0)
|
|
@@ -39,10 +37,8 @@ def laplacian_of_gaussian(image):
|
|
| 39 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 40 |
blurred_img = cv2.GaussianBlur(image, (3, 3), 0)
|
| 41 |
log_img = cv2.Laplacian(blurred_img, cv2.CV_64F)
|
| 42 |
-
log_img = cv2.normalize(log_img, None, 0, 255, cv2.NORM_MINMAX) # Added normalization
|
| 43 |
return log_img
|
| 44 |
|
| 45 |
-
|
| 46 |
# 5. Median Filtering
|
| 47 |
def median_filter(image, kernel_size=5):
|
| 48 |
median_img = cv2.medianBlur(image, kernel_size)
|
|
@@ -70,7 +66,7 @@ def high_pass_filter(image):
|
|
| 70 |
dft_shift = np.fft.fftshift(dft)
|
| 71 |
rows, cols = image.shape
|
| 72 |
crow, ccol = rows // 2, cols // 2
|
| 73 |
-
mask = np.ones((rows, cols), np.
|
| 74 |
mask[crow-30:crow+30, ccol-30:ccol+30] = 0
|
| 75 |
fshift = dft_shift * mask
|
| 76 |
f_ishift = np.fft.ifftshift(fshift)
|
|
@@ -78,7 +74,6 @@ def high_pass_filter(image):
|
|
| 78 |
img_back = np.abs(img_back)
|
| 79 |
return img_back
|
| 80 |
|
| 81 |
-
|
| 82 |
def low_pass_filter(image):
|
| 83 |
if len(image.shape) == 3: # Convert to grayscale if RGB
|
| 84 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
|
@@ -86,7 +81,7 @@ def low_pass_filter(image):
|
|
| 86 |
dft_shift = np.fft.fftshift(dft)
|
| 87 |
rows, cols = image.shape
|
| 88 |
crow, ccol = rows // 2, cols // 2
|
| 89 |
-
mask = np.zeros((rows, cols), np.
|
| 90 |
mask[crow-30:crow+30, ccol-30:ccol+30] = 1
|
| 91 |
fshift = dft_shift * mask
|
| 92 |
f_ishift = np.fft.ifftshift(fshift)
|
|
@@ -94,7 +89,6 @@ def low_pass_filter(image):
|
|
| 94 |
img_back = np.abs(img_back)
|
| 95 |
return img_back
|
| 96 |
|
| 97 |
-
|
| 98 |
def wavelet_transform(image):
|
| 99 |
import pywt
|
| 100 |
if len(image.shape) == 3: # Convert to grayscale if RGB
|
|
|
|
| 24 |
sobel_x = cv2.Sobel(image, cv2.CV_64F, 1, 0, ksize=3)
|
| 25 |
sobel_y = cv2.Sobel(image, cv2.CV_64F, 0, 1, ksize=3)
|
| 26 |
sobel_combined = np.sqrt(sobel_x**2 + sobel_y**2)
|
|
|
|
| 27 |
return sobel_combined
|
| 28 |
|
|
|
|
| 29 |
# 3. Gaussian Blur
|
| 30 |
def gaussian_blur(image, kernel_size=5):
|
| 31 |
blurred_img = cv2.GaussianBlur(image, (kernel_size, kernel_size), 0)
|
|
|
|
| 37 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
| 38 |
blurred_img = cv2.GaussianBlur(image, (3, 3), 0)
|
| 39 |
log_img = cv2.Laplacian(blurred_img, cv2.CV_64F)
|
|
|
|
| 40 |
return log_img
|
| 41 |
|
|
|
|
| 42 |
# 5. Median Filtering
|
| 43 |
def median_filter(image, kernel_size=5):
|
| 44 |
median_img = cv2.medianBlur(image, kernel_size)
|
|
|
|
| 66 |
dft_shift = np.fft.fftshift(dft)
|
| 67 |
rows, cols = image.shape
|
| 68 |
crow, ccol = rows // 2, cols // 2
|
| 69 |
+
mask = np.ones((rows, cols), np.uint8)
|
| 70 |
mask[crow-30:crow+30, ccol-30:ccol+30] = 0
|
| 71 |
fshift = dft_shift * mask
|
| 72 |
f_ishift = np.fft.ifftshift(fshift)
|
|
|
|
| 74 |
img_back = np.abs(img_back)
|
| 75 |
return img_back
|
| 76 |
|
|
|
|
| 77 |
def low_pass_filter(image):
|
| 78 |
if len(image.shape) == 3: # Convert to grayscale if RGB
|
| 79 |
image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
|
|
|
|
| 81 |
dft_shift = np.fft.fftshift(dft)
|
| 82 |
rows, cols = image.shape
|
| 83 |
crow, ccol = rows // 2, cols // 2
|
| 84 |
+
mask = np.zeros((rows, cols), np.uint8)
|
| 85 |
mask[crow-30:crow+30, ccol-30:ccol+30] = 1
|
| 86 |
fshift = dft_shift * mask
|
| 87 |
f_ishift = np.fft.ifftshift(fshift)
|
|
|
|
| 89 |
img_back = np.abs(img_back)
|
| 90 |
return img_back
|
| 91 |
|
|
|
|
| 92 |
def wavelet_transform(image):
|
| 93 |
import pywt
|
| 94 |
if len(image.shape) == 3: # Convert to grayscale if RGB
|