0

我想用python清除图像上的黑点。因为我需要对图像文件进行 ocr 处理。

我将图像转换为单色,所以我得到了这个图像; http://s23.postimg.org/bulq1dmt3/ba210.png

所以,我想删除黑点;

def temizleHips2 (x,y,w,h,listei):
koordinat=list(nfind(x,y))
x = int(x)
y = int(y)
w = int(w)
h = int(h)
i=0
a=0
m=4
b=0
for i in xrange(8):
        b=0
        k=koordinat[i]
        x2,y2=koordinatparse(k)
        if x2>=0 and y2>=0 and x2<w and y2<h:
            if listei[x2,y2]==0:
                a=a+1
if a>2:
    return 0
else:
    return 255

def ultratemizle(dosya):    
# 290a.tif
image_file = dosya
img = Image.open(image_file)
# img=img.convert('1')
# img.save("209i.tif","TIFF")
datas = list(img.getdata())
newData = list()
temizlemes = list()
temizlemeson = list()
siyah =0
beyaz =0
for each in datas:
    if each == 255:
        beyaz = beyaz +1
    else:
        siyah = siyah+1
if siyah > beyaz :
    for each in datas:
        if each == 255:
            each=0
        elif each==0:
            each = 255
        newData.append(each)
    img.putdata(newData)
x1,y1=0,0

tmp_isim = "a"+dosya
img.save("b"+tmp_isim, "TIFF")
img = Image.open(tmp_isim)
imgmat = img.load()
x,y= img.size
x1=0
y1=0
deger =0
temizlemes =[]
for x1 in range (0,x):
    for y1 in  range(0,y):
        if imgmat[x1,y1] == 0:
            deger = temizleHips(x1,y1,x,y,imgmat)
            temizlemes.append(deger)
            if deger != imgmat[x1,y1]:
                print "noktalar : "+str(x1)+","+str(y1)+" ilk : "+str(imgmat[x1,y1])+" son: "+str(deger)
        else:
            temizlemes.append(imgmat[x1,y1])
img.putdata(temizlemes)
img.show()
img.save(tmp_isim,"TIFF")

tem = img.load()

我得到这张图片; http://s16.postimg.org/wc97bdzdt/a356.png 但是,我想在第二张图片上清除黑色像素周围的“s”。我找不到问题出在哪里

4

1 回答 1

0

您应该尝试找到大轮廓并删除另一个轮廓

于 2013-10-15T04:37:34.647 回答