Assign a value to a shape, in Python - 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.

Related

Get color of specific pixel in image using python

is it possible to get color of specific pixel from image using python?
Something like:
colorOfPixel = pixel(1, 9)
Looking at another answer I found, on a similar question, it appears as though 'It's probably best to use the Python Image Library to do this which I'm afraid is a separate download.'
It's quite a good answer, I'd recommend checking it out!

Python - differentiating similar images

I am trying to detect the differences in two images in python (object present or not). I tried different approaches with opencv and pillow for python. The goal is to check if an object is present or not. And if possible i want to extract the coordinates of the changes (with a bounding box)
The problem is, that the images are not 100% identical. There is always a very slight change in angle or lighting. Thresholding didnt do the trick as expected....
Is there any other approaches that you would suggest?
Thanks in advance
You can use the Structural similarity index for a robust image comparison:
https://scikit-image.org/docs/dev/auto_examples/transform/plot_ssim.html
This is implemented on scikit-image package.

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.

python library to find outline of image

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.

Adding multiple images to one canvas in Python

I want to load a number of images from harddrive and place them on a larger white background. And I want to do it in Python. I am wondering what is the best way of doing that. I am using a windows machine and I can use any library I want. Any pointer to a webpage or a sample code that can point me to a good direction would be appreciated.
Something like this:
A very popular image processing library for Python is PIL. The official PIL tutorial might be useful, especially the section about "Cutting, Pasting and Merging Images".
PIL isn't enough. Try also with PIL the aggdraw library.
But aggdraw also isn't enough. It works poorly with transparency. I mean 0.5-1 gray pixel around opaque object over the transpparent area.

Categories