473,657 Members | 2,896 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Converting grayscale - RGB to other colours

2 New Member
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 10428
newb16
687 Contributor
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
Sodrohu
2 New Member
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
3849
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 pixel. I need a way to save this this byte array as a gif. Does anyone have any suggestions???
7
1809
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 entered by the user. I know the web script must convert the values into integers, store them as variables and then output them, but I cannot seem to establish the calculation for this. I'm attaching the html I've got, that works when the page is...
6
3311
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 (core dumped)" error. I am at a loss as to why this works only part of the time. I hope it's proper etiquette to post the code below (3 files). Can someone please show me what's wrong with the following code? I
8
11403
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
3263
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 there an industry standard for the GrayScale ColorMatrix values? Thanks, Henry Solution #1, Jacob Grass:
2
2522
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 < Width; x++) {
8
47909
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 that image in grayscale format.How do i do that.It still saves in true color format. -i used picturebox1.image.save() method -i tried to convert an 8-bit image into grayscale but was unable to do it.
1
2347
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 button) the button can be converted to grayScale??? Any help would be much appreciated. Ian
3
6775
by: srsaravanan | last post by:
i need coding for converting block and white image into RGB image
0
8384
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8302
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5630
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2726
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1601
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.