We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you a podcast all about Citrix Workspace, moving to the cloud, and analytics & intelligence. Episode 2 coming soon!Listen Now

x

# Colour image to a red, a green and a blue image

on
Medium Priority
322 Views
Im writing a report about a colour clustering algorithm and one of the steps in the algorithm is to create a red image, a green image and a blue image from a colour image.  So in total i'll end up with 3 images that get created from this single colour image.

The part i'm not too sure about is the creating of the red, the green or the blue images?

What are the stages involved (in details please) ?

Like I know the stages involved for converting a colour image into a greyscale image, but not a colour image into a red image, and a green image and a blue image.  Remember i'll end up with 3 separate images - red green and blue.

I do know that it involves examining each pixel of the colour image in turn and processing it into red pixel if you want to create a red image, or a green pixel if you want to create a green image and so on...

I know its a Sunday and more than likely, most peoples day off, but if I could get some help on this today, it would great!!

If you think i wasnt clear on what im trying to do, please ask and i'll try explain more...

Ellandrd
Comment
Watch Question

## View Solution Only

Commented:
If I understand you correctly, you want to have 2 color channels discarded in each of the 3 resulting images and ony one preserved in some way. The question is what to do with the discarded color channels because a color consists always of all three channels, even if it is a greyscale image (where all 3 channels have the same value).

I made an example here: http://xs74.xs.to/pics/06130/channels.png
The first row contains the original image and a greyscale version of it.
The next rows show operations on one channel "X" only, which is the red channel in 1st column, green in the 2nd and blue in the 3rd.
The 2nd row has the X channel preseved as it is in the original image and the other two set to 0 (black).
The 3rd row has the X channel preseved as it is in the original image and the other two set to 255 (white).
The 4th row has the X channel copied into the other 2 channels and the X channel itself set to a fixed value of 255.

Is there a row similar to what you want to achieve?
Do you have a more information about how the 3 images will be used later that might give some hints about how they need to be generated?
What tools do you plan to use to create the 3 images (a certain programming language or a certain program like Photoshop)?

Commented:
>>Is there a row similar to what you want to achieve?

Yes this:

>>The 2nd row has the X channel preseved as it is in the original image and the other two set to 0 (black).

Bascially im needing to know the steps or process involved in:

original colour image -> red image
original colour image -> green image
original colour image -> blue image

>>Do you have a more information about how the 3 images will be used later that might give some hints about how they need to be generated?

Im doing some research on image analysis techniques used for OCR.

Ive developed a simple application using Java to evaluate the techniques I found.  One technique I found uses the images colour information at the pre-processing stage (Binarizarion).

The algorithm converts an colour image into a red image, a green image and a blue image and then uses these R,G & B images to futher process the image.  The part im stuck with and have not any knowledge in is the converting of the original colour image into a separate red image, a separate green image and a separate blue image, hence why im asking, can somebody explain the process and/or steps (in detail) to me for this convertion.

Ellandrd

Commented:
Here is some code in Java that creates the 3 images you want. It's basically masking out the 2 other colors from the original image for each of the 3 images. I.e. for the red image all information for green and blue is set to 0 while the red channel remains untouched.

import java.io.*;
import java.awt.image.*;
import java.awt.*;

public class Img
{
public static final Toolkit toolkit = Toolkit.getDefaultToolkit();

public static void main( String[] args )
{
try {
Image img = readImage( args[ 0 ] );
int width = img.getWidth( null ), height = img.getHeight( null );
int[] pix = grabPixels( img ); // gets the pixels in the default (A)RGB format
int[] res = new int[ pix.length ];
Image[] seperated = new Image[ 3 ]; // resulting images: 0=red, 1=green, 2=blue
for( int chan = 0; chan < 3; chan++ )
{
final int shift = 16 - 8 * chan;
final int mask = 0x000000ff << shift; // 0x00ff0000 is red, 0x0000ff00 green and 0x000000ff blue
for( int idx = 0; idx < pix.length; idx++ ) // iterates all pixels in (A)RGB format
res[ idx ] = pix[ idx ] & mask; // keeps only one channel and sets the other 2 channels to zero
seperated[ chan ] = createImage( width, height, res );
/* FileOutputStream fout = new FileOutputStream( args[ 0 ] + "_" + chan + ".png" );
PngEncoder.encode( fout, seperated[ chan ], false );
fout.close(); */
}
} catch( Exception ex ) {
ex.printStackTrace();
}
}

public static int[] grabPixels( Image img )
{
int width = img.getWidth( null ), height = img.getHeight( null );
PixelGrabber grabber = new PixelGrabber( img, 0, 0, width, height, true );
try { grabber.grabPixels(); } catch( InterruptedException ie ) { ie.printStackTrace(); }
return (int[]) grabber.getPixels();
}

public static Image createImage( int width, int height, int[] pix )
{
}

public static Image readImage( String filename )
{
Image img = toolkit.getImage( filename );
boolean success = false;
try {
while( ( toolkit.checkImage( img, -1, -1, null ) & ( ImageObserver.ERROR | ImageObserver.ABORT ) ) == 0 )
{
if( success = toolkit.prepareImage( img, -1, -1, null ) )
break;
synchronized( img ) { img.wait( 50 ); }
}
} catch( InterruptedException iex ) {}
return success ? img : null;
}
}

In case you are not that familar with Java and bit manipulation operations I can also expain that part in more detail if you want.

Not the solution you were looking for? Getting a personalized solution is easy.

Commented:
>>It's basically masking out the 2 other colors from the original image for each of the 3 images. I.e. for the red image all information for green and blue is set to 0 while the red channel remains untouched.

Could you expand on this or is it possible to say more?

It just from your 2 lines above, i wouldnt be able to write a big paragraph from it...

Commented:
>>In case you are not that familar with Java and bit manipulation operations I can also expain that part in more detail if you want.

Yes please, other than that is great!

Commented:
anybody?
##### Thanks for using Experts Exchange.

• View three pieces of content (articles, solutions, posts, and videos)
• Ask the experts questions (counted toward content limit)
• Customize your dashboard and profile