Laplacian sharpening - grey image as result
<p>As many people before me, I am trying to implement an example of image sharpening from Gonzalez and Woods "Digital image processing" book.</p>

<p>I create a negative Laplacian kernel (-1, -1, -1; -1, 8, -1; -1, -1,-1) and convolve it with the image, then subtract the result from the original image. (I also tried taking positive Laplacian (1, 1, 1; 1, -8, 1; 1, 1, 1) and adding it to the image). On each stage I perform fitting the results into the (0, 255) range, the normalized Laplacian looks nice and grey as it is supposed.</p>

<pre><code>import matplotlib.cm as cm
import scipy.misc
import scipy.ndimage.filters

#Function for plotting abs:
pic_n = 1
def show_abs(I, plot_title):
    plt.title(plot_title)
    plt.tight_layout()
    plt.axis('off')
    plt.imshow(abs(I), cm.gray)

#Reading the image into numpy array:
A = scipy.misc.imread('moon1.jpg', flatten=True)

plt.figure(pic_n)
pic_n += 1
show_abs(A, 'Original image')

A          -= np.amin(A) #map values to the (0, 255) range
A          *= 255.0/np.amax(A)

#Kernel for negative Laplacian
kernel      = np.ones((3,3))*(-1)
kernel[1,1] = 8

#Convolution of the image with the kernel:
Lap         = scipy.ndimage.filters.convolve(A, kernel)

#Laplacian now has negative values in range (-255, 255):
print('L', np.amax(Lap), np.amin(Lap))

plt.figure(pic_n)
pic_n += 1
show_abs(Lap, 'Laplacian')

#Map Laplacian to the (0, 255) range:
Lap        -= np.amin(Lap)
Lap        *= 255.0/np.amax(Lap)
print('L', np.amax(Lap), np.amin(Lap))

plt.figure(pic_n)
pic_n += 1
show_abs(Lap, 'Normalized Laplacian')

A         += Lap #Add negative Laplacian to the original image

print('A', np.amax(A), np.amin(A))
A          -= np.amin(A)
A          *= 255.0/np.amax(A)
print('A', np.amax(A), np.amin(A))

plt.figure(pic_n)
pic_n += 1
show_abs(A, 'Laplacian filtered img')

plt.show()
</code></pre>

<h2>Original image:</h2>

<p><img src="http://i.stack.imgur.com/tM3V5.jpg" alt="Original image"></p>

<h2>Results:</h2>

<p><img src="http://i.stack.imgur.com/o6Dmy.png" alt="Results"></p>

<p>The problem is that the final sharpened image looks faded and grey. I tried doing histogram equalization to make it more contrasting, but the result was weird. I thought about applying gamma-correction, but I don't like the voluntary choice of the gamma coefficient.</p>

<p>It seems there must be an easy and convenient way of bringing the image back to the original dynamic range. I would appreciate ideas and comments on the code. Thank you!</p>

<p>It seems to me that part of the problem has to do with how you are rescaling <code>Lap</code>. I don't think you want to subtract the minimum first - sharpening should decrease the intensity of some pixels as well as increasing that of others. You may also wish to play around with the scaling factor you multiply <code>Lap</code> by in order to control the degree of sharpening (255 might be too extreme).</p>

<p>The reason the background looks grey in the final image is probably because after adding the negative Laplacian there will be pixels in the moon that are darker than the background (the magnitude of the Laplacian in this part of the image will be greater since it contains more local structure). This means that you do your rescaling the background pixels will map to some value > 0. If you don't subtract the min from <code>Lap</code> then these darker pixels would have negative values, so you could then clip the pixel values in the resulting image such that they are all > 0. That way you will end up with a pure black background.</p>

python image-processing scipy