# JAI and RGB Histograms

 More Topics Java-Javascript interaction. PLAF and UIDefaults Applets and Proxies

In the previous page, we looked at how an image can be read using JAI and how to get hold of a Histogram object. The Histogram class has numerous methods but we only need to make use of one of them; getBins() . It returns a two dimensional array. This array is in fact three separate Histograms, for three separate bands, which in this case happen to be RGB values.

In order to plot this data, we need to find their maximals, that's straight forward so we will not go into that, you can check it out in the code. What's not straight forward is the color mixing bit. As we all know, Red, Green and Blue when added together should produce white. So in our chart, where the three fields overlap should appear as white. Unfortunately coming up with the correct AlphaComposite for Graphics2D turns out to be a hit and miss approach. In fact I wasted quite a bit of time on it before switching over to an alternate approach which involves the use of AreaS

``````
Area red = new Area(poly[0]);
Area green = new Area(poly[1]);
Area blue = new Area(poly[2]);

red.intersect(green);
green.intersect(blue);
blue.intersect(new Area(poly[0]));

g2D.setColor(new Color(255,255,0));
g2D.fill(red);

g2D.setColor(new Color(0,255,255));
g2D.fill(green);

g2D.setColor(new Color(255,0,255));
g2D.fill(blue);

g2D.setColor(Color.white);
blue.intersect(new Area(poly[2]));
g2D.fill(blue);

```
```

Area has a method that can be used to make new area based on the interection of two areas. When three areas intersect, we fill that area in white, and when two areas intersect we fill that area with the corresponding color combinations. Now we will see how these areas are actually defined

``````
for(int j=0 ; j
```
```

That ladies and gentlemen, is all there is to it. Of course we do need to add place this inside a paintComponent() method is a JComponent and add that to a JFrame or an applet and so on. All that is routine stuff so we will not go into that. You can check it out when you download the code.