recolor an s/w image with his colored thumbnail?

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
tenim
Posts: 6
Joined: 2012-10-23T09:27:40-07:00
Authentication code: 67789

recolor an s/w image with his colored thumbnail?

Post by tenim »

hello,

i have a problem, i cant solve: i have a grayscale image(430x420) and an thumbnail of this image(91x120) which is a 24bit rgb image(colored). the thumbinail is horizontal smaller than the original image, but only a few pixels. i want to recolor the s/w image with the informations from the thumbnail but i doesn´t know how. can imagemagick do that and if not, which tool can do this?
i use imagemagick 6.7.6 Q8 static for win32.

thanks
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: recolor an s/w image with his colored thumbnail?

Post by fmw42 »

tenim wrote:hello,

i have a problem, i cant solve: i have a grayscale image(430x420) and an thumbnail of this image(91x120) which is a 24bit rgb image(colored). the thumbinail is horizontal smaller than the original image, but only a few pixels. i want to recolor the s/w image with the informations from the thumbnail but i doesn´t know how. can imagemagick do that and if not, which tool can do this?
i use imagemagick 6.7.6 Q8 static for win32.

thanks
If not proprietary, please post links to your two input images, so that others can test some ideas. Post your images to some free image hosting site and then put the links to them here.

Best thought is to resize the thumbnail to the same size as your grayscale image. Then convert the new colored thumbnail to YCbCr, extract the Cb and Cr channels and combine them with the grayscale to replace the Y channel, then convert back to RGB. This might work better with LAB or HCL, but those would require a more current IM version.
tenim
Posts: 6
Joined: 2012-10-23T09:27:40-07:00
Authentication code: 67789

Re: recolor an s/w image with his colored thumbnail?

Post by tenim »

as i mentioned in the other thread, the images are some personal stuff i want to post. the method should also work for every image and his thumbnail.
the thumbnail has not the exact aspect ratio as the original image, it has a ca. 10% lesser width.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: recolor an s/w image with his colored thumbnail?

Post by fmw42 »

tenim wrote:as i mentioned in the other thread, the images are some personal stuff i want to post. the method should also work for every image and his thumbnail.

If you resize your thumbnail to the exact same size as the grayscale image, to they match exactly? Or has the thumbnail come from some other image that is not exactly the same as the grayscale image?

If they do not match exactly (or nearly so) then the method mentioned above may not work too well.

The only other method I can think of is to use histogram matching. I have a script, histmatch, at the link below) to try to do that, but it only runs on Linux/Mac or Windows w/cygwin. I tried it on a grayscale version of the logo: image and though it recolored it. The colors were a bit faded or desaturated.
tenim
Posts: 6
Joined: 2012-10-23T09:27:40-07:00
Authentication code: 67789

Re: recolor an s/w image with his colored thumbnail?

Post by tenim »

the scaled image doesn´t match exact. an other scope of application are 2 fotos (one in color, the other in s/w) with the same person on the same background in different poses. in general, the colors should be recalculateble. i think to write a c-program which makes the following stuff:

thumbnail (color):
* convert every pixel to greyscale and save the old rgb-equivalent in a table (with pixel-position in the image) i.e. grey 123, rgb(23,55,104), area a3

image(s/w):
* scan the s/w image for the greyscale-values in the table and replace every greyscale-value with the one in the table if the value and the area matches (area is nessessary because it´s possible that 2 different rgb-values have the same greyscale-value).

this sould work, or? but i will start only coding if it exists no other, easier solution.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: recolor an s/w image with his colored thumbnail?

Post by fmw42 »

convert your color image to 256 max colors. get the colormap from the verbose info. make it into an array. convert the array values to grayscale and sort both arrays. Then take the sorted color array and convert it back to a 1D image and use that with -clut to apply it to the other grayscale image. see http://www.imagemagick.org/Usage/color_mods/#clut.

To convert r,g,b values to grayscale use the formula at http://www.imagemagick.org/script/comma ... colorspace for colorspace gray

You can extract the colormap from the verbose into using sed in unix and do the sorting with sort in unix. If on windows, sorry, I do not know how to do those as I am not a windows user.
tenim
Posts: 6
Joined: 2012-10-23T09:27:40-07:00
Authentication code: 67789

Re: recolor an s/w image with his colored thumbnail?

Post by tenim »

sounds complex. have written my c program to test the stuff i mentioned in the last post. well, the colorizing doesn´t work as i expected. the new image is not greyscale and not full colored. colors are very weak and some pixels are not treated.
it is much more difficult as i expected.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: recolor an s/w image with his colored thumbnail?

Post by fmw42 »

tenim wrote:sounds complex. have written my c program to test the stuff i mentioned in the last post. well, the colorizing doesn´t work as i expected. the new image is not greyscale and not full colored. colors are very weak and some pixels are not treated.
it is much more difficult as i expected.

Yes I coded some unix script to do the same and found the same results. I tested with the logo: image and its grayscale equivalent.

Color Image:
Image

Gray Image:
Image


Recoloring by sorting in sync the colormap for the color and gray images and creating a lut applied with -clut:
Image


Recolored using my histmatch script:
Image
Post Reply