FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   Tint
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: Tint  (Read 276 times)
inadaze


Tint
« on: Oct 18th, 2004, 1:34am »

i was wondering how turn a color image into a black and white image.
I noticed the tint function but I don't understand how the values in tint(value1,value2,value3) can be used for both saturation-hue-brightness and red-green-blue?  is there an indicator that says whether you are using RGB or the other fields?
 
Thanks
Jay
 
Markavian

Markavian+iTX WWW
Re: Tint
« Reply #1 on: Oct 18th, 2004, 3:08am »

Are you trying to create a pure black and white image, or a greyscale image?
 
There are probably lots of algorithms out there for converting images, you'd probably have more fun trying to write your own.
 
I imagine using the colour c = get(x, y) would be the best way to go ahead, taking the red(c), green(c) and blue(c) values of the colour and then averging them out to give a grey value, which you then use to recreate the image.
 
If you want to do pure black and white you'd need to look into dithering functions to represent block shaded areas of the image.
 
Markavian

Markavian+iTX WWW
Greyscale
« Reply #2 on: Oct 18th, 2004, 4:03am »

I tried a few things with an imported image I drew, my code is below.
 
Or you can see it working on my website... http://mkv25.net/index.php?item_id=86
 
Code:
// Load an image and convert to grey scale
 
size(300, 300);
colorMode(RGB, 255, 255, 255);
 
BImage cImg = loadImage("house.gif");
image(cImg, 0, 0);
 
for(int ix=0; ix<100; ix++) {
  for(int iy=0; iy<100; iy++) {
    // Get colour for ix, iy pixel
    color ct = get(ix, iy);
    // Calculate averaged grey value
    int gval = int(red(ct) + green(ct) + blue(ct))/3;
     
    // Image as averaged grey of three colours / 3
    set(ix+100, iy, color(gval, gval, gval));
    // Inverted grey image
    set(ix+200, iy, color(255-gval, 255-gval, 255-gval));
    // Grey image expressed as value of red
    set(ix, iy+100, color(red(ct), red(ct), red(ct)));
    // Grey image expressed as value of green
    set(ix+100, iy+100, color(green(ct), green(ct), green(ct)));
    // Grey image expressed as value of blue
    set(ix+200, iy+100, color(blue(ct), blue(ct), blue(ct)));
    // Red values only image
    set(ix, iy+200, color(red(ct), 0, 0));
    // Green values only image
    set(ix+100, iy+200, color(0, green(ct), 0));
    // Blue values only image
    set(ix+200, iy+200, color(0, 0, blue(ct)));
  }
}
 
Pages: 1 

« Previous topic | Next topic »