5
$\begingroup$

Me and some friends want to make a present for another friend and we want to put pictures of each of us, e.g., me

enter image description here

into a, e.g., one hundert dollar bill (replacing Benjamin Franklin and adequate color correction)

enter image description here

and as a watermark on the white left part of the 20 Euro Bill

enter image description here

I know I could use online stuff, e.g., https://photofunia.com/effects/100_dollars, but I would like to learn how to do this the geeky and fun way with Mathematica. Besides, I would like to print the generating code also for the present. Any ideas?

$\endgroup$
  • $\begingroup$ You could use image histogram matching to match the colours of the 100 dollar bill. $\endgroup$ – Rahul Apr 25 '17 at 22:01
  • $\begingroup$ Hmmm... I dont know if I am using it correctly, it does not seem to match the colors very well, or the color space of the bill is just to poor, see drive.google.com/file/d/0B4HppN1nEJ6KOXlEVE8yQWEtYUE/… . $\endgroup$ – Mauricio Fernández Apr 25 '17 at 22:34
  • $\begingroup$ Ah, my bad. It works better if you transform the face to monochrome, ImageApply[{1, 1, 1} ({0.3, 0.6, 0.1}.#) &, face], and use only the face part of the bill, ImageTrim[bill, First@FindFaces[bill]]. Then you get i.stack.imgur.com/3gBWp.png $\endgroup$ – Rahul Apr 26 '17 at 22:57
5
$\begingroup$

Here's a suggestion for getting the picture of your face to have the proper colors of the bill:

bill = Import["https://i.stack.imgur.com/niI83.jpg"];
face = Import["https://i.stack.imgur.com/1Ub07.jpg"];

billColors = Sort[DominantColors[bill]]

quantize = ColorQuantize[face, 3];

faceColors = 
 Sort[RGBColor @@ # & /@ 
   DeleteDuplicates[Flatten[ImageData[quantize], 1]]]

ColorReplace[ColorQuantize[face, 3], Thread[faceColors -> billColors]]

While this doesn't address the whole problem, it's one step of it. You might also find the FindFaces function useful as well:

boxes = FindFaces[bill];
HighlightImage[bill, Rectangle @@@ boxes]

but it would take a little more effort to get this to work well.

Hope it helps!

$\endgroup$
  • $\begingroup$ Thanks! Is the first code block correct? I get an error for ColorReplace. Also, in the second code block, should it be bill instead of i in HighlightImage? $\endgroup$ – Mauricio Fernández Apr 25 '17 at 21:42
  • $\begingroup$ The first code block works well for me, see puu.sh/vw8EK/526dbd8804.png. And yes, you were correct about my second code bloc, thanks for catching that. $\endgroup$ – user6014 Apr 25 '17 at 21:51
  • $\begingroup$ Thanks, weird, in my Mathematica version 11.0.1, I get 4 dominant colors for the bill, see drive.google.com/file/d/0B4HppN1nEJ6KSFRWbUg3U0U1UXM/… . You got 3, that was my problem in the arguments of ColorReplace $\endgroup$ – Mauricio Fernández Apr 25 '17 at 22:00
  • $\begingroup$ Is there any difference between your faceColors and Sort@DominantColors@quantize? $\endgroup$ – Mauricio Fernández Apr 25 '17 at 22:21
  • $\begingroup$ @MauricioLobos interesting. You can do something like quantize = ColorQuantize[face, Length@billColors] which would work pretty well. Regarding your second question, for some reason the colors look slightly different. Would take some more investigation as to why that is, but for some reason they don't look the same when I examine the underlying numbers that generate the colors. I like the idea though. $\endgroup$ – user6014 Apr 26 '17 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.