How to sharpen an image using OpenCV? There are many ways of smoothing or blurring but none that I could see of sharpening.
相关问题
- How to get the background from multiple images by
- Try to load image with Highgui.imread (OpenCV + An
- CV2 Image Error: error: (-215:Assertion failed) !s
- Is it a bug of opencv RotatedRect?
- How do I apply a perspective transform with more t
相关文章
- How do I append metadata to an image in Matlab?
- opencv fails to build with ipp support enabled
- Code completion is not working for OpenCV and Pyth
- Face unlock code in Android open source project?
- Python open jp2 medical images - Scipy, glymur
- How to compile a c++ application using static open
- On a 64 bit machine, can I safely operate on indiv
- Converting PIL Image to GTK Pixbuf
You can try a simple kernel and the filter2D function, e.g. in Python:
Wikipedia has a good overview of kernels with some more examples here - https://en.wikipedia.org/wiki/Kernel_(image_processing)
For clarity in this topic, a few points really should be made:
Sharpening images is an ill-posed problem. In other words, blurring is a lossy operation, and going back from it is in general not possible.
To sharpen single images, you need to somehow add constraints (assumptions) on what kind of image it is you want, and how it has become blurred. This is the area of natural image statistics. Approaches to do sharpening hold these statistics explicitly or implicitly in their algorithms (deep learning being the most implicitly coded ones). The common approach of up-weighting some of the levels of a DOG or Laplacian pyramid decomposition, which is the generalization of Brian Burns answer, assumes that a Gaussian blurring corrupted the image, and how the weighting is done is connected to assumptions on what was in the image to begin with.
Other sources of information can render the problem sharpening well-posed. Common such sources of information is video of a moving object, or multi-view setting. Sharpening in that setting is usually called super-resolution (which is a very bad name for it, but it has stuck in academic circles). There has been super-resolution methods in OpenCV since a long time.... although they usually dont work that well for real problems last I checked them out. I expect deep learning has produced some wonderful results here as well. Maybe someone will post in remarks on whats worthwhile out there.
One general procedure is laid out in the wikipedia article on unsharp masking: You use a gaussian smoothing filter and subtract the smoothed version from the original image (in a weighted way so the values of a constant area remain constant).
To get a sharpened version of
frame
intoimage
: (bothcv::Mat
)The parameters there are something you need to adjust for yourself.
There's also laplacian sharpening, you should find something on that when you google.
you can find a sample code about sharpening image using "unsharp mask" algorithm at OpenCV Documentation
changing values of
sigma
,threshold
,amount
will give different resultsTry with this:
You might find more info here