Based on this paper Adjustable quadratic filters for image enhancement, Reinhard Bernstein, Michael Moore and Sanjit Mitra, 1997, I am trying to implement the high pass image filter described in the experimental section. More specifically, the formula for the filter used here is formula (53) in the paper "A General Framework for Quadratic Volterra Filters for Edge Enhancement", I have attached a picture of it below. I normalize the input gray image to the range [0, 1], then map it using predefined functions (specifically the definition of f_map_2 and f_map_5 please see in the image), then pass it through the Teager filter (which is the formula (53)), multiply it by an alpha coefficient (here I put alpha = 0.1) and combine the original image for sharpening (unsharp masking), finally denormalize back to the range [0, 255]. map2, map5, and Teager's filter import cv2 import numpy as np from numpy import sqrt import matplotlib.pyplot as plt def normalize(img): return img.astype(np.float32)/255.0 def denormalize(img): """Convert image to [0, 255]""" return (img * 255).clip(0, 255).astype(np.uint8) def input_mapping(x, map_type='none', m=2): """Apply input mapping function according to the paper""" if map_type == 'none': return x # none (4b) elif map_type == 'map2': return x**2 # f_map2: x^2 (4c) elif map_type == 'map5': # piece-wise function f_map5 (4d) mapped = np.zeros_like(x) mask = x > 0.5 mapped[mask] = 1 - 2*(1 - x[mask])**2 mapped[~mask] = 2 * x[~mask]**2 return mapped else: raise ValueError("Invalid mapping type") def teager_filter(img): padded = np.pad(img, 1, mode='reflect') out = np.zeros_like(img) for i in range(1, padded.shape[0]-1): for j in range(1, padded.shape[1]-1): x = padded[i,j] t1 = 3*(x**2) t2 = -0.5*padded[i+1,j+1]*padded[i-1,j-1] t3 = -0.5*padded[i+1,j-1]*padded[i-1,j+1] t4 = -1.0*padded[i+1,j]*padded[i-1,j] t5 = -1.0*padded[i,j+1]*padded[i,j-1] out[i-1,j-1] = t1 + t2 + t3 + t4 + t5 return out def enhance_image(image_path, alpha, map_type='none'): """Enhance images with optional input mapping""" # Image reading and normalization img = cv2.imread(image_path, 0) if img is None: raise FileNotFoundError("No image found!") img_norm = normalize(img) # Input mapping mapped_img = input_mapping(img_norm, map_type) # Teager filter teager_output = teager_filter(mapped_img) enhanced = np.clip(img_norm + alpha * teager_output, 0, 1) return denormalize(enhanced) input_path = r"C:\Users\tt\OneDrive\Desktop\original_image.jpg" original_image = cv2.imread(input_path, 0) alpha = 0.1 enhanced_b = enhance_image(input_path, alpha, map_type='none') enhanced_c = enhance_image(input_path, alpha, map_type='map2') enhanced_d = enhance_image(input_path, alpha, map_type='map5') plt.figure(figsize=(15, 5)) plt.subplot(1, 4, 1) plt.imshow(original_image, cmap='gray') plt.title('Original') plt.axis('off') plt.subplot(1, 4, 2) plt.imshow(enhanced_b, cmap='gray') plt.title('No Mapping (b)') plt.axis('off') plt.subplot(1, 4, 3) plt.imshow(enhanced_c, cmap='gray') plt.title('Map2 (c)') plt.axis('off') plt.subplot(1, 4, 4) plt.imshow(enhanced_d, cmap='gray') plt.title('Map5 (d)') plt.axis('off') plt.tight_layout() plt.show() The problem is my experimental results look very unconvincing. As discussed in the paper, if everything works correctly, then map2 gives better sharpening in high intensity regions, while map5 gives better sharpening in medium intensity regions. But as you can see, my enhanced images still look almost exactly the same as the original, with a slight increase in sharpness if you look closely, and the sharpening effect is almost the same between large, small, and medium intensity areas. Not to mention the ones using mapping, even my no_mapping image is not as sharp as the no_mapping in the paper. my result paper's result Maybe this is helpful, so I'll also post a picture of the output of the above Teager filter, without multiplying by alpha and adding to the original image, as below Teager output (before unsharp masking) I tried changing the alpha but it didn't help, i also tried adding a denoising step in the normalisation function, still didn't help, the image still looks almost identical to the original. I would like to have a way to make the result more clear (i.e. highlight the differences between the improved regions, adjusted by the mapping functions used). I would appreciate any ideas and comments on the code. Thank you! Continue reading...