Connecting Tech Pros Worldwide Help | Site Map

Converting grayscale - RGB to other colours

  #1  
Old June 4th, 2009, 07:56 AM
Newbie
 
Join Date: Jun 2009
Posts: 2
Currently I got a thermal image mapping program which converts grayscale pictures to RGB. Now, what I need to do is to convert those 3 RGB colors into other three colours. The choice of colours are white, black, red, green and blue.

To explain more, for the thermal mapping using grayscale converted to RGB, red denotes hot areas, green-zero, and blue-cold. What I want to do is to make a program that enables you to choose the colours from the five I mentioned above to represent the hot, zero and cold areas. This is the program, using Microsoft visual Studio C++ .

This program reads from the text file map24 and puts it in the RGB variable.
Expand|Select|Wrap|Line Numbers
  1. int readmappingFile()
  2. {
  3.     FILE *fp;    
  4.     int i;
  5.  
  6.     fp = fopen("C:\\map24.txt", "r");
  7.  
  8.     if(fp != NULL)
  9.     {
  10.         for(i=0; i<256; i++)
  11.         {
  12.             fscanf(fp, "%d %d %d", &R[i], &G[i], &B[i]);
  13.         }
  14.     }    
  15.  
  16.     return OK;
  17. }
This one deals with the RGB conversion.

Expand|Select|Wrap|Line Numbers
  1. int temperatureMappingCore()
  2. {
  3.     byte index;
  4.     int w, h;
  5.     int gWStep, cWStep;
  6.  
  7.     gWStep = inImg->widthStep;
  8.     cWStep = outImg->widthStep;
  9.  
  10.     for(h=0; h<inImg->height; h++)
  11.     {
  12.         for(w=0; w<inImg->width; w++)
  13.         {
  14.             index = (byte)inImg->imageData[h*gWStep + w];            
  15.             outImg->imageData[h*cWStep + w*3] = B[index];
  16.             outImg->imageData[h*cWStep + w*3 + 1] = G[index];
  17.             outImg->imageData[h*cWStep + w*3 + 2] = R[index];
  18.         }        
  19.     }        
  20.  
  21.     return OK;
  22. }
Can anyone help?
  #2  
Old June 4th, 2009, 12:08 PM
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 367
Provided Answers: 2

re: Converting grayscale - RGB to other colours


If I understood you, given three colors ( c1, c2, c3 ) you want to map grayscale to RGB so that for grayscale pixel with value (g) in range [0..127] resulting rgb value is between (color1) and (color2) for each component, where r1 is red component of color c1:
R = r1+ (r2-r1)*g/128 and the same for G and B components, and for g in range [128..255]: R = r2+(r3-r2)*(g-128)/128. Then you can either generate the mapping file for 256 values of grayscale or convert in on the fly.
  #3  
Old June 29th, 2009, 09:30 AM
Newbie
 
Join Date: Jun 2009
Posts: 2

re: Converting grayscale - RGB to other colours


Uh, not really. But I've solved that one already so thanks.
Reply


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colour functions - RGB -> Greyscale (sloooww~...) Robbie answers 6 July 11th, 2007 05:27 AM
determine if image is grayscale tjh answers 3 July 17th, 2005 09:35 AM