-
June 2nd, 2005, 08:46 AM
#1
display a bitmap image file in black and white
Hi,
I want to open a bitmap image file and display it in black and white. can anyone help me in this?
-
June 2nd, 2005, 09:00 AM
#2
Re: display a bitmap image file in black and white
Do you mean black and white (2 colors) or greyscale?
-
June 2nd, 2005, 12:20 PM
#3
Re: display a bitmap image file in black and white
Black and white, only 2 colors
-
June 2nd, 2005, 01:08 PM
#4
Re: display a bitmap image file in black and white
To display your bmp image file into black and white you will have to write a function to threshold the image. you can set the threshold value of the colours according your own choice.
To do this you will have to first load the image and then with the help of GetColour or getpixel functions compare the values with your threshold value and then if the value is less than your threshold then set it to black, using the setpixel (i think there is also setColour) functions. for black the value would be 0 and for white the value would be 255. and also keep in mind if you are using pixel values than you will have to set it for all the three basic colours RGB.
Hope this is what you want.
Farooq.
-
June 2nd, 2005, 02:19 PM
#5
Re: display a bitmap image file in black and white
Converting color to B&W is a little more complex than farooqmaniar indicates. You'll first have to convert the color to greyscale by using some formula: one example is Greyscale = 0.299Red + 0.587Blue + 0.114Green, although there are others.
Once you have a greyscale value, you can use thresholding to determine which pixels you force to white (because their greyscale value is greater than the threshold) and which you force to black.
Then, once you've done all that, you'll discover - as I have - that the threshold value is quite critical in how your final image appears. You may find - as I did - that you have to vary the threshold value for each image. I never did find an algorithm for that, so if you come up with one, please publish it here.
Good luck!
Regards
Robert Thompson
-
June 2nd, 2005, 03:06 PM
#6
Re: display a bitmap image file in black and white
Well TSYS,
Its not difficult, and its not even necessary to convert the image to a greyscale image, you can directly convert it into a black and white image, the only thing at this time you need to take care is that you have to provide threshold for all the three colours. (RGB) or may be you need to provide value for HUE, SATURATION and Intensity. (HSI)
Well and for your question , the solution is, to do dynamic thresholding. To use dynamic thresholding there are various methods and one of them that i remember right now is iterative method. In this method you first find out the peak of the pixels (mean the maximum number of pixels for a particular grey scale value) once you have found this out, your next target is to find the second peak. Once you have found out these two peaks, you have to find the minium point(minimum number of pixels for a particular grey scale value) between these two peaks. and this point will act as a threshold value.
Dynamic thresholding is a bit complex but it works perfect. There are other methods other than iterative method. if you search on net properly you will be able to find the algorithms.
Farooq.
-
June 2nd, 2005, 04:45 PM
#7
Re: display a bitmap image file in black and white
Yes, there are several interesting papers on dynamic thresholding on the net which I didn't know about. Thanks for pointing out the search term to use.
I'm not convinced you can go directly from RGB (or HSI) to B&W. Can you point to any examples?
Regards
Robert Thompson
-
June 3rd, 2005, 10:35 AM
#8
Re: display a bitmap image file in black and white
Search using the term "colour thresholding" and you will find a lot of articles.
Farooq
-
June 3rd, 2005, 12:04 PM
#9
Re: display a bitmap image file in black and white
Just a thought.
Can't we just create a monchrome Device Context. Blit the original bitmap into this monochrome DC and blit the monochrome DC into the Windows DC.
What do you think?
If there is no love sun won't shine
-
June 3rd, 2005, 01:46 PM
#10
Re: display a bitmap image file in black and white
Originally Posted by miteshpandey
Just a thought.
Can't we just create a monchrome Device Context. Blit the original bitmap into this monochrome DC and blit the monochrome DC into the Windows DC.
What do you think?
That;s the exact question that popped up in my head too.. Does MS' GDI does all that thresholding internally ??
-
June 7th, 2005, 12:39 AM
#11
Re: display a bitmap image file in black and white
"Can't we just create a monchrome Device Context. Blit the original bitmap
into this monochrome DC and blit the monochrome DC into the Windows DC."
Can someone give the sample code, i have tried but not able to do it? Should be just three lines....
Besides i am using a DIB, but i guess i can convert it to a bitmap....Any ideas???
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|