Decolorizer

This is a way of creating a largely gray-scale image with some color. This program replaces pixels in the input image that are non-bright with gray equivalents, and leaves brightly colored pixels alone.

There are a lot of ways to define a "bright" color. In this example, the gray equivalent is the color of equal red, green, and blue components given by the mean of the original red, green and blue components. A bright color is here defined as one for with any of the red, green, and blue components are greater than some factor times the equivalent gray value.

The right image is the result of processing the left image with the code below.


rem
rem This is an example of image manipulation software written in Basic
rem using the freeware Macintosh METAL basic interpreter.
rem 
rem This program de-colorizes an image, making pixels their equivalent
rem grey unless they are "brightly" colored.  The grey equivalent is
rem simplistically taken to be just the mean of the R, G, and B values 
rem of the pixel.  A pixel is "brightly" colored if at least one of the
rem R, G and B values is some percentage (determined by the fact variable)
rem greater than that grey value.  There are a lot of ways to define a
rem bright color, but this is simple and effective here.
rem
rem Metal seems to have a problem with very large images, so try this on
rem relatively small ones, say 600 x 500 or smaller.
rem
rem Matthew M. Conroy, 2001.  
rem Do whatever you want to with this code, especially improve it.
rem

file$ = open preview dialog$
get quicktime pict size file$,picW,picH

resize console 20,50,picW+20,picH+50
 load quicktime pict file$

fact=2.0 
rem determines how bright a pixel must be to not go grey 
rem note: fact must be greater than 1.0 to have any affect
rem the range 1.1-2.0 seems about the limits of usefulness
rem larger values result in more grey pixels

for x=0 to picW
for y=0 to picH

get pixel x,y,red,green,blue
grey = (red+green+blue)/3

if ((red>grey*fact) or (green>grey*fact) or (blue>grey*fact)) then
   forecolor red,green,blue
else
   forecolor grey,grey,grey
endif

plot x,y

next y
next x


back