Friday, 27 September 2013

CONVERSION OF COLOR MODELS in C Aglorithm | Computer Graphics Lab Manual | IT department | Final Year




AIM:

To implement conversion of color models.

ALGORITHM:

1. Start the program.

2. Get RGB value from user and find min and max.

3. Assign u for max and Δ=max-min.

4. Determine h by calculating relative position of point within hexagon.

5. If s=0

Then h=h0-hx

Else

If v==max

Then h=(g-b)/ Δ

Else

G=max

Then h=2+(b-r)/ Δ

Else

If b=max

Then h=4+(r-g)/ Δ

6. Calculate h=h*60 and h=h/60

7. Stop the program.




SOURCE CODE:


import java.awt.*;

import javax.swing.*;

public class yiq

{

public static void main(String args[])

{

JFrame frame=new JFrame("RGB");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

RGBpanel panel=new RGBpanel();

frame.getContentPane().add(panel);

frame.pack();

frame.setVisible(true);

int a,b,c;

a=panel.red;

b=panel.green;

c=panel.blue;

JFrame frame1=new JFrame("YIQ");

frame1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

RGBpanel panel1=new RGBpanel(a,b,c);

frame1.getContentPane().add(panel1);

frame1.pack();

frame1.setVisible(true);

}

}



class RGBpanel extends JPanel

{

int red,green,blue;

public RGBpanel()

{

setPreferredSize(new Dimension(300,300));

red=Integer.parseInt(JOptionPane.showInputDialog("Enter r"));

green=Integer.parseInt(JOptionPane.showInputDialog("Enter g"));

blue=Integer.parseInt(JOptionPane.showInputDialog("Enter b"));

Color colr=new Color(red,green,blue);

setBackground(colr);

}

public RGBpanel(int red,int green,int blue)

{

setPreferredSize(new Dimension(200,200));

red=red/255;

green=green/255;

blue=blue/255;

int y=76*red+150*green+37*blue;

int i=152*red-70*green-82*blue;

int q=54*red-135*green+79*blue;

Color colr=new Color(y,i,q);

setBackground(colr);

}

}


No comments:

Don't You Think this Awesome Post should be shared ??
| CONVERSION OF COLOR MODELS in C Aglorithm | Computer Graphics Lab Manual | IT department | Final Year |
Back To Top Related Posts Plugin for WordPress, Blogger...