473,394 Members | 1,865 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Converting grayscale - RGB to other colours

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?
Jun 4 '09 #1
2 10399
newb16
687 512MB
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.
Jun 4 '09 #2
Uh, not really. But I've solved that one already so thanks.
Jun 29 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Chad | last post by:
I have a one dimensional byte array that stores the pixel information of my image. The image is 8-bit grayscale so each byte in the array holds a value from 0(black) to 255(white) for a single...
7
by: Krista Bailie | last post by:
I'm sure this is so easy that it will hurt for anyone to read it, but I really need some direction. I'm trying to create a color chart (RGB) that shows steps between two different colors as...
6
by: QuasiChameleon | last post by:
Hi, I'm trying to create a grayscale image class that reads and writes grayscale Targa format. This works well with smaller images, but corrupts larger images and creates a "Segmentation fault...
8
by: RicercatoreSbadato | last post by:
I'm using bmp.Save() and the bmp is in PixelFormat.Format8bppIndexed. But when I open the image with Gimp, it tells me that the image is RGB and not grayscale.
2
by: Henry Wu | last post by:
Hi I was at the search for making e.Graphics.DrawImage turn any image to Grayscale, and I found two similar solutions but different ColorMatrix values, what is the difference between the two? Is...
2
by: Sirin Azazi | last post by:
i am trying to convert an image into grayscale format. but i have a problem saving the bmp file after the process.here the code; for (int y = 0; y < Height; y++) { for (int x = 0; x <...
8
by: platinumhimani | last post by:
-How to convert any image(8,16,24,32 or 64-bit) to 8-bit grayscale -i have tried to convert a 24-bit image to grayscale using setpixel and getpixel functions, in vb.net but i am unable to save...
1
by: IanH1982 | last post by:
Hi, I am building a quiz in Flash, the quiz will display a question and a set of three possible answers. Im just wondering if its possible once an incorrect answer has been selected (which is a...
3
by: srsaravanan | last post by:
i need coding for converting block and white image into RGB image
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.