473,408 Members | 1,744 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

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

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

Aug 24 '05 #1
9 4414

Raj wrote:
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

Aug 24 '05 #2
Raj wrote:
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.

--
Regards,
Martin Leese
E-mail: pl****@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/
Aug 24 '05 #3
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

Aug 24 '05 #4
Raj wrote:
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?

--
Regards,
Martin Leese
E-mail: pl****@see.Web.for.e-mail.INVALID
Web: http://members.tripod.com/martin_leese/
Aug 24 '05 #5
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

Aug 24 '05 #6
In article <11**********************@o13g2000cwo.googlegroups .com>,
kr****@yahoo.com says...
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
Aug 25 '05 #7
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

Aug 25 '05 #8
Raj wrote:
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: do*@tinaja.com

Please visit my GURU's LAIR web site at http://www.tinaja.com
Aug 25 '05 #9
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

Aug 29 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

48
by: Joseph | last post by:
Hi I'm writing a commercial program which must be reliable. It has to do some basic reading and writing to and from files on the hard disk, and also to a floppy. I have foreseen a potential...
6
by: Sebastian Kemi | last post by:
How should a write a class to a file? Would this example work: object *myobject = 0; tfile.write(reinterpret_cast<char *>(myobject), sizeof(*object)); / sebek
3
by: ishekar | last post by:
Hi, I have an application where i want to write data to a file, the data is being sent from an external source. I know the total size of the data and then i retrieve the data in small segments...
1
by: Daniel | last post by:
System.IO.StreamWriter Close or Flush method to shut down the computer in such a way that just part of the file is written? or an empty file is written? Also if the Close or Flush is to a...
5
by: Jeong-Gun Lee | last post by:
I'm writing a code of writing a value to a specific memory address. ================================================================= #include <stdio.h> int main() { long air; long...
102
by: Xah Lee | last post by:
i had the pleasure to read the PHP's manual today. http://www.php.net/manual/en/ although Pretty Home Page is another criminal hack of the unix lineage, but if we are here to judge the quality...
16
by: Claudio Grondi | last post by:
I have a 250 Gbyte file (occupies the whole hard drive space) and want to change only eight bytes in this file at a given offset of appr. 200 Gbyte (all other data in that file should remain...
6
by: arne.muller | last post by:
Hello, I've come across some problems reading strucutres from binary files. Basically I've some strutures typedef struct { int i; double x; int n; double *mz;
3
by: Barry Flynn | last post by:
Hi I am working with a VB 2005 program which has been converted from VB6. It writes data out to a flat file, with code like the following line WriteLine(riFileNo, "Hist", lsAssetID,...
89
by: Skybuck Flying | last post by:
Hello, This morning I had an idea how to write Scalable Software in general. Unfortunately with Delphi 2007 it can't be done because it does not support operating overloading for classes, or...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.