How to motion deblur an image using OpenCV and Python? - python

So I have been asked to motion deblur a frame captured from a video, I am kind of new to this deblur filters so need help. The video does not contain any noise, just a vertical motion blur. I am not allowed to use skimage, or any other library except cv2. It would be a great help even if what technique or function I have to use comes to know. Thanks!

You can use the Motion Deblur Filter of opencv, if you specifically want to use opencv.
Following is the link to its documentation, which is fairly easy to understand:
http://amroamroamro.github.io/mexopencv/opencv/weiner_deconvolution_demo_gui.html
You can go for skimage as well. It has many function like deconvolution which can help in deblurring images.

I think that for this kind of problem you have to use the recent deep learning techniques. They outperform the classical approaches. I recommend to look on github for a repository that would already provide a trained network that can deblur the same kind of blur that you have.
I never tried it, but this could be a nice candidate.

Related

How many Blur Filter or Deblur models/modules are available in OpenCV or other python libraries?

I am doing a project where I have to remove noise, filter blur, and so many image preprocessing things to be applied in a real-time video to enhance the video quality. So at first, I broke down the video into frames then I wanted to use all the mechanisms.
So, my question is, which deblur approach should I apply to get my desired result, or is there any python library that will be better for my work?
Maybe you could start with scikit-image's Image Deconvolution to "filter blur" and median filtering to remove pepper and salt noise.
Seeing some images could be useful to help you more.

how to reconstruct in 3d of a scene from two images

I wish to make a 3D reconstruction of a scene. For that, I have 2 images of the scene taken from two different angles.
Is there a library that does that? (I work in python)
if not, what are the steps that must be followed?
if you have the code ready, it is welcome.
thanks
I have not tried it for myself yet, but it seems simple with OpenCV.
OpenCV has module for 3D reconstruction.
Also check out this tutorial.
Upd. Please look at comments from #berak below. I misunderstood yours question at first.
I found SfM-Toy-Library library on github, which uses algorithms from mentioned "Multiple View Geometry" book. It's written using OpenCV and better relates to the topic, but it might be not so easy to use library in Python.
You can use vtk
First step is image processing and second step is 3d reconstructions
For example you can try for first step:
1)Median Filtering
2)Image contrast
3)Thresholding
4)Noise reduction
And second step includes:
1)vtkMarchingCubes
2)vtkPolyDataMapper
3)vtkActor
4)Renderer
Also you can read this article : enter link description here

CAPTCHAs Image Manipulation using Pillow

As an exercise, I'm attempting to break the following CAPTCHA:
It doesn't seem like it would be too difficult to break as the edges seems to fairly solid and noise should be relatively easy to remove. Problem is, I have very little experience with image manipulation. Currently I'm using Python with the Pillow library to manipulate the CAPTCHA image, after which it will be passed into Tesseract for OCR.
In the following code I attempt to bring out the edges by sharpening the image and the convert the image to black and white
from PIL import Image, ImageFilter
try:
img = Image.open("Captcha.jpg")
except:
print("Can't load captcha.")
exit()
# Bring out the edges by sharpening.
out = img.filter(ImageFilter.SHARPEN)
out = out.convert("L")
out = out.point(lambda x: 0 if x<136 else 255, "1")
width, height = out.size
out = out.resize((width*5, height*5), Image.NEAREST)
out.save("captcha_modified.png")
At this point I see the following:
However, Tesseract is still unable to read the characters. As an experiment, I used good ol' mspaint to manually modify the image to a point to where it could be read by Tesseract:
So if can get the image to that point, I think Tesseract will do a fairly good job at detecting characters. So my current thoughts are that I need to enhance the edges and reduce the noise the image. Also, I imagine it would be easier for Tesseract to detect the letters if the letters will filled in rather than outlined, but I have not idea how I'd do this.
Any suggestions on how to go about this? Is there a better way to process the images?
I am short on time so this answer may not be incredibly useful but goes over my own 2 algorithms exactly. There isn't much code but a few method reccomendations. It is a good idea to use code rather than MS Paint.With code its actually really easy to break a captcha and achieve above 50% success rate. Behavioral recognition may be a better security mechanism or may be an additional one.
A. Edge Detection Method you use:
Edge detection really isn't necessary. In this case, just use the getpixel((x,y)) function and fill in the area between the bounding lines, recognizing to fill at lines 1,3,5;etc. and turn off the fill after intersection 2,4,6;etc. Luckilly, you chose an easy Captcha so edge detection is a decent solution without decluttering,rotating, and re-alignment.
B. Manipulation Method:
Another method I use utilizes OpenCV and pillow as well. I am really busy but am posting a blog article on this later at druid5.wordpress.com/ which will contain code examples of this method. Since it isn't illegal to get through them, at least I am told, I use the method I will post to collect data all the time. Mostly, contrast and detail from pillow, some basic clutter removal with stats, re-alignment with a basic dfs, and rotation (performable with opencv or easily with a kernal). Tesseract is a good choice for open source but it isn't too hard to create an OCR with opencv either.
This exercies is a decent introduction to OpenCV, PIL (pillow), image manipulation with math, and some other things that help with everything from robotics to AI.
Using flow control to find the failed conditions and try different routes may be necessary but the aim should always be a generic solution.

Python - Identifying/Processing an Image

I'm looking in to learning about processing and handling images with Python. I'm experimenting with searching the inside of an image for a specific picture. For example, this picture has two images in it that are the same;
In Python, how would I go about detecting which two images are the same?
I would recommend you to take a look at OpenCV and PIL, if you want to implement simple (or complex) algorithms on your own.
Furthermore you can integrate OpenCV with PIL and also numpy, which makes it a really powerful tool for this kind of jobs.

Otsu's Method and A Median Filter in Python

I've tried looking around and have been unable to find any implementation of either Otsu's method or a median filter into Python other than OpenCV.These are the only two links of documentation for the OpenCV functions that I've tried.
http://opencv.willowgarage.com/documentation/c/image_filtering.html
http://www.cs.indiana.edu/cgi-pub/oleykin/website/OpenCVHelp/ref/OpenCVRef_Cv.htm#decl_cvThreshold3
I checked this post first but it never really seemed to have a full solution that fits my problem.
Machine vision in Python
I'm basically looking to see if anyone knows any other functions that I can implement both Otsu's method and a median filter. I'm just trying to find alternatives before I have to program them into myself, but I would rather not have to reinvent the wheel unless necessary. Thanks for your help in advance, if you need some more specific information just let me know.
In response to the Otsu Method I was able to find an image processing packaged called Mahotas that contained it. All I had to do was easy_install it. The documentation can be found here.
http://packages.python.org/mahotas/index.html?highlight=otsu#mahotas.otsu
I am not sure about Otsu's method but the Scipy library has a whole sub-library dedicated to image processing. For example here is the link to their multi-dimensional median filter:
http://docs.scipy.org/doc/scipy-0.9.0/reference/generated/scipy.ndimage.filters.median_filter.html#scipy.ndimage.filters.median_filter
The matlab image toolbox includes a built in median filter.
http://www.mathworks.com/help/toolbox/images/ref/medfilt2.html
If you don't have the image processing toolbox, you can implement one using block processing.

Categories

Resources