how to convert a bitmap image in binary image?
+1
A:
The simplest and easiest way to convert a grey scale image to a binary image is to just apply a threshold, i.e.
out[y][x] = in[y][x] > threshold ? 1 : 0;
The threshold
value can be fixed, e.g. 128, variable, supplied by the user, or determined automatically by histogramming the image first.
There are more sophisticated methods which will generate subjectively "better" binary images, but without knowing more about your requirements it's hard to know whether you need something more advanced or whether simple thresholding will be good enough.
Paul R
2010-06-26 08:55:53
i have tried but it just print a black square :( this is my code plz check this. COLORREF rgb = dc.GetPixel(x, y); BYTE r = GetRValue(rgb); BYTE g = GetGValue(rgb); BYTE b = GetBValue(rgb); BYTE bw = (BYTE)(0.3 * r + 0.59 * g + 0.11 * b + 0.5); BYTE bin = RGB(bw,bw,bw) > 128 ? 1: 0; dc.SetPixel(x,y,RGB(bin,bin,bin));
Sweety Khan
2010-06-26 10:17:32
@Sweety Khan: maybe your threshold is too high for this image - try a lower value. Also note that if your image is still 8 bits with values of 1 and 0 then it won't be visible - you'll need to use 0 and 255 for an 8 bit image.
Paul R
2010-06-26 15:52:22
the color image i m using is 24 bit bitmap.
Sweety Khan
2010-06-26 17:14:40
so it is possible or not? i have tried smaller values but still it displays a black square
Sweety Khan
2010-06-26 17:28:11
i have changed these lines. BYTE bin = bw > 175 ? 255: 0;dc.SetPixel(x,y,RGB(bin,bin,bin)); not so good but its done! thank u sooo much Paul :)
Sweety Khan
2010-06-26 17:48:22