1

I'm trying to imitate in a simple way (=> without any I.A.) the old trichromy process to colorize B&W photographs.

Source : CNRS

Here's the start picture :

enter image description here

I copied this picture in a red, green and blue version by using Pillow :

enter image description here

Each filtered picture has a reduced opacity (I used a putalpha(round(255/3)) for this case), and these are valid PNG files.

Then, I tried to merge this three samples, but there are no colors at the end. The results is the same by using paste or alpha_composite after a for loop :

enter image description here

Was I too optimistic or did I miss something to achieve this ?

EDIT

Here's the filter color function. It's certainly heavy because it compared each red, green and blue level of apixel in a picture with the red, green and blue level of the filter's color. But, still :

def color_photo(file:str,color:tuple,def_file_name:str):
    """
        This function colorizes a picture based on a RGB color.
        Example : put a red filter on a B&W photo.
    """
    try:
        format_file = file.split(".")[-1]
        img = Image.open(file).convert("RGB")
        pixels = img.load()
        res = img.info["dpi"]
        w, h = img.size
        for px in range(w):
            for py in range(h):
                l_col = [int(new_level) if int(new_level)<int(old_level) else int(old_level) for new_level,old_level in zip(color,img.getpixel((px,py)))]
                pixels[px,py] = tuple(l_col)
        img.save(def_file_name+"."+format_file,dpi = res, subsampling = 0, quality = 100, optimize = True)
    except:
        print("You must do a mistake handling file names and/or the tuples of RGB's color instead of something like (234,125,89)")
Raphadasilva
  • 565
  • 1
  • 6
  • 21
  • Each pixel has exactly the same amount of red, green, and blue. That's simply gray. You'd have to somehow vary the proportions of R/G/B in order to get any visible color in the result. – jasonharper Dec 27 '22 at 19:16
  • I'm not sure to quite understand... How colors filter could produce three different images if their pixels are the same ? – Raphadasilva Dec 27 '22 at 19:18
  • I don't know for sure how you are creating your three filtered images from the original greyscale image, but I can take an educated guess. Probably your original greyscale image has three channels: Red, Green and Blue (RGB). However because the original image is greyscale, at each pixel the values of all three channels are equal. So say at some pixel location in the original image you have the RGB value (123,123,123). I suspect that in the Red filtered image at this location you have (123,0,0), in the Green image you have (0,123,0) and in the Blue image you have (0,0,123). – Wilf Rosenbaum Dec 28 '22 at 01:21
  • OK, these explanation as clearer. I can copy the main lines of B&W-unique colors filter function – Raphadasilva Dec 28 '22 at 06:14
  • I think you could try to look info on how our eyes response to each of primary colors, and multiply your RGB values by that factor, that way you will have different values for pixels and won't end up with gray image – aramcpp Dec 28 '22 at 07:11

1 Answers1

2

The trichromy process starts with three different images, or inputs. One is the light relected by the object passed through a green filter, the next through an orange filter and the third through a green filter.

You don't have that. You only have a single input image, and though it may be expressed in RGB terms, the red, green and blue channels are all identical.

There is simply no colour information available to you from which to construct, construe or create a likeness of the original. Anything you do is pure guesswork. Imagine looking at each pixel in the image and saying "Mmmm, this pixel has a grey value of 146, now what were the three R, G and B values that gave rise to this?". How could you possibly know?

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • So I was too optimistic ? The issue is that we must photograph the same subject in B&W but with filters directly on the camera ? If yes, I close with your answer. – Raphadasilva Dec 28 '22 at 09:26
  • And no, channels RGB of filtered photos are not strictly identical : if they were, output pic would be litteraly the same than the input one... – Raphadasilva Dec 28 '22 at 09:29