# Greyscale image to binary image conversion using operations on pixel

Previously, I tried convert a color image into a greyscale image by using pixel values of an image from a simple formula :-

Grey = 0.3*Red + 0.58*Green + 0.11*Blue


After that, I wanted to convert the greyscale image into a binary image & I used two different techniques :

NOTE : Red, Green & Blue are variables storing Greyscale intensity of the Pixel.

1. Algorithm 1:

if Red <= 127:
Red = 0
Green = 0
Blue = 0
else:
Red = 1
Green = 1
Blue = 1


2. Algorithm 2:

if Red <= AvgIntensity:
Red = 0
Green = 0
Blue = 0
else:
Red = 1
Green = 1
Blue = 1


where, AvgIntensity represents the average intensity of all the pixels of the image.

(Obviously,) the algorithms turned out to be wrong, producing incorrect output. So, I wanted to know about the correct way for greyscale to binary image conversion.

• What is the purpose? what do you expect to find when changing to binary image? – Shahaf Finder Feb 4 at 16:49
• Experimentation. – Aashish Loknath Panigrahi Feb 4 at 17:03
• I mean, what is the "correct" output? – Shahaf Finder Feb 4 at 17:16
• You may want to look for error diffusion. Other than that, the answer may be as simple as Red = Green = Blue = 255 (seeing that you compare to 127). Better yet, don't use magical literals. – greybeard Feb 4 at 19:03