# how to binarize an image?

I don't want to binarize a certain image through another program, I want to know how to binarize things myself. All I know is that there is something to do with a threshold and if it is above the threshold it is either 1 or 0 and the opposite if below. My images are using RGB but I can also use HSB or HSV. I just want the algorithm to do so . :)

• What research have you done? We expect you to do a significant amount of research before asking, and to show us in the question what research you've done. This topic is described on Wikipedia, and a simple search on 'image binarization' turns up some references in the first result (even searching for just 'binarization' turns up some stuff among the first 10 hits). As a rough rule of thumb, if your question can be answered using information readily findable on Wikipedia or in standard textbooks, you probably haven't done enough research before asking. – D.W. Nov 14 '15 at 6:08

## 1 Answer

There is Otsu method to use variance when splitting.

Taking your own steps you should convert RGB to grayscale (simple mean like $(R+G+B)/3$, or use luminance grayscale).

The next step is to give some threshold, from Otsu or arbitrary given by your choice, and operating on grayscale image everything below (or equal) is 0, so it will be black, and greater than threshold is 1 (white).

Operations on other scheme like HSL is exactly taking luminance, but the full change RGB -> HSL is not needed because you discard color info.

Situation when values are out of range does not occur, so do not worry.

• How do i turn the image into a histogram – MrQandA Nov 13 '15 at 21:02
• If you have 256 gray levels, you start from declaring that big array initialized with 0, and then for each pixel you increment proper bin (grayscale value, rounded). – Evil Nov 13 '15 at 21:13
• Is it the number of accurances for each number between 0 and 256? – MrQandA Nov 13 '15 at 21:29
• Yes, with minor change - 0 to 255 inclusively for 8bit colors. – Evil Nov 13 '15 at 22:01
• I looked at the website you said to use for the otsu method and converted it to python but it dosn't seem to be giving me the right thresholds. Would it be ok to add that to my question or should I ask it on stack overflow? – MrQandA Nov 13 '15 at 22:04