Reputation: 123
I'd like to implement an image recoloring algorithm to produce results similar to what is shown here:
but using Python. However, I'm not sure where to start. I've been playing around with OpenCV but the functions mentioned in the article (expectation maximization and GMM) don't seem to be available in Python API. Can somewhat point me in the right direction as to what tools/libraries I should be using?
Upvotes: 3
Views: 2850
Reputation: 521
The key word you are looking for is "color transfer". I found this link really helpful http://www.pyimagesearch.com/2014/06/30/super-fast-color-transfer-images/
for Python install the color-transfer library like so;
pip install color_transfer
To use:
import color_transfer
destination_image = ... # import your destination image here
source_image = .... # import your source image here
new_image = color_transfer.color_transfer(source_image, destination_image)
Both source and destination images should be of type Numpy array.
Upvotes: 2
Reputation: 3522
First option is just implement this code in Python. It looks like all functions mentioned in article are avaible in Python API. CvEM
is just EM
(in module cv2):
>>> cv2.EM.__doc__
'EM([, nclusters[, covMatType[, termCrit]]]) -> <EM object>'
there is no CvEMParams
, because EM
already handles it. If you are looking for any other function/object, type dir(cv2)
in Python console and most likely you will find what you are looking for. Quite often things in Python API has slightly different names, but still it's not a big problem to find them. Note that some things may be in cv2.cv
module as well.
Second option is just to use this C++ code and call it from Python. Writing extensions for Python is not very easy, but if you use Boost.Python it shouldn't be very hard. Writing extension modules is quite popular task for Boost.Python so there are some good tutorials which describes that well. Good point to start might be this one. Writing converter for cv::Mat <->numpy.array might be a problem, but here is easy solution.
Upvotes: 2