Dec 092017
 
Changes B&W pictures to grey scale.
File BIT2GRAY.ZIP from The Programmer’s Corner in
Category Printer + Display Graphics
Changes B&W pictures to grey scale.
File Name File Size Zip Size Zip Type
BIT2GRAY.DOC 7338 2482 deflated
BIT2GRAY.EXE 44992 15545 deflated
FACE261.GIF 23958 23369 deflated

Download File BIT2GRAY.ZIP Here

Contents of the BIT2GRAY.DOC file


============================================================
BIT2GRAY 1.0 -- Convert Black and White Images to Gray Scale
============================================================
Copyright 1989 Brian K. Uechi. All right reserved.


========
Synopsis
========

bit2gray [-option] [.PCX] [.PCX|.PCC]

-2 = Convert 2x2 non-overlapping cells to 5 level gray scale.
-3 = Convert 3x3 non-overlapping cells to 10 level gray scale.
-4 = Convert 4x4 non-overlapping cells to 16 level gray scale.
-5 = Convert 5x5 non-overlapping cells to 16 level gray scale.
-6 = Convert 6x6 non-overlapping cells to 16 level gray scale.

-20 = Convert 2x2 overlapping cells to 5 level gray scale.
-30 = Convert 3x3 overlapping cells to 10 level gray scale.
-40 = Convert 4x4 overlapping cells to 16 level gray scale.
-50 = Convert 5x5 overlapping cells to 16 level gray scale.
-60 = Convert 6x6 overlapping cells to 16 level gray scale.

-41 = Convert 4x4 non-overlapping cells to 17 level gray scale.
-51 = Convert 5x5 non-overlapping cells to 26 level gray scale.
-61 = Convert 6x6 non-overlapping cells to 37 level gray scale.

-410 = Convert 4x4 overlapping cells to 17 level gray scale.
-510 = Convert 5x5 overlapping cells to 26 level gray scale.
-610 = Convert 6x6 overlapping cells to 37 level gray scale.

========
Examples
========

bit2gray -61 infile outfile
This converts the black and white input file "infile.pcx" to the
gray scale output file "outfile.pcx". The option "-61" selects a 6x6
grid moving 6x6 input pixels per output pixel (non-overlapping mode).
The output file will be padded on the right to make it at least 320
pixels wide. The output file will be a 256 color PCX file although
there will be at most 37 gray levels. The output file will be 1/6
the height and width (padding may make it wider) of the input file.

bit2gray -6 infile outfile.pcc
This converts the black and white input file "infile.pcx" to the
gray scale output file "outfile.pcc". The option "-6" selects a 6x6
grid moving 6x6 input pixels per output pixel (non-overlapping mode).
The output file will be not be padded since it is a cutout file. The
37 possible gray levels will be mapped to 16 gray levels yielding a
16 color PCC output file. The output file will be 1/6 the height and
width of the input file.

bit2gray -40 infile outfile.pcc
This converts the black and white input file "infile.pcx" to the
gray scale output file "outfile.pcc". The option "-40" selects a 4x4
grid moving one input pixel per output pixel (overlapping mode). The
output file will be not be padded since it is a cutout file. The 17
possible gray levels will be mapped to 16 gray levels yielding a 16
color PCC output file. The output file will be approximately the
same height and width as the input file.


===========
Description
===========

BIT2GRAY converts black and white dithered images to gray scale. It works
by moving an NxN grid over the dithered image and counting the number of
light pixels in the grid. This count is used as the gray scale intensity.

BIT2GRAY reads and writes ZSoft Corporation PC Paintbrush (.PCX) files.
It reads black and white PCX files of any size (limited by available
memory) and writes 16 color/gray scale or 256 color/gray scale PCX files.
The 16 gray scale files are best loaded into PC Paintbrush configured for
VGA 640x480x16 colors/gray scale. The 256 color/gray scale files are best
loaded into PC Paintbrush configured for VGA 320x200x256.

In real life, VGA has only 64 gray levels and a 6x6 grid can have only 37
different gray levels. However, PCX files apparently must be either 16 or
256 color pictures.

BIT2GRAY can also write ZSoft Corporation PC Paintbrush cutout (.PCC)
files. The difference is PCX files are at least 320 pixels wide for 256
color files or 640 pixels wide for 16 color files. This means there may
be extra padding on the right hand side of the image to force the proper
minimum width. PCC files are only as wide as the image. The reason for
padding is PC Paintbrush sometimes refuses to load PCX files which are not
wide enough. It usually pastes cutout files properly although it ignores
the color palette. I use the Pictor paint program which properly loads
both PCX and PCC files.

The DFI HS-3000 hand scanner uses a 6x6 pattern dither so you'll get the
best results by using a 6x6 non-overlapping option. Using other options
usually results in interference lines. The non-overlapping options
greatly shrink the image so always scan at 300 or 400 dpi. Use your
favorite paint program or desktop publishing program to stretch and crop
the scan.

The other options are useful for converting high quality dithered pictures
to gray scale. For example, many MacPaint files exhibit very good
dithering and convert well to 16 level gray scale using the "-4" option.


=====================
Creating GIF pictures
=====================

The sample picture was created with a DFI HS-3000 hand scanner and Scan
1.0 software configured for 400 dpi. The 1664x1251 black and white PCX
file was converted to a 320x208 256 color/gray scale (really only 37 gray
levels at most) PCX file using the "-61" option. The 256 color PCX file
was converted to GIF format using John Bridges' CVTGIF 1.4 program.
Earlier versions of CVTGIF may not properly convert 256 color PCX files.
I use John Bridges' PICEM 1.9b program to view the images and adjust the
contrast and brightness. This program can load PCX files directly but
does not read 256 color PCX files properly.


==================
Why use gray scale
==================

Gray scale images can be stretched and resized without the ugly lines and
interference patterns resulting from manipulating dithered images. The
type of dithering used by DFI is particularly susceptible to these defects.

Another reason is the dithering methods used by DFI are dreadful. There
are much better dithering algorithms called error diffusion dithering
which yield much better looking results.

==============
How to find me
==============
If you have any problems or suggestions please let me know. I can be
reached via GEnie, CompuServe, or U.S. mail.

Brian K. Uechi
2616-A Kalihi St.
Honolulu, HI 96819

GEnie: B.UECHI
CompuServe: 72330,155

If you find this program useful, please support the further development of
this and similar programs by sending $15.00 to:

Brian K. Uechi
2616-A Kalihi St.
Honolulu, HI 96819


======================
DISCLAIMER OF WARRANTY
======================
THIS SOFTWARE AND DOCUMENTATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF
ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS OF PURPOSE. YOU ASSUME
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM AND
DOCUMENTATION. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE ENTIRE
COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.


 December 9, 2017  Add comments

Leave a Reply