BMP-Threshold-8bit-->2 bit-problem-image writing

R

Raj

Hello Members,
I wrote a program to convert a greyscale bitmap image in to monochrome
bitmap image, a simple thresholding.

Input:Greyscale image[1 pixel = 8 bit ie 1 byte = 1 pixel];
Expected Output:Monochrome image[1 pixel = 1 bit]

Pseudocode:
row:0->height
column:0->width
if (current pixel value>Threshold value)
current pixel value = 0;
else
current pixel value = 255;

I am writing back the thresholded values in to the same input buffer.

The problem what i am facing is that i am getting a thresholded image
but in the grey scale image format.

So here i need to write 1 byte as 1 bit. I am stuck here. How can i do
this being my data remains the same but instead of 1 byte, it has to be
1 bit.

Kindly guide me

thanks
Raj
 
A

Alipha

Raj said:
Hello Members,
I wrote a program to convert a greyscale bitmap image in to monochrome
bitmap image, a simple thresholding.

Input:Greyscale image[1 pixel = 8 bit ie 1 byte = 1 pixel];
Expected Output:Monochrome image[1 pixel = 1 bit]

Pseudocode:
row:0->height
column:0->width
if (current pixel value>Threshold value)
current pixel value = 0;
else
current pixel value = 255;

I am writing back the thresholded values in to the same input buffer.

The problem what i am facing is that i am getting a thresholded image
but in the grey scale image format.

So here i need to write 1 byte as 1 bit. I am stuck here. How can i do
this being my data remains the same but instead of 1 byte, it has to be
1 bit.

Kindly guide me

thanks
Raj

each of the 8 bits in the byte would represent a different pixel (that
is, 8 pixels are packed into 1 byte). you use shifting and bitwise
operators manipulate the individual bits. google becoming bitwise
 
M

Martin Leese

Raj said:
> Subject: Re: BMP-Threshold-8bit-->2 bit-problem-image writing
Hello Members,
I wrote a program to convert a greyscale bitmap image in to monochrome
bitmap image, a simple thresholding.

Input:Greyscale image[1 pixel = 8 bit ie 1 byte = 1 pixel];
Expected Output:Monochrome image[1 pixel = 1 bit]

Pseudocode:
row:0->height
column:0->width
if (current pixel value>Threshold value)
current pixel value = 0;
else
current pixel value = 255;

I am writing back the thresholded values in to the same input buffer.

The problem what i am facing is that i am getting a thresholded image
but in the grey scale image format.

So here i need to write 1 byte as 1 bit. I am stuck here. How can i do
this being my data remains the same but instead of 1 byte, it has to be
1 bit.

Kindly guide me

I have never used the BMP format, but a quick Google
brought up:
http://astronomy.swin.edu.au/~pbourke/dataformats/bmp/

This suggests that the number of bits per pixel is
set in the image header. So, the switch to 1-bit
values happens when you write the output image. You
seem to have assumed that the code will automatically
know you now have binary data. This was an
unreasonable assumption.

It would probably help if you used output values of
0/1 instead of 0/255. Also, depending on the
capabilities of the software you are using to write
the BMP image, you may or may not have to pack the
1-bit values into bytes yourself.
 
R

Raj

Hello Martin,

I am writing in C using visual c++ environment. I have tried the trick
what you have advised. But it just switches the value of 8 to 1 in the
Bits per pixel[BPP] in the information header. But there occurs no
change to the data size.

I converted my output image[a thresholded but in greyscale format] to
monochrome using paint. Subjectively, i find the pixels remain the
same. Its just the memory what i am using vary leading to my original
post.

Any suggestion.

thanks
Raj
 
M

Martin Leese

Raj said:
Hello Martin,

I am writing in C using visual c++ environment. I have tried the trick
what you have advised.

Which one? I advised that the switch to 1-bit
values happens when you write the output image.
How did you write your output image?

I advised using output values of 0/1 instead of
0/255. Did you do this?

I advised that, depending on the capabilities
of the software you are using to write the BMP
image, you may or may not have to pack the
1-bit values into bytes yourself. What software
are you using to write your output image? Did
you check whether you need to pack the 1-bit
values into bytes yourself?
 
B

Bob Alvarez

Writing and reading different image formats is quite tricky and there
are a lot of freeware libraries out there that do the job. Visual C++
may already have objects that have this capability. I program in
Borland and their builtin TImage component can read and write bmp's (as
well as jpg's and other formats).

I suggest you google on your request. A possibility is imagemagick,
although I have not used it.

Bob
 
G

Gerry Quinn

The problem what i am facing is that i am getting a thresholded image
but in the grey scale image format.

Well, obviously!
So here i need to write 1 byte as 1 bit. I am stuck here. How can i do
this being my data remains the same but instead of 1 byte, it has to be
1 bit.

Create a separate monochrome bitmap and either write to that, or use
BitBlt to copy to it from the greyscale version.

- Gerry Quinn
 
C

cjl

Hey all:

Here is a nice open source BMP library in C++:

http://easybmp.sourceforge.net/

The source code is well documented.

I guess I wouldn't try to reinvent the wheel on this one, and just use
a library that is already tried and tested.

-CJL
 
D

Don Lancaster

Raj said:
Hello Members,
I wrote a program to convert a greyscale bitmap image in to monochrome
bitmap image, a simple thresholding.

Input:Greyscale image[1 pixel = 8 bit ie 1 byte = 1 pixel];
Expected Output:Monochrome image[1 pixel = 1 bit]

Pseudocode:
row:0->height
column:0->width
if (current pixel value>Threshold value)
current pixel value = 0;
else
current pixel value = 255;

I am writing back the thresholded values in to the same input buffer.

The problem what i am facing is that i am getting a thresholded image
but in the grey scale image format.

So here i need to write 1 byte as 1 bit. I am stuck here. How can i do
this being my data remains the same but instead of 1 byte, it has to be
1 bit.

Kindly guide me

thanks
Raj

There are many different .BMP data formats.
To go to a true 1-bit, you have to repack the individual bits.

Grayscale stores one pixel in eight bits. True 1-bt stores eight pixels
in eight bits.

See http://www.tinaja.com/glib/expbmp.pdf and similar tools on our website.

--
Many thanks,

Don Lancaster
Synergetics 3860 West First Street Box 809 Thatcher, AZ 85552
voice: (928)428-4073 email: (e-mail address removed)

Please visit my GURU's LAIR web site at http://www.tinaja.com
 
R

Raj

Hello Members,
Thank you for all of your advice. I have sorted my problem. I passed on
the header values for the new monochrome image and wrote the data in
it. There must be a special caution interms of padding and interms of
colour table.

Thank you
Raj
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top