I've been advised to ask here, I hope that it fits.

Original question:

I want to create a more straightforward and lighter version of this fantastic repo (which itself is based on Fingerprint Image Enhancement: Algorithm and Performance Evaluation).

The tradeoff here will be between the running time and the quality of the results, which will be damaged.

The idea is to iterate through some prefixed orientations, wavelengths, phases, and kernels and choose the most suiting one.

Here is my initial attempt:

def prepare_image_V1(img):

orientations = [0, 45, 90, 135]
wavelengths = [5, 7, 9, 11, 13, 15]
phases = [0, np.pi/4, np.pi/2, 3*np.pi/4]
kernels = [3, 5, 7, 9, 11]

max_response = 0

for orientation in orientations:
    for wavelength in wavelengths:
        for phase in phases:
            for kernel_size in kernels:
                kernel = cv2.getGaborKernel(
                    (kernel_size, kernel_size), 1.5, orientation, wavelength, 0.5, phase)

                response = cv2.filter2D(img, cv2.CV_64F, kernel)

                if np.sum(response) > np.sum(max_response):
                    max_response = response

max_response = max_response/np.amax(max_response)*255

return max_response

The problem with this is that it will choose the best orientation for the image as a whole.

E.g - The original image on the left, and on the right, the image after applying prepare_image_V1 and some thresholding. We can see fairly good results where the orientation is 45 deg.

enter image description here

My question is how can I apply the filter for each region individually? I've tried to use view_as_blocks and apply the same function to each block individually, but the results are just not good - I can "see" the blocks.

For comparison, here's the result of the above repo:

enter image description here

And the original image if anyone would like to try it themself. enter image description here

  • $\begingroup$ You need to choose the most suited parameters for each pixel individually (using its neighborhood, of course). That is, you don’t use the same orientation for a whole block, you only set one output pixel in the middle of that block, and then shift the block over by one pixel. $\endgroup$ Jul 22 at 23:26

1 Answer 1


when working in blocks a softer approach is needed.
make your blocks overlap which means for each pixel you get numerous values which you average. this will make the result smoother with no harsh boundaries.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.