0

I need to perform a thresholded zero-crossing detection of the filtered image's laplacian. But once the laplacian is applied, it gives error when doing thresholding. Any advice?

code:

img = cv2.imread('H:/FYP/interim/aniso.jpg')
lap = cv2.Laplacian(img, 1, ksize=5)
retval, threshold = cv2.threshold(lap, 70, 255, cv2.THRESH_BINARY)
plt.imshow(threshold)

error:

---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-23-e36300501b24> in <module>
      1 img = cv2.imread('H:/FYP/interim/aniso.jpg')
      2 lap = cv2.Laplacian(img, 1, ksize=5)
----> 3 retval, threshold = cv2.threshold(lap, 70, 255, cv2.THRESH_BINARY)
      4 plt.imshow(threshold)

error: OpenCV(4.1.0) C:\projects\opencv-python\opencv\modules\imgproc\src\thresh.cpp:1612: error: (-210:Unsupported format or combination of formats)  in function 'cv::threshold'
fmw42
  • 46,825
  • 10
  • 62
  • 80
shavindip
  • 607
  • 9
  • 27
  • 1
    You need to specify your desired ddepth. See https://docs.opencv.org/4.1.1/d4/d86/group__imgproc__filter.html#gad78703e4c8fe703d479c1860d76429e6. The laplacian typically produces a floating point image -1 to 1. So you need to scale the image back to 8-bit 0 to 255 range. See https://docs.opencv.org/3.4/d5/db5/tutorial_laplace_operator.html. Here is a link to zero crossing. https://theailearner.com/tag/cv2-laplacian/ You should always refer to the OpenCV documentation and/or search Google (and this forum) first, when you have an issue. – fmw42 Oct 05 '19 at 03:37

1 Answers1

1

you can change like this

retval, threshold = cv2.threshold(img, 127, 255, cv2.THRESH_TOZERO)
HUAI-DE HU
  • 13
  • 2