CHAPTER 1. IMAGE FILE INPUT AND OUTPUT
The BMP color table has four bytes in each color table entry. The bytes
are for the blue, green, and red color values. The fourth byte is padding and
is always zero. For a 256 gray shade image, the color table is 4x256 bytes
long. The blue, green, and red values equal one another.
The nal part of the BMP le is the image data. The data is stored row
by row with padding on the end of each row. The padding ensures the image
rows are multiples of four. The four, just like in the color table, makes it
easier to read blocks and keep track of addresses.
1.5.1 The BMP Code
The code in Listing 1.3 reads image arrays from and writes them to BMP
les. The code works with eight-bit gray scale BMP images. It sits one level
closer to the les than the general routines given in listing 1.1.
Listing 1.4 (cips.h shown later) contains the #include les, constants and
the data structures. The structures bmpleheader and bitmapheader hold
the information from the BMP le header and bit map header.
Listing 1.3 begins with the functions that read the essential header infor-
mation from a BMP le. The function read
header reads the rst
information in the BMP le. The function read
header reads the bit map
header information. The function read
table reads the essential color
Next comes reading image datafrom le with read
image. This calls
the above functions to learn the header information. It seeks to the start of
the image data and reads the data one byte at a time. This function uses the
color table information to convert the read byte to the proper short value. If
array is called to turn the image right-side up.
The next functions create a blank BMP le on disk. The function cre-
needed checks the le name given it does
exist. If it does
needed calls create
le to create and ll
the blank BMP le. It writes the necessary header information and color
table before writing zeros to the le.
The function write
image writes an array of numbers into a BMP
le. First, it reads the header information and seeks to the color table loca-
tion. After writing the color table to le, it loops over the height and width
of the array of numbers. It writes the image data to disk by lling a buer
with one row of image data at a time and writing this buer to disk.
VB Imaging - VB ISSN Barcode Generating
help VB.NET developers draw and add standard ISSN barcode on photos, images and BMP image formats, our users can even create ISSN barcode on PDF, TIFF, Excel extract images from pdf acrobat; extract vector image from pdf
1.6. A SIMPLE PROGRAM
The remaining functions in listing 1.3 are utilities. The function is
looks at a le name and then the information in the le header to determine
if a le is a BMP image le. The function calculate
pad calculates the extra
bytes padded tothe end of a row of numbers tokeep thefour-byteboundaries
in place. The function equate
bmpleheaders sets the essential le header
information equal for two headers, and
ips the image num-
bers right-side up.
1.6 A Simple Program
Listing 1.5 shows how a simple program can use the I/O routines presented
earlier. This listing shows the round program that rounds o a part of an
input le and stores it to an output le. The basic use of this program is
to create a new le that contains the desired part of an existing le. The
user species the desired starting point in the existing le and the size of the
The program rst interprets the command line to obtain the le names
and output image size. It calls the is
aroutines to determine the type of
le being used. The next calls create the desired output le. Calls to the
previously discussed routines allocated two arrays of shorts and read the
input image. The loop over out
length and out
width copy the desired part
of the input image to an output image array. The nal calls write the output
image to the output le and free the memory used by the two image arrays.
1.7 Converting Between TIFF and BMP
The nal two listings in this chapter show short programs that convert be-
tween the TIFF and BMP image le formats. Listing 1.6 shows the tif2bmp
program. It checks the command line parameters to ensure the user entered
the proper le names. The program obtains the size of the input TIFF image
le, allocates an image array of that size, and creates an output BMP image
le also of that size. It then reads the image data from the input le and
writes it to the output le.
Listing 1.7 shows the bmp2ti program. This program is similar to the
tif2bmp program described above. It reads data from a BMP image le,
creates a TIFF image le, reads the data from the BMP image le, and
CHAPTER 1. IMAGE FILE INPUT AND OUTPUT
writes it to the TIFF le.
This chapter has discussed image le input and output. Image I/O is a
fundamental part of image processing. Images are easier to nd today than
ever before. The second edition of this book is based on the new image I/O
routines described in this chapter. These routines allow the image processing
programmer to concentrate on image processing operators. The current I/O
routines work with 8-bit gray scale TIFF images and 8-bit gray scale BMP
images. Inexpensive software products are available to convert almost any
image to one of these formats.
1.1. \TIFF Revision 6.0," Final, June 3, 1993, Aldus Developers Desk, Aldus
Corporation, 411 First Avenue South, Seattle, WA 98104-2871, (206) 628-
6593. See also
1.2. \Encyclopedia of Graphics File Formats," James D. Murray, William
vanRyper, O’Reilly and Associates, 1996.
1.3. \The BMP File Format: Part I," David Charlap, Dr. Dobb’s Journal,
1.4. \The BMP File Format: Part II," David Charlap, Dr. Dobb’s Journal,
Viewing and Printing Image
Image processing is a visual task. Therefore, displaying images in various
forms is a necessity. This chapter presents techniques to display the numbers
in an image on a screen, print the numbers in an image, and display and
print the image like a photograph.
2.2 Displaying Image Numbers
There are times when the best technique an image processor can use is to
look at the raw image numbers. The numbers tell exactly what is happening.
They show what the image operators are doing to the image.
The rst method of looking at image numbers is to display them on the
screen. The rst program presented in this chapter shows the image numbers
on a DOS text window on a PC. This would also work in a text window on
Listing 2.1 presents the showi program. It reads the image numbers from
the input le and shows a portion of the numbers on the screen. The user
can alter which part of the image is displayed via keystrokes. This is a short,
simple program that is quite useful when trying to have a quick view of the
CHAPTER 2. VIEWING AND PRINTING IMAGE NUMBERS
2.3 Printing Image Numbers
Printing image numbers on paper gives the image processor something noth-
ing else will | a hard copy of the image in your hand to study. The program
in listing 2.2 takes the easy route by dumping all the image numbers to a
text le. Common word processors can do the work of printing to paper.
When the image exceeds page width (which happens almost all the time),
the user can adjust font size and page orientation and resort to that tried
and true technique of taping pages together.
Listing 2.2 shows the dumpi program. It reads the entire input image
into an array and writes the numbers in each line to a buer. The program
writes each buered line of numbers to a text le.
2.4 Viewing and Printing Images
Viewing and printing images like photographs is easier today than ever in
the past. Discretion is the better part of valor, so I opted out of writing
viewing and printing programs for the Windows environment. There are
many excellent programs available at little or no cost. As in chapter 0, I
recommend VuePrint from Hamrick Software (http://www.hamrick.com).
This approach also improves portability. Users of UNIX systems can also
nd free or inexpensive image viewers and printers.
Word processors are much better today than ve years ago. Almost any
word processor can import a le and print it alone and in a document. It
seems a long time ago when that was not possible. That is why I struggled
with photographingCRT displays and included those photographs in therst
edition of this book. Those less than wonderful pictures are absent from this
edition. The publisher, and almost anyone else, can now import the image
les into a publishing package with much better results.
Use what is available in the marketplace to view and print images. This
continues with the spirit of the C Image Processing System. Concentrate
on image operators and leave the details of image I/O (including display) to
C# Imaging - Scan RM4SCC Barcode in C#.NET
PDF, Word, Excel and PPT) and extract barcode value Load an image or a document(PDF, TIFF, Word, Excel barcode from (scanned) images, pictures & photos that are pdf image extractor online; extract jpeg from pdf
This chapter has discussed methods of viewing an image. Often, there is no
substitute for looking at the raw image numbers. This chapter presented a
program to see the numbers on the screen and another one that dumps the
image numbers to a text le. Word processors can print those numbers to
paper for examination. Viewing and printing images in visual format has
been left to others. Inexpensive programs that display images on the screen
are available. Today’s word processors are much more powerful than ve
years ago. They can import and print images to paper.
CHAPTER 2. VIEWING AND PRINTING IMAGE NUMBERS
Black and white printers put gray shade images on paper via the presence
or absence of black ink on paper. Printers do not contain ink with varying
shades of gray. These black and white output devices create the illusion of
shades of gray via haltoning.
This chapter presents a halftoning algorithm that converts a gray scale
image into an image containing only 1s and 0s. The image display sources of
chapter 2 can output the resulting image.
This chapter also presents a program that dumps the 1/0 image to a text
le as spaces and asterisks. A word processor can print that text le allowing
the user to make a large wall display of an image.
3.2 The Halftoning Algorithm
Figure 3.1 shows the basic halftoning algorithm. Reference [3.1] is the source
of the original algorithm. The basis of the algorithm is an error-diusion
technique. When the \error" reaches a certain value, turn a pixel on and
reset the error. If the error is not great enough, leave the pixel turned o.
Errors result from approximating a gray shade image with only ones and
Figure 3.1 shows the input imageI with R rows and C columns. E
is the sum of the errors propagated to position (m,n) due to earlier 1 or 0
(m;n) is the total error generated at location (m,n). C(I;J)
CHAPTER 3. HALFTONING
I(R,C) - input image with R rows and C columns
Ep(m,n) - sum of the errors propogated to position (m,n) due
to prior assignments
Eg(m,n) - the total error generated at position (m,n).
C(i,j) - the error distribution function with I rows and J
1. Set Ep(m,n) = Eg(m,n) = 0 for R rows and C columns
2. loop m=1,R
3. loop n=1,C
4. Calculate the total propogated error at (m,n) due to
5. Sum the current pixel value and the total propogated
error: T = I(m,n) + Ep(m,n)
6. IF T > threshold
THEN do steps 7. and 8.
ELSE do steps 9. and 10.
7. Set pixel (m,n) on
8. Calculate error generated at current location
Eg(m,n) = T - 2*threshold
9. Set pixel (m,n) off
10. Calculate error generated at current location
Eg(m,n) = threshold
3. end loop over n
2. end loop over m
Figure 3.1: The Basic Halftoning Algorithm
Documents you may be interested
Documents you may be interested