我正在尝试处理图像以强调(并能够区分)胶片颗粒与像素分辨率。
例如,在这张图片中(来自here):
我想应用转换/过滤器来突出显示左侧的颗粒/右侧的像素化。保持图像的语义在我的过程中根本不重要。
我使用了以下代码和不同的尝试来尝试实现这一点,但想知道是否还有更好的方法,因为最终 hpf 在我的一些示例中也失去了一些颗粒的分辨率(确实如此)似乎不是概念上应用的正确过滤器)。
来自 here 的代码:
import matplotlib.pyplot as plt
import numpy as np
from scipy import ndimage
from PIL import Image
def plot(data,title):
plot.i += 1
plt.subplot(2,2,plot.i)
plt.imshow(data)
plt.gray()
plt.title(title)
plot.i = 0
# Load the data...
im = cv2.imread('./images/grain-pixelation-header.jpg',0)
#im = cv2.cvtColor(im,cv2.COLOR_BGR2RGB)
data = np.array(im,dtype=float)
plot(data,'Original')
# A very simple and very narrow highpass filter
kernel = np.array([[-1,-1,-1],[-1,8,-1]])
#kernel = np.dstack([kernel,kernel,kernel]) * (1.0/12.0)
highpass_3x3 = ndimage.convolve(data,kernel*(1.0/12.0))
plot(highpass_3x3,'Simple 3x3 Highpass')
# A slightly "wider",but sill very simple highpass filter
kernel = np.array([[-1,-2,[2,-6,2],[-2,-12,-2],1]])
#kernel = np.dstack([kernel,kernel]) * (1.0/12.0)
highpass_5x5 = ndimage.convolve(data,kernel*(1.0/12.0))
plot(highpass_5x5,'More complex 5x5 Highpass')
# Another way of making a highpass filter is to simply subtract a lowpass
# filtered image from the original. Here,we'll use a simple gaussian filter
# to "blur" (i.e. a lowpass filter) the original.
lowpass = ndimage.gaussian_filter(data,6)
gauss_highpass = data - lowpass
plot(gauss_highpass,r'Gaussian Highpass,$\sigma = 3 pixels$')
plt.show()