Jump to content
Sign in to follow this  
Guest cloudbase

Coloring B&W Images - An idea in testing

Recommended Posts

Guest cloudbase

I am working on a program that colors black and white pictures.I have been wanting to make some photorealistic New Zealand scenery, luckily we have a fantastic resource found at LINZ http://www.linz.govt.nz/rcs/linz/pub/web/r...exmap/index.jspHowever it is only in the last couple of years that they have photographed in color (resolution 2.5m / pixel), the previous years they only photographed in black and white.So I got to thinking how do you color the black and white pics, here is my mission history as follows,I have tried using photoshop using methods mentioned frequently in this forum with frustration, and the thought of automating the process seemed attractive, but how??what I have been working on is a program that colors the black and white pics by using color information from an adjacent color image.The main issues encounted are that black and white pics use a 256 (0-255) grey scale.RGB images are made using 256 Red, 256 Green, 256 Blue, giving a possible 256*256*256 = 1703936 color possibilities.So for each possible grey pixel there are (256 * 256 ) = 6656 possible colors to choose from, I first wrote a program that created a sort of color palette, it took the adjacent COLOR image and converted it to black and white, with this I scanned through the B&W image and for each grey scale I tallied the number of colors and a count for each color that mapped to it, yes each grey did have 1000's of potential colors in practice.So with this rosetta color palette I could color the black and white image, for example gray level 150 mapped to 1400 possible colors, for my first program I used the color with the highest count for each grey level.So with this color palette I then colored my black and white image.Results were okay with this method but I could see improvement on the method. The main problem was the black and white image was stained with a layer of the average color from the original color image I used, a lot of contrast and variation was lost.So I started on version 2Version2 needed a process to reduce this average color staining due to the limitation of choosing a single color from a range of 1000,s of colors.So I thought of the concept of creating a color palette using not only the color from the color image like in my first program but also isolate some form of texture information.My current efforts involve taking the color image and converting it to black and white (more about this process/problem later), then for each pixel and also adjacent pixels I note the grey level, at the moment I also look at the 2 pixels to the right of the pixel I am processing, I end up with an array (255,255,255). So I now have created for each pixel 256*256*256=16777216 possibilities, thats funny the same number as possible colors in the RGB format. I could use and would like to use an even bigger number of adjacent pixels but this slows the program down heaps.The end result of this is that an individual grey pixel gets a mapped color using the grey levels of the pixels around it, ie its like the pixel is colored using the variation/texture in grey around it. So with this palette of color/texture I color my black and white image of choice, if it comes across a texture that it hasnt learned from the color image previously then it does a search for the closest match.This is the point I am at at the moment, the programming process has been slow as I have had to learn to program as I have gone (Yes no previous programming experience). the analysing process and conversion is slow, but its better to go to bed and let the computer grind away overnight on a bitmap (size 8000* 6000 pixels) than doing all the work by hand in photoshop.The results rely on choosing a good color image to represent the colors and textures that will be required for the image that is to be colored, luckily I just use a LINZ Color image that is adjacent to a black and white image that I want to color that has a similar range of vegetation, paddocks, forests, towns, roads etc.some of the more common 3 pixel patterns/textures still map to 10-20 possible colors (better than thousands of colors), so I just take the color with the highest count, I would like to increase the pixel pattern/texture to a higher number but the array causes a computer out of memory error, I might have to think up a better method.One problem I am left with is the process of converting the color image to black and white to create the color/texture map, when I compare the histogram of this image to the histogram of the B&W image I want to color there is a variation/skew that needs to be adjusted, this I am doing by hand using photoshop, but I am looking at a more elegant automated process, and I need to speed the coloring process up.some others ideas I have thought about include using mesh altitude information to further reduce possible color choice in making the color/texture palette but I do not know how to get this information from a bgl file and it would mean calibrating the images to a coordinate system like in terrabuilder, a bit to complex for me and I am sure using the texture process does the same thing in effect. The results of this new process are much better, with improved maintanence of color and range of contrast.The final colored image can be manipulated later by photoshop for those finishing touches.I have been using visual basic.net for the coding.Has anybody done anything like this before? please let me knowDavid

Share this post


Link to post
Share on other sites
Guest A_Delta_Sierra

Hi David,It looks like you and I are thinking along the same lines. I too am attempting to make a complete mechanical system for converting the grayscale images to color. Looks like you have done a lot of number crunking on the subject.In reading your post ---- I think the grayscale images only have from 1 to 255 possible shades of gray. Not the 256X256 matrix you indicated. Also. I think trying to collect data from a colored reference image into a 256X256X256 matrix is a bit of overkill as you puter has told you. If you are populating the cells in the matrix with your own program, keep in mind the cell sizes do not need to be uniform. Example, the upper,left, front cell could contain all of the levels from 1to30 for each rgb. While a cell in the middle of the specturn could be closer, example 140 to 145 range for the rgb values. A quick way to "see" where you cell size and concentration levels need be is by looking at the Histrograms in Photoshop. (Image - Histrograms) Move the mouse back and forth over the graph and watch the percentile change. If you hold the left mouse button down and move it over the histrogram, the percentage of pixels with the value will be shown. This way you can see real quick where you need to have different cells with different spacing to capture the essence of the colored image you are using in the rosetta pallete. ;-)I like your method it is very similar to what I have been working on for the last week for we folks who have zero artistic talent. We have done "similar" test work this week on terraserver images of Central Illinois.Give me a ring at rsam@mtco.com if you would llke to discuss more.Bob SamuelsonRegards,BobSSeems the rage to talk about the "size and speed" of each others computer. Beat this if you can for solving novel/unique problems.. ..Have K&E and know how to use it!

Share this post


Link to post
Share on other sites
Guest A_Delta_Sierra

Hi again David,I play while you sleep. ;-)We can get the "xxx most popular colors", provided you don't want more then 256, for the rosetta stone right from Photoshop. We still need a good machinical way to match them to the grayscale. That will come. Here is how to find those first xxx most needed colors in Photoshop....Image....Mode .....Indexed Colors........Palette -> ADAPTIVE (key to solution -- adaptive!)........Colors--- enter from 1 to 256 ........Options -- NONEThis will then convert the rosetta image into the number of colors selected above.The color range will still be from 0 to 255 for each rgb value. BUT, the total number of unique colors will be the value you selected. Photshop generates the best possible palette to duplicate the rosetta with. ;-)To see this new color range:....Image.....Mode ......Color Table.Unfortunately, they are not sorted in order of occurance. ;-(The rgb value for each color can be obtained by double clicking on the color chip.And now you can convert the image back to a rgb, it will only have xxx colors.To get the range sorted, you will need to use your matrix as you have before, but it only needs to the have the cells you discovery from the "color table".Now if you tabulate the number of pixels in the various grayscale levels using you current matrix work. The high count grayscale cell should be matched with the high count color solution. likewise the "low counts" need to be matched. Low count -- I been called that before. ;-)The key is to use 256 cells for the color because you grayscale ranges from 0 to 255. (just thought of this trick)The grayscale image can then be colored using the method I have outlined in the other postings on this subject.Big strides today in getting to a solution. Regards,Bob Samuelsonrsam@mtco.com... Bill W -- I was "SAM" for 40 years at work. I knew you were "talking to" to me in the other tread. ;-)

Share this post


Link to post
Share on other sites
Guest A_Delta_Sierra

Hi David once again, ,,,Closer yet to what you wish to do.In the previooous msg I showed how to use Photoshop to reduce the image to 256 unique colors. The challenge remained on how to reference those 256 unique colors to the 256 levels of grayscale.That turns out to be the easy part. Take those 256 unique colors and convert them to a grayscale by using the math relationship you will find here. -- Along with C and VB code. ;-)http://www.bobpowell.net/grayscale.htmSorry about doing this a little piece at a time.You probably will end up with one grayscale being assign to two or more rgb values. Then I guess we will have to select which one to use by which one is the most popular?Regards,BobS

Share this post


Link to post
Share on other sites
Guest cloudbase

Hi BobThere are 256 grey levels (0-255), dont forget to count 0, (0=black, 255 = white), well this is how its referenced in VB.Net.Regarding the 256*256 matrix that you mentioned, what I was talkig about was that in theory for every single grey level there are 256*256 possible RGB colors to choose from, for example if you convert a color to a grey level say using an average of the RGB color components, eg color(R 255,G 45,B 0) = Grey 100color(R 255,G 44,B 1) = Grey 100color(R 255, G 43,B 2) = Grey 100..color(R 0,G 45,B 255) = Grey 100There are 256*256=65536 color possibilities if you work it out for each individual grey level, and to color a grey pixel you need to choose only one color.With my technique you dont need to limit yourself to 256 color possibilities for the coloring of a black and white image, in fact you can in theory use all 256*256*256 colors in the RGB color format.The palette that I generate is not limited to only 256 greys. I also use the surrounding pixels to generate a much larger palette.For example I have a sample representive color image that I want to use for the generation of a color palette, ie this color image looks much like how I want the Black and White image that I have to look when it is colored, so now with this sample color image I convert to a greyscale image (represented here in grey scale values 0-255) x0 x1 x2 x3 x4 ,xny0 100, 150, 120, 110, 130, . . . .y1 102, 145, 125, 115, 120, . . . . y2 105, 150, 120, 110, 125, . . . . y3 . . . . . . . . . ynMy process cycles through all the pixels, for each pixel I add it to the palette array, BUT the palette looks at the pixel grey level and also the pixel grey levels to the 2 pixels to the right of it (however any pattern or number of pixels could be used). In our example we start at x0, y0. So to my array I index it asarray(px0, px1, px2), array(100,150,120) to this array I add the color from the color image at position x0,y0The next iteration would bearray(150,120,110) and set this to the color at position x1,y0 from the color imageSo in effect when I come to recolor my greyscale image, I need to look at the variation of greyscale of the pixels to the right of the pixel I want to color as its the unique spread of these 3 greyscale value that will decide which color will be used to recolor with.however when I have scanned the whole image I can still end up with a large range of color possibilities from which I have to select 1.One issue I am resolving it making sure the color image that is converted to greyscale resembles closely the spread of grey values in the greyscale image that I want to recolor.I hope this clarifies the process that I am using.It is this sort of process that cant be done in photoshop unless you write a scriptI have tried using your indexed color process but it was to tedious to then select which grey was to be mapped to one of the indexed colors, although I hadnt thought about using the histogram to weed out the likely colors, its a nice idea, yes you could easily write this in a program, I might try it thanks.For your interest If you send me a color pic and a black and white pic you want to recolor, send it to me and I can run it through my programDavid

Share this post


Link to post
Share on other sites
Guest cloudbase

Thanks for the code, I am familiar with that particular RGB weighted function to convert RBG to greyscale. Although I do mention a crude averaging solution for the example in my last post, what I have been doing so far is just using photoshop to create the greyscale image from the color image.The problem I have created in making my process more complex but thorough is that I have to have both greyscale images very similar to each otherSo I am creating a greyscale transform so both images have a similar histogram spread, a bit like what you are doing with the indexed color mapping to the greyscale levels.David

Share this post


Link to post
Share on other sites
Guest A_Delta_Sierra

The solution is simple! Isn't it? We have 3 variables used in calculating the grayscale.Thus, knowing y, lumonosity I can solve for rgb by writing three equations.Yp=.3Rp+.59Gp+.11BpYleft=.3Rleft+.59Gleft+.11BleftYright=.3Rright+.59Grgith+.11BrightCan't subscript here so:Yp means take the y at the pixel we are converting for one value of y.Yleft means take the y at the pixel to the left of the one we are convertingYright means take the y at the pixel to the right of the one we are converting.Three unknown -- rgb --- three equations. Linear algebra 101.certainly the first and last column would require special handing. Use the pixel to the top or bottom for Y, depending if we are on the first or last line of pixels.This will loose some shapness, but that is the price to pay? Wonder if it is too much.Good puzzle that others have solved. Search on grayscale to color with google or yahoo. ;-)you will like this one:http://www.cs.sunysb.edu/~tfwelsh/colorize/Comments?Regards,BobS

Share this post


Link to post
Share on other sites
Guest cloudbase

Nice article on coloring, just need the code :) I notice they use swatches to prevent the staining that I described.I look forward to any other ideas you can throw at me.David

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...