maybe it would even be a good idea to make a program where you can see the original picture, the converted picture next to it (both kind of bigger "thumbnails"), and have a slider to play around with the threshold, to see instand results, and a button to make the conversion permanent, if you have found a good threshold value (like the "proof" functionality of paintshop pro image filters)
if you want to batch-convert dozens of completely independant images, this might be no option. if you want to batch-convert dozens of images from the same scan of say 30 pages of a text book, it could work to have the user adjust a threshold for the first picture and then use it also for the others. (with same scan I mean you scanned the 30 pages with the same scanner, same settings, same properties (brightness) of all the paper pages and the print on it etc)
well, i dont know of an existing library / if .NET can do this. if there is one, I hope sombody will tell.
but if you don't have too high demands on the quality, you could pretty easily do it yourself, I think.
you first have to read up on how to obtain a buffer with the raw pixel data of an image you loaded with .NET. (don't remember myself, haven't done that in .NET too often) once you have that, you can go on using the data.
set a threshold somewhere near the middle of your gray shades, say t=128. check all color index values in your gray scale image (which reach from 0 to 255) against the threshold. I assume that an index of 0 equals the darkest, and an index of 255 the brighest shade.
foreach pixel in grayscale image if (pixel < t) set corresponding pixel in black/white image to 0 ("black") else set corresponding pixel in black/white image to 1 ("white")
experiment with the theshold value. it may make sense to analyze the original picture before conversion, and find out the smallest and greatest used indices, let's name them si,gi. then set your threshold to be t = si + (gi-si)/2 to have the middle. but maybe the middle is not even that good of a value, and short before highest is better, just experiment! I'm not familiar with common practises for that task - I just told you what I came up with thinking for a minute, maybe it's not the best idea possible ;-)
in a 1-bpp image, there are 8 pixels stored in one byte. so you have to use boolean operators to stuff those 0/1 values for 8 pixels in one byte each. you have to allocate numberofpixels/8 bytes for your image, in case the number of pixels aren't a multiple of 8, you have to allocate one byte more than the integer result of numberofpixels/8.
well, that way you get the raw data. to store this thing in a bitmap is another thing. you'd have to read up on the windows bitmap format, or maybe .NET provides a feature to plug raw data into a windows bitmap. If I remember correctly, a windows bitmap stores rows after rows (in memory), where a row of a picture has *always* a number of bytes being divisible by 4. if the number of pixels/row is not a multiple of 4, the extra bytes are ignored by image displaying software, but they are there. just to prevent confusion in case you find not so good tutorials about the *.bmp format ;)
binarization
Chris Adams - IIS
terceslil
maybe it would even be a good idea to make a program where you can see the original picture, the converted picture next to it (both kind of bigger "thumbnails"), and have a slider to play around with the threshold, to see instand results, and a button to make the conversion permanent, if you have found a good threshold value (like the "proof" functionality of paintshop pro image filters)
if you want to batch-convert dozens of completely independant images, this might be no option.
if you want to batch-convert dozens of images from the same scan of say 30 pages of a text book, it could work to have the user adjust a threshold for the first picture and then use it also for the others.
(with same scan I mean you scanned the 30 pages with the same scanner, same settings, same properties (brightness) of all the paper pages and the print on it etc)
Reuben
Shalini
wullien
but if you don't have too high demands on the quality,
you could pretty easily do it yourself, I think.
you first have to read up on how to obtain a buffer with the raw pixel data of an image you loaded with .NET. (don't remember myself, haven't done that in .NET too often)
once you have that, you can go on using the data.
set a threshold somewhere near the middle of your gray shades, say t=128.
check all color index values in your gray scale image (which reach from 0 to 255) against the threshold. I assume that an index of 0 equals the darkest, and an index of 255 the brighest shade.
foreach pixel in grayscale image
if (pixel < t) set corresponding pixel in black/white image to 0 ("black")
else set corresponding pixel in black/white image to 1 ("white")
experiment with the theshold value.
it may make sense to analyze the original picture before conversion,
and find out the smallest and greatest used indices, let's name them si,gi.
then set your threshold to be t = si + (gi-si)/2
to have the middle.
but maybe the middle is not even that good of a value, and short before highest is better, just experiment!
I'm not familiar with common practises for that task - I just told you what I came up with thinking for a minute, maybe it's not the best idea possible ;-)
in a 1-bpp image, there are 8 pixels stored in one byte.
so you have to use boolean operators to stuff those 0/1 values for 8 pixels in one byte each.
you have to allocate numberofpixels/8 bytes for your image, in case the number of pixels aren't a multiple of 8, you have to allocate one byte more than the integer result of numberofpixels/8.
well, that way you get the raw data.
to store this thing in a bitmap is another thing. you'd have to read up on the windows bitmap format,
or maybe .NET provides a feature to plug raw data into a windows bitmap.
If I remember correctly, a windows bitmap stores rows after rows (in memory), where a row of a picture has *always* a number of bytes being divisible by 4. if the number of pixels/row is not a multiple of 4, the extra bytes are ignored by image displaying software, but they are there. just to prevent confusion in case you find not so good tutorials about the *.bmp format ;)
hope that was more helping than confusing.
Steve