How to convert an image to FFT mask?

Hi, I want to filter an image with FFT. I followed this tutorial

It works so far, but it uses a simple circular mask in the center. I want to use an image as mask. The image is grayscale and has only black and white.

How can I convert the image so that it works as a mask?

Hi @burli

About how to apply a mask on an numpy image, I found this:

As I believe you are trying to filter the image, I suggest exploring the use of gaussians, multiplying the image with a centered gaussian.

maybe the following code worth to try if you still trying to solve your previous question.

import cv2
import numpy as np

img = cv2.imread('d:/test/pt4.png', cv2.IMREAD_GRAYSCALE) # load an image as GRAYSCALE

ed = cv2.ximgproc.createEdgeDrawing()
ed.detectEdges(img)
grad_img = np.float32(img)

grad_img = ed.getGradientImage()

cv2.imshow("",grad_img*255)
cv2.waitKey()

a

Sadly doesn’t work. Get the error

ed.detectEdges
cvw.error: Unknown C++ exception from OpenCV code

I have OpenCV 4.5.5.62 and Python 3.9

I need to learn more about numpy arrays. Thanks for the link.

be sure you opened your image as gray scale ( second parameter of imread must be cv2.IMREAD_GRAYSCALE)

1 Like

must be cv2.IMREAD_GRAYSCALE because magic numbers are cryptic

2 Likes

Sorry, my fault. I copied your code, but replaced a part with a for loop