0

I have an image with horizontal lines in it. An approach that I found that works somewhat well is to use imagemagick to morphology like this.

convert orig.jpg -morphology close:1 "1x7: 1,0,0,0,0,0,1" final.jpg

It is running one iteration of morphology with 1x7 kernel

I'm trying to find equivalent of this in opencv python.

1 Answer 1

1

This command is performing the CLOSING Morphological Operation on the image which can be translated to OpenCV as:

kernel = np.array([1, 0, 0, 0, 0, 0, 1], dtype=np.uint8)  # 1x7: 1,0,0,0,0,0,1
closing = cv2.morphologyEx(img, 
                           cv2.MORPH_CLOSE, # morphology close:1
                           kernel)
Sign up to request clarification or add additional context in comments.

9 Comments

I get error Assertion failed (_kernel.type() == CV_8U) in MorphFilter, file /home/guru/opencv-2.4.10/modules/imgproc/src/morph.cpp, line 791 mitre1.jpg /home/guru/opencv-2.4.10/modules/imgproc/src/morph.cpp:791: error: (-215) _kernel.type() == CV_8U in function MorphFilter while doing this in opencv using the snippet you provided. if I change np.array([[1,0,0,0,0,0,1]]) to np.ones((1,1)) then it works fine. Any thoughts?
Sorry @Anthony missed something obvious there, Edited.
Thanks! that worked! however, I'm not getting results anywhere close to what imagemagik provides. original img, converted from imagemagik, converted from opencv
FWIW i got the imagemagik command from here imagemagick.org/discourse-server/viewtopic.php?p=92969#p92969 which explains what the command is doing in detail
Oh that was really Helpful.
|

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.