python library to find outline of image - python

I am working with Python and PyQt4. I am looking a library with which I can find the outline path of an image (bitmap). With "outline path" I mean a polygon, which separates filled (non-transparent) pixels in the middle of the image from transparent pixels surrounding them.
I can not find anything via google, which kind of makes me wonder if I am using the correct search terms.
Thanks!

There are similar questions here on Stack Overflow which may be of use... ? Essentially you're trying to do edge detection; try searching for that..

OpenCV has a function called FindContours which does what I want.

Related

How to check if two points (characters) in an image are at the same horizontal level?

I'm a beginner and would like to know methods that could be used to check if two characters in an image are at the same horizontal level. Any help would be appreciated.
I'm looking for a simple method using python image processing.
Use OpenCV or PIL library. These libraries can help finding the bounding box/rectangle of the characters. Then you can use that info to compare positions and verify if they are on same level.
check: https://docs.opencv.org/3.4/dd/d49/tutorial_py_contour_features.html

Rotating and cropping a ROI from minAreaRect() OpenCV python

I'm trying to make a program that rotates and crops an image ROI (without losing a single pixel of the frame) based just on what minAreaRect() returns (from seeing what it can mark with drawContours).
Now since I don't understand what the function returns other than the rotation angle(list [0:1]) I'm struggling to make that myself. All I found on the internet was a Stack Overflow question with code that wasn't really explained very well and didn't realy work (atleast for openCV 3.6 not)
May I have any clues to what is the return syntax of this function and what is the method and keywords to search for such things, as well as a short little function that can maybe do that rotation and cropping? Since that looks like a quite common and simple thing to achieve.

Fill image with a certain color similar to how Paint does it using PIL? [duplicate]

I want to programmatically modify a bitmap using python but don't really need a thorough grounding in the subject, so would like to concentrate on learning just what I need to get the job done.
A good example of the kind of thing I'm after would be a bitmap image of england and it's counties. This would initially display a black border around all the counties on a white background.
So far so good, but how can I dynamically change the background color of a county?
Off the top of my head I was thinking I might find a flood-fill routine that works similar to a simple paint app. Something that changes all the pixels within an area enclosed by a specified color. I've had a quick look at the PIL documentation but didn't find anything I recognised as a flood fill function?
I don't yet know exactly what a mask is or how to use it but maybe this is an avenue I should explore. Maybe I could define a mask for each county and then use the mask to guide the fill process? Can masks be defined and stored within the bitmap for later use by my program?
Same goes for paths???
Any help or pointers would be greatly appreciated.
PIL has an undocumented function ImageDraw.floodfill:
>>> import ImageDraw
>>> help(ImageDraw.floodfill)
Help on function floodfill in module ImageDraw:
floodfill(image, xy, value, border=None)
Fill bounded region.
(Flood-filling should generally be a last resort because it interacts poorly with anti-aliased lines. It is usually better to get the actual boundary data for the counties and then draw a filled polygon. However, PIL doesn't support anti-aliased line drawing so this advice is useless unless you switch your drawing module to something more capable like PythonMagick or pycairo.)
You can try the opencv binding in python. Here is some example: http://opencv.willowgarage.com/documentation/python-introduction.html
You can then use the cvFloodFill function to flood fill a region.

Assign a value to a shape, in Python

Is there a way, in a picture:
to detect a shape (eg. a circle).
to relate the shape with its location on the picture (eg. left, right, center) and to assign a value (true or false).
I think that there is a solution using PIL and SciPy, but do not know where to start. any tips?
Thanks and sorry for the bad english.
You might want to use OpenCV for this.
Python bindings for it already exist (they are not very pythonic though) so it shouldn't be too hard to get into it.
I would recommend SimpleCV. I have recently found it. It is very easy way how to deal with opencv in python. They have also examples. There is also detection library attached.
We've tried to make it quite easy in SimpleCV.
import SimpleCV
img = SimpleCV.Image('foo.png')
blobs = img.findBlobs()
circles = blobs.filter([b.isCircle() for b in blobs])
now circles is just a list, each object in that list is a feature and has all the relevant information like x,y,area,color,etc.

How to find a fix number of (almost) fixed proportion rectangles with opencv?

I am writing a simple fly tracking software and I would love some input from opencv experts.
The image I have looks pretty much like:
I used to do tracking using kmeans and PIL/numpy but I re-wrote everything to use blob detection in opencv. Tracking works OK but I would also like to automatize division of ROI.
What I need to do is find each of the 32 grooves that appear in the picture, where flies live. See the black rectangle on the image as example of what I mean.
I think cornerHarris may be what I need but how do I specify only the grooves and not each single rectangle found in the image? All those grooves have proportions of roughly 10:1.
Thanks!
I don't think cvCornerHarris is even close to what you need.
A much better start would be to experiment with the demo available at: OpenCV-2.3.0/samples/cpp/squares.cpp. This technique uses Canny(), dilate() and findCountour().
Right out of the box, this demo outputs:
I believe that with a few tweaks here and there you can have your party started.

Categories