How to implement the magic wand function in Python - python

I have a image region labelling programme which was coded with python and library of PyQt4, I want to implement the magic wand function like photoshop and GMIP to selection a region referring a object and then to label the region. Could you tell me how to implement that or Are there some libray which can be used to deal with the issue.

Thank you, I have found that a [blog]: http://www.losingfight.com/blog/2007/08/28/how-to-implement-a-magic-wand-tool/ "blog of Andy Finnel" which includes the detail of implementing such algorithm. I also found that downscaling the image that you will process and then rescale the image up is a good ideal for performance reason.

Related

using python to obtain objects in an image

I have this picture. I need to identify the animal in this picture as shown using an image processing algorithm. I'm thinking of using Python for this. But I don't know which algorithm to use and I don't know where to start. Where should I start?
image
The best place to start is fast.ai. You will find the videos you need and the code. You can do it on any computer, even a cheap laptop. You will also want to look into LIME model explanations for image classifiers.

Get black region from image using Tensorflow and Python

I'm trying to get the black region from an image using TensorFlow. To this point I was using OpenCV but it fails to get the hole region given that the gray scale is very complicated.
The image I'm using is a photo of a electric meter, the whole meter is white(normally) except for the part with the numbers that is black. I would want to isolate this part in order to get the numbers later on.
To de the date, I have been using the function findContours from OpenCV, with a defined threshold .
I have seen that TensorFlow is very potent so I think this could no be a problem, but I can't find any documentation. Any hints? Thanks!
Tensorflow is a general purpose math library that is unique in two respects:
It provides automatic differentiation.
It has efficient kernels built to run on either the CPU or GPU.
It does have a library of image functions, but it's nowhere near as extensive as OpenCV, and will never be. Those are mostly for data augmentation (as it pertains to ML) and data loading.
Note that you can run OpenCV code on the GPU in many cases (I'm not sure about findContours in particular. So sticking with OpenCV should be considered.
But within tensorflow you would have to re-write that function yourself. In looking at the code (which I provided a link to in your question) it doesn't look very hard to do. You could replicate that in symbolic tensorflow operations in relatively short order, but nothing like that exists pre-built in tensorflow. Nor is it likely to in the future.

Python: Recognize a part of an Image, and get coordinates

I have a problem. I have a screenshot of my screen, and want to recognize a simple button. (I know how the button is looking, and what to find). How to do it? Using PIL? I just want coordinates.
I think OpenCV will be a easy answer -- Train an image detector on your button and it will return coordinates. I would suggest a cascade classifier, even though it might be overkill for find a button (Its usually used for face recognition) the library support is very good so it will make your life easy rather then homebrewing something. Resource use is very good also it is designed to run with very little CPU and memory.
http://opencv.org/
http://docs.opencv.org/2.4/doc/tutorials/objdetect/table_of_content_objdetect/table_of_content_objdetect.html#table-of-content-objdetect

Tracking an object via OpenCV

I am trying to track an object and mask or Hide it (a CODE in this case) using OpenCV and Python. As example I am using this video , the code will showing on 1min19s :
https://www.dropbox.com/s/eu01hxoxmd3ns5f/capture-3.mp4?dl=0
What I need is to keep track on the CODE and mask or Hide it as the video without detecting other parts of the video as the code. Tracking by colour doesn't work here.
Any idea for a good approach on this problem?
Tracking is much more complex than searching the similar colour. OpenCV has implemented some tracking algorithms, what you need to do is to use the existing apis to solve the problem. Here is an introduction to OpenCV tracker.
If you do not stick to OpenCV, dlib is also a c++ library with python interface which also implements object tracking algorithms.

Fractal image scaling with Python

I am in a position where relatively low resolution images are provided (via an API, higher resolution images are not available) and high resolution images need to be generated.
I've taken a look at PIL and it's just great for about everything... Except scaling up images.
It has the common resizing algorithms:
Nearest Neighbor
Bilinear
Bicubic
Anti-aliased
I would like to use Fractal Resizing (as per jeff's post on coding horror), but alas, PIL has no support for this kind of resizing.
Further Google searches yield no alternative libraries to provide fractal image resizing either.
Does such a thing exist or do I really have to buckle down and write my own fractal resizing algorithm?
I'm no expert but from my current vantage point, that looks like a pretty steep learning curve :(
If no such library exists, maybe you have some advice where to learn about fractal compression algorithms?
There are algorithms, and you're definitely not going to find them in Python. To start with, you can take this paper :
Daniel Glasner, Shai Bagon, and Michal Irani, "Super-Resolution from a Single Image," in Proceedings of the IEEE International Conference on Computer Vision, Kyoto, Japan, 2009.
It is very much state of the art, highly sophisticated, and producing promising results. If you ever make it into a python implementation please release it to the public :)
Fractal-based image scaling is still quite unusual and hasn't settled down onto one accepted-best algorithm yet. I'm afraid you aren't going to find it in standard image processing libraries yet.
It's also not invariably preferable to bicubic. It can have artefacts which will be undesirable for some kinds of images. For me, Jeff's example image looks a bit weird and unnatural around the sharp edges like the right-hand-side of the nose. Better for some values of ‘better’, sure, but I wouldn't blanket-apply it to all my images.
(This is the case with other ‘advanced’ upscaling techniques, too, including the better-known and more widely-implemented Lanczos/Sinc method.)
Check out this solution using Residual Dense Networks:
https://github.com/idealo/image-super-resolution
Good documentation and rather easy to implement. They even have docker builds and google collab notebooks available. See the docs

Categories