At first, I did this where image
is a grayscale image and example
is a colored image.
BasicColorizer[image_, example_] :=
Module[{grayed, pairs, clustered, rules, default},
grayed = ColorConvert[example, "Grayscale"];
default = RandomChoice[Commonest[Flatten[ImageData[example], 1]]];
pairs =
Flatten[MapThread[List, {ImageData[grayed], ImageData[example]},
2], 1];
clustered = GatherBy[pairs, Round[100 #[[1]]] &];
rules =
Append[Round[100 #[[1, 1]]] ->
RandomChoice[Commonest[#[[All, 2]]]] & /@ clustered, _ ->
default];
Image[Replace[
Round[100 ImageData[ColorConvert[image, "Grayscale"]]],
rules, {2}]]]
And then
limg = First@ColorSeparate[img, "LAB"]
{lref, aref, bref} = ColorSeparate[ref, "RGB"]
l2 = HistogramTransform[limg, lref]
ImageHistogram /@ {l2, lref}
radius = 2
{neighimg, neighref} = ColorCombine[{
MeanFilter[#, radius],
StandardDeviationFilter[#, radius]}] & /@ {l2, lref}
nfun = Nearest[
Flatten[ImageData@neighref, 1] ->
Transpose[Flatten@ImageData@# & /@ {aref, bref}]]
col = Map[First@nfun[#, 1] &, ImageData@neighimg, {2}];
ColorConvert[
Image[Join[{ImageData@limg}, Transpose[col, {2, 3, 1}]],
Interleaving -> False, ColorSpace -> "RGB"], "LAB"]
This is a grayscale image.
Import["http://fc06.deviantart.net/fs71/f/2012/047/6/b/saint_basil__s_cathedral_by_tomdal-d4pwlwo.jpg"]
And this is a colored image.
Import["http://static.guim.co.uk/sys-images/Guardian/Pix/pictures/2012/3/14/1331719456752/St.-Basils-Cathedral-001.jpg"]
After that, I find Corresponding Points between these two images.
Every object from a grayscale image and colored image after colorization should have the same color.
To do this I chose the same images from the net: one grayscale and the other colored. Now how can I transfer the colors from colored images into grayscale?
I tried doing it with several methods but I encountered some colorization errors. What can I do?