0
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ What is the purpose? what do you expect to find when changing to binary image? $\endgroup$ – Shahaf Finder Feb 4 at 16:49
  • $\begingroup$ Experimentation. $\endgroup$ – Aashish Loknath Panigrahi Feb 4 at 17:03
  • $\begingroup$ I mean, what is the "correct" output? $\endgroup$ – Shahaf Finder Feb 4 at 17:16
  • 1
    $\begingroup$ 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. $\endgroup$ – greybeard Feb 4 at 19:03
1
$\begingroup$

You are looking for a thresholding algorithm. There is no correct or incorrect algorithm. Some methods tend to work better than others on specific types of images; which method is best may depend on what kind of images you usually work with. I suggest studying standard thresholding methods and picking one.

| cite | improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.