問題描述
使用以下代碼,我可以刪除圖像中的水平線.見下面的結果.
結果還不錯,不是很完美,但是很好.我想要實現的是
我的一個問題是:如何在不應用灰色效果的情況下保存 Sobel X
?作為原始但經過處理..
另外,有沒有更好的方法呢?
編輯
對源圖像使用以下代碼很好.效果很好.
但是如果我有這張圖片呢?
我嘗試執行上面的代碼,結果真的很差……
我正在處理的其他圖像是這些......
這是一種方法
將圖像轉換為
接下來我們創建一個特殊的水平內核來檢測水平線.我們將這些線條繪制到蒙版上,然后在蒙版上找到輪廓.為了去除線條,我們用白色填充輪廓
檢測到的線
面具
填充輪廓
圖像當前有間隙.為了解決這個問題,我們構建了一個垂直內核來修復圖像
<塊引用>
注意根據映像,內核的大小會有所變化.例如,為了檢測更長的行,我們可以使用
(50,1)
內核.如果我們想要更粗的線條,我們可以增加第二個參數為(50,2)
.這是其他圖片的結果
檢測到的線
原始(左),刪除(右)
檢測到的線
原始(左),刪除(右)
完整代碼
Using the following code I can remove horizontal lines in images. See result below.
The result is pretty good, not perfect but good. What I want to achieve is the one showed here. I am using this code.
Source image..
One of my questions is: how to save the
Sobel X
without that grey effect applied ? As original but processed..Also, is there a better way to do it ?
EDIT
Using the following code for the source image is good. Works pretty well.
But if I have this image ?
I tried to execute the code above and the result is really poor...
Other images which I am working on are these...
解決方案Here's an approach
Convert image to grayscale
Otsu's threshold to get binary image
Create special horizontal kernel and morph open to detect horizontal lines
Find contours on mask and "fill in" the detected horizontal lines with white to effectively remove horizontal lines
Create vertical kernel and repair image with morph close
After converting to grayscale, we Otsu's threshold to obtain a binary image
Next we create a special horizontal kernel to detect horizontal lines. We draw these lines onto a mask and then find contours on the mask. To remove the lines, we fill in the contours with white
Detected lines
Mask
Filled in contours
The image currently has gaps. To fix this, we construct a vertical kernel to repair the image
Note depending on the image, the size of the kernel will change. For instance, to detect longer lines, we could use a
(50,1)
kernel instead. If we wanted thicker lines, we could increase the 2nd parameter to say(50,2)
.Here's the results with the other images
Detected lines
Original (left), removed (right)
Detected lines
Original (left), removed (right)
Full code
這篇關于刪除圖像中的水平線(OpenCV、Python、Matplotlib)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!