3

I'd like to implement an image recoloring algorithm to produce results similar to what is shown here:

http://www.morethantechnical.com/2010/06/24/image-recoloring-using-gaussian-mixture-model-and-expectation-maximization-opencv-wcode/

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?

Alex Riley
  • 169,130
  • 45
  • 262
  • 238
n.jmurov
  • 123
  • 2
  • 12
  • Asking for external resources (libraries/tools) is considered an Off topic question. – ρss Apr 24 '15 at 08:22
  • 1
    The first Google search I got is http://scikit-image.org/. – LittlePanda Apr 24 '15 at 08:33
  • scikit-image doesn't seem to have the EM and GMM functions. Perhaps you meant scikit-learn. However, I'm more interested in how to approach this problem in general to obtain the results as shown in the screenshots on that webpage. On another page, they also describe a different method - histogram matching - but since there are no images, I can't tell if the results would be as good as using the EM/GMM method. – n.jmurov Apr 24 '15 at 11:46

2 Answers2

2

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.

Community
  • 1
  • 1
cyriel
  • 3,522
  • 17
  • 34
  • Many thanks, I think I will give the first option a try since some comments to that article mention compilation error in the C++ code. I wouldn't know how to fix them if they occurred. – n.jmurov Apr 25 '15 at 07:23
2

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.

Nuelsian
  • 501
  • 7
  • 18