简体   繁体   中英

Image Processing use Python find black contour

I have a problem Please help me if I have an image multi 16 in 1 image I wanna find black contour in an image just one show YES if find black contour What should I do? in Image Processing use Python! 在此处输入图片说明

Python Image Library can give RGB data of an image. You can get RGB data simply by using

 import Image
 pic  = Image.open('/path/to/file')
 rgbdata = pic.load()
 width, height = pic.size

 def identify_black():
     for i in range(width):
        for j in range(height):
            if rgbdata[i,j] == (0,0,0):
                #print rgbdata[i,j]   
                print "Yes"
                return True
            break

identify_black() 

You can view the data purely in terms of RGB values of ijth pixel in rgbdata[i,j]. width and height help you define the blocks.

RGB value for black is (0,0,0). So if in your image list, a block of pixels give you (0,0,0) you can use that i, j th number to find in which block you have black! In fact, you identify any color!

Hope this helps.

一个非常简单的解决方案是阈值化,只需将任何非黑色像素(0,0,0)设置为(255,255,255),您将在图像中拥有所有轮廓。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM