問題描述
使用以下代碼,我可以刪除圖像中的水平線.見下面的結(jié)果.
結(jié)果還不錯(cuò),不是很完美,但是很好.我想要實(shí)現(xiàn)的是
我的一個(gè)問題是:如何在不應(yīng)用灰色效果的情況下保存 Sobel X
?作為原始但經(jīng)過處理..
另外,有沒有更好的方法呢?
編輯
對(duì)源圖像使用以下代碼很好.效果很好.
但是如果我有這張圖片呢?
我嘗試執(zhí)行上面的代碼,結(jié)果真的很差……
我正在處理的其他圖像是這些......
這是一種方法
將圖像轉(zhuǎn)換為
接下來我們創(chuàng)建一個(gè)特殊的水平內(nèi)核來檢測(cè)水平線.我們將這些線條繪制到蒙版上,然后在蒙版上找到輪廓.為了去除線條,我們用白色填充輪廓
檢測(cè)到的線
面具
填充輪廓
圖像當(dāng)前有間隙.為了解決這個(gè)問題,我們構(gòu)建了一個(gè)垂直內(nèi)核來修復(fù)圖像
<塊引用>
注意根據(jù)映像,內(nèi)核的大小會(huì)有所變化.例如,為了檢測(cè)更長(zhǎng)的行,我們可以使用
(50,1)
內(nèi)核.如果我們想要更粗的線條,我們可以增加第二個(gè)參數(shù)為(50,2)
.這是其他圖片的結(jié)果
檢測(cè)到的線
原始(左),刪除(右)
檢測(cè)到的線
原始(左),刪除(右)
完整代碼
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
這篇關(guān)于刪除圖像中的水平線(OpenCV、Python、Matplotlib)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!