在不保留语义信息的情况下实现纹理/像素分辨率移情的图像处理?

2024-09-27 07:19:30 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图处理图像,以强调(并能够区分)胶片颗粒与像素分辨率

例如,在此图像中(从here): enter image description 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],
                   [-1, -1, -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, 2, -1],
                       [2, -6, 8, -6, 2],
                       [-2, 8, -12, 8, -2],
                       [2, -6, 8, -6, 2],
                       [-1, 2, -2, 2, 1]])
#kernel = np.dstack([kernel, 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()

上述各项的产出: enter image description here


Tags: thefrom图像importdataplottitlenp

热门问题