473,383 Members | 1,925 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,383 software developers and data experts.

Convert image from RGB to LMS

I need to convert an image from RGB format to LMS format using matrix's and an array of double to hold the LMS values as they're created. I need to take each pixel (R, G, and B) and and multiply it by the combined matrix shown below. Any ideas? I also know that I need to convert the byte value: (val + 256) % 256.

{0.3811,0.5783,0.0402}
{0.1967,0.7244,0.0782}
{0.0241,0.1288,0.8444}

Thanks for your help!
Dec 5 '06 #1
1 6032
Here's more info to help with understanding what I'm doing. It's the same thing from above with with some added stuff to it. Thanks again for your help!


I need to convert an image from RGB format to LMS format using matrix's and an array of double to hold the LMS values as they're created. I need to take each pixel (R, G, and B) and and multiply it by the combined matrix shown below. Any ideas? I also know that I need to convert the byte value: (val + 256) % 256.

{0.3811,0.5783,0.0402}
{0.1967,0.7244,0.0782}
{0.0241,0.1288,0.8444}

Then, after I convert it to RGB, I need to go back to LMS. I need to create an array of byte to hold the RGB values as they are created. Take each pixel (L, M, and S) and multiply it by combined matrix as shown below. I have to remember to clamp the value between 0 and 255 before assigning into RGB which is a byte array.

{4.4679, -3.5873, 0.1193}
{-1.2186, 2.3809, -0.1624)
{0.0497, -0.2439, 1.2045)

Here's some of my code that I've already written:

Expand|Select|Wrap|Line Numbers
  1. public static void main(String args[]) throws IOException
  2.         {
  3.         DataInputStream rd = new DataInputStream(System.in);   
  4.         char c1=(char)rd.readUnsignedByte();
  5.         char c2=(char)rd.readUnsignedByte();
  6.         int width=getNumber(rd);
  7.         int height=getNumber(rd);
  8.         int colorValue=getNumber(rd);
  9.         System.out.println("P6" + " " + width + " "+ height + " 255");
  10.         byte image[] = new byte[width*height*3];
  11.         double lms[] = new double[width*height*3];
  12.         rd.read(image);
  13.  
  14.         double A[][] = {{0.3811,0.5783,0.0402},{0.1967,0.7244,0.0782},{0.0241,0.1288,0.8444}};
  15.         double D[][]=new double[3][1];
  16.         double V[][]=new double[3][1];
  17.  
  18.         for(int i=0; i < image.length; i = i+3) 
  19.             {
  20.             D[0][0] = image[i];
  21.             D[1][0] = image[i+1];
  22.             D[2][0] = image[i+2];
  23.             V = mult(A, D);
  24.             lms[i] = V[0][0];
  25.             lms[i+1] = V[1][0];
  26.             lms[i+2] = V[2][0];
  27.             }
  28.  
  29.         System.out.print(V);
  30.     }
  31.  public static double [][] mult(double A[][], double D[][])
  32.         {
  33.         double V[][] = new double[A.length][D[0].length];
  34.         for(int i = 0; i<A.length; i++)
  35.             {
  36.             for(int j = 0; j<D[0].length; j++)
  37.                 {
  38.                 for(int k=0; k<A[0].length; k++)
  39.                     {
  40.                     V[i][j] = V[i][j] + A[i][k]*D[k][j];
  41.                     }
  42.                 }
  43.             }
  44.         return V;
  45.         }
  46.  
  47. }
  48.  
Thanks for your help!
Dec 5 '06 #2

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

Similar topics

1
by: Fritz Switzer | last post by:
With two controls a PictureBox and another "PictureBox like" , Pic2, a control from a dll, I'm stuck on cannot implicity convert System.Drawing.Image to System.Drawing.Bitmap error. How do I...
1
by: mevar81 | last post by:
Hello to everybody.I have a problem.I used a TypeDescriptor to retrieve a TypeConverter to convert an Image to a string.The problem is that it converts the image to the string...
1
by: Daniel | last post by:
I have looked everywhere on the web for an answer to this and the only thing I can find is converting the image format when the file is present on the local filesystem. What I want to do is use a...
7
by: Scott Schluer | last post by:
Is there a way to use the Image class to convert a color photo (GIF or JPEG) to a B&W photo? Thanks, Scott
5
by: Trammel | last post by:
Hi, I have a vb.net program made to grab screenshots and then store them in image objects. The image is displayed in a pictureBox atm but I want to store the data in a String only. (Without...
5
by: Socrates | last post by:
I am interested in developing an online utility that will enable users to copy and past any image (or upload any image on the internet) to the online utility, which will then convert the image to...
6
by: PenguinPig | last post by:
Dear All Experts I would like to know how to convert a HTML into Image using C#. Or allow me contains HTML code (parsed) in Image? I also tried this way but it just display the character "<" &...
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...
5
by: stef | last post by:
hello I can find all kind of procedures to convert an array to a bitmap (wxPython, PIL), but I can't find the reverse, either - convert a bitmap to an array or - read a bitmap file to an...
0
Debadatta Mishra
by: Debadatta Mishra | last post by:
Introduction In this article I will provide you an approach to manipulate an image file. This article gives you an insight into some tricks in java so that you can conceal sensitive information...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.