Connecting Tech Pros Worldwide Help | Site Map

Converting grayscale - RGB to other colours

Newbie
 
Join Date: Jun 2009
Posts: 2
#1: Jun 4 '09
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?
Needs Regular Fix
 
Join Date: Jul 2008
Posts: 380
#2: Jun 4 '09

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.
Newbie
 
Join Date: Jun 2009
Posts: 2
#3: Jun 29 '09

re: Converting grayscale - RGB to other colours


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