home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
GEMini Atari
/
GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso
/
zip
/
graphics
/
utility
/
mgif40.lzh
/
MGIF40
/
MGIF.1
< prev
next >
Wrap
Text File
|
1993-08-25
|
18KB
|
492 lines
NAME
mgif - display a GIF and Degas images in monochrome
SYNOPSIS
mgif
[
-i
] [
-v
] [
-N
] [
-pi1
|
-pi2
]
file
...
mgif
-fl
[
-m
]
file
...
DESCRIPTION
Mgif
displays color
GIF
and Degas
PI1
or
PI2
images on a
monochrome ST display.
GIF
files carry the extensions
!
.gif
"
and are compressed using
LZW
codes. It uses Floyd-Steinberg
dithering to simulate color. In addition, this new version
implements
!
flicker
"
palettes to simulate grayscale on a
monochrome screen. All things considered, it does a decent
job.
Mgif
now also contains numerous image processing functions to
enhance images. Included are:
Histogram equalization
Contrast stretching
Blurring
Brightening (or darkening)
Convolutions (numerous)
Enlarge/reduce
Inversion (negation with threshold)
Log scaling
Thresholding
Median filtering
Histogram plot
Mgif
allows each image processing function to be cummulative or
each operation can be independent.
Mgif
is interactive (not a
GEM
program) and prompts for commands. It also has online help
and can save the
!
flicker
"
screen image to a special file (*.fl)
for viewing.
Mgif
can also view these files.
OPTIONS
The following command line options are recognized:
-i
Inquire about the file but do not display it. Output
contains information like image size, number of bits per
pixel, and whether or not the image is interlaced or
sequential.
-v
Verbose output.
-N
Use the classic
NTSC
equation for computing luminescense
from
RGB
values, that is:
lum = 0.299 R + 0.587 G + 0.114 B
Otherwise the values are unweighted. This option only
makes sense for files with color maps in which the entry
for each color uses different values for red, green, and
blue. It is not recommended to use this for existing
grayscale images. Note that the actual equation used
is:
lum = (30 R + 59 G + 11 B) / 100
which is close enough. Also note that
NTSC
luminescense
is a global option and must be set on program entry.
-pi1
Files specified are Degas
PI1
files rather than
GIF
files, i.e. low resolution 320x200 16 color images.
-pi2
Files specified are Degas
PI2
files rather than
GIF
files, i.e. medium resolution 640x200 4 color images.
You will have to either shrink the horizontal axis or
expand the vertical axis after each image is read since
the aspect ratio is wrong. Since some images react
better to shrinking than expanding, the choice is left
to the user. It helps to blur the image first,
especially when shrinking, since there are only 4
intensities to start with. Blurring will increase the
number of intensities and shrinking will reduce the
effect of the blur. This is generally optimal for these
images.
file
One or more
GIF
files (or Degas files if
-pi1
or
-pi2
is
specified).
Mgif
can also be used as a simple flicker file viewer. To do
so, you must specify the
-fl
option. Only the
-m
option is
recognized in this case:
-fl
Just display flicker files (*.fl). With no other
options, each file is displayed sequentially. Any key
entered goes to the next file if there are any or
quits.
-m
This optional flag will attempt to create a mosaic of
multiple files. Either two 320x400, four 320x200, or
six 200x200 images are displayed at the same time. If
images are smaller or larger than these sizes, tile to a
size that fits. For example two 320x300 images will be
tiled as if they are 320x400.
file
In this case,
file
is one or more .fl files.
INTERACTIVE COMMANDS
The following commands are available at the prompt:
Control Commands
?
help
Clears the screen and prints a brief summary of
commands.
q
quit (next image)
Quit does not exit the program. It just moves to the
next image from the command line.
ESC
exit program
Cleans up and exits the program.
SPACE
draw image
The current image, either original or new, is drawn (or
redrawn).
w
what
Display information about the image.
hi
histogram
Plots the histogram of the original or new image,
depending on which mode is toggled. The histogram is
based on intensity only. Older versions of the program
displayed
RGB
histograms as well. That option was
dropped, though it was sometimes useful. Note that if
o
is toggled for original image, you should toggle
o
again
to plot a histogram of a transformed image, then toggle
back to work on the original.
o
original/new image
This toggles two sorts of behavior: 1) all
transformations take place on the
original
image and are
not cummulative, 2) all transformations take place on
the
new
(last) image and are cummulative.
f
file operations
Currently, the only file operation is to save the last
screen image to a special file having a
!
.fl
"
suffix, a
so called
!
flicker
"
file. This file contains the three
screen images which are used by the flicker routine to
simulate grayscale. These are the actual screen
bitmaps, truncated to the actual image size. Note that
in order to save an image in this format, you
must
first
display it completely by the flicker routine. You
should not escape the actual screen draw but let it
finish.
cp
image copy
You can copy the new, transformed image to the original
and visa versa. The former is the most useful.
Display Options
n
noise
Adds noise not to the image but to the
!
flicker
"
process
itself. Can help in images which have artificial
banding as a result of the dithering process. You are
asked for a value, which if 0, turns off noise
addition. Otherwise, it is a percentage (0 to 100).
Each time
o
is toggled, noise is reset to 0 (i.e. off).
g
Laplace filter
This, like noise, is not applied to the image itself but
rather in the flicker process. It helps to define hard
edges in images and implements a Laplace filter. A
quantity,
Beta
, is required. Use integers (1, 2, etc.)
for this value. A value of 1 corresponds to Beta of
0.25, a value of 2 corresponds to Beta of 0.50, etc. A
value of 0 turns off Laplace filtering. Each time
o
is
toggled, Beta is reset to 0 (i.e. Laplace filtering
off).
Frame Processes
e
enlarge
Enlarges images by 2x (only). You can choose the
dimension to enlarge as either horizontal, vertical, or
both. Note that if the size of an image is such that
enlarging it will exceed the amount of memory allocated
for the image, the enlarge is aborted. The enlarged
image can be larger than the screen, but must fit in the
raster memory. Enlarging is done by shifing pixels and
filling in the holes within a scan line with the average
of adjacent pixels, and between scan lines by averaging
adjacent scan lines to create the new one.
s
shrink
Reduces images by 2x (only). Makes them half size in
height and width. You can choose the dimension to
reduce as either horizontal, vertical, or both.
Reduction is a simple decimation which throws away every
other point in a scan line and every other scan line.
z
zoom
The image is drawn (without flicker) then gridded with a
20x20 grid, then a box appears representing the zoom
window which is always half the height and width of the
image. Move the box with the arrow keys. By
themselves, the arrow keys move 8 pixels in the
corresponding direction. Shifted arrows move the box 1
pixel at a time. Detect the final location with the
INSERT
key. Any other key cancels. Once the zoom
rectangle is defined, the image defined is expanded to
fit the current image size (similar to enlarge with both
directions specified).
cu
cut
Cuts out a rectangular area of the image for scrutiny.
You can choose to cut areas which are partially or fully
out of the display area. First, the image is
redisplayed without flicker. Then a 20x20 pixel grid is
overlaid. A crosshair system is then drawn. Move the
crosshairs with the arrow keys (see
zoom
section).
Detect the upper left corner first with the
INSERT
key.
Then do the same for the lower right corner. The cut
image is drawn with the same size as the cut area which
can then be enlarged if desired. Use zoom to cut and
enlarge (with restrictions) all at once. Cutting is
helpful for a number of uses including: 1) zooming in on
a smaller portion, 2) to trim artificial borders around
an image, 3) for artistic cropping.
r
rotate
You can only rotate the original image in this version.
If you are in
!
new
"
mode, you are asked if you want to
proceed (because any transformations done in the new
buffer will be lost) and if you answer
!
yes
"
, you are
placed in orig mode where the transformation takes
place. You are asked for an angle which must be either
-90 (for 90 degree clockwise rotation), 90 (for 90
degree counter clockwise rotation) or 180. After the
image is rotated, you are placed in
!
new
"
mode where all
suggessive transformations accumulate. The original
image, however, is also rotated.
mi
mirror
You can mirror about a horizontal axis (top to bottom
swap) or a vertical axis (left to right swap).
Point Processes
he
histogram equalization
Histogram equalization attempts to smooth out images
with skewed or narrow histograms. A histogram is a
graph showing the relative number of pixels with each
possible intensity value. The practical use is to make
images more uniform in contrast by making the histogram
more uniform and hence representing all intensities as
equally as possible. It is often not possible to achive
a very smooth histogram, but more often than not it is
possible to improve image quality. Histogram
equalization can also help to bring out structure hidden
in shadow. The technique used here does not randomly
redistribute pixels to new intensity levels. It just
changes the intensity of all pixels with a certain
intensity, thus stretching the histogram so that each
intensity is represented uniformly.
i
inverse (negation)
Invert an image, i.e. make low intensity pixels bright
and visa versa. Inversion is implemented here more
generally. A threshold is needed. If it is 0, the
entire image is inverted. If it is a negative value
between 0 and -255, only pixels
below
that level are
inverted. If it is a positive value between 0 and 255,
only pixels
above
that level are inverted.
The basic algorithm is:
For threshold = 0:
new[i] = 255 - old[i]
For threshold < 0:
new[i] = 255 - old[i], old[i] < -threshold
= old[i], otherwise
For threshold > 0:
new[i] = 255 - old[i], old[i] > threshold
= old[i], otherwise
l
log scaling
Application of log scaling helps some images. Here each
pixel's value is scaled to the ratio of the logarithm of
the pixel's intensity and the maximum intensity in the
image.
The basic algorithm is:
new[i] = maxval * log(old[i]) / log(maxval)
maxval is highest intensity in the image
t
threshold (black & white)
This process makes all pixels above a given threshold
intensity white and all below the threshold black. It
is useful in producing line art.
The basic algorithm is:
new[i] = 255, if old[i] > threshold
= 0, if old[i] <= threshold
co
contrast expansion
Attempts to expand the contrast of an image to cover the
entire range of 256 allowable grayscales. Somewhat
similar to histogram equalization but it does not
redistribute actual pixels. You are asked for a
threshold which is a pixel count. This determines the
lowest and highest intensities, based on the histogram,
which define the range to be stretched. What happens is
that the histogram is searched beginning at the low end
for the first intensity level with more pixels than the
input threshold. This is also done starting at the high
end. A range is thus defined. Entering 0 will define a
range starting with the lowest (and highest) intensity
for which there are more than one points.
The basic algorithm is:
new[i] = 255 * (old[i] - lo) / (hi - lo)
where lo to hi is new contrast range
The contrast range is defined by the intensities of bins
which exceed the given threshold pixel count at both low
and high ends of the histogram.
br
brighten (or darken)
Here a constant intensity is added (or subtracted) from
every pixel. A negative number causes image darkening
and a positive number causes image brightening. Pixels
which would otherwise go less than 0 or greater than 255
are limited to these values, respectively.
The basic algorithm is:
new[i] = old[i] + constant
Area Processes
bl
blur
Blurring an image can also help contrast, though at the
expense of loss of detail. Here a 3x3 neighborhood is
used. Often in practice a 5x5 neighborhood is used, but
that tends to take a relatively long time.
The basic algorithm is (j runs through the 3x3
neighborhood):
new[i] = sum (old[i] ) / 9
j j
me
median filter
Median filtering can remove noise from an image. Here a
3x3 neighborhood is used with the median value of each
of the 9 pixels replacing the pixel of interest. This
is done in place so that the next pixel examined within
the row or the next row will see pixels already
filtered.
The basic algorithm is (j runs through the 3x3
neighborhood):
new[i] = median (old[i] )
j j
v
convolution filters
Apply one of a number of 3x3 convolutions to an image.
Choose one of the built-in filters (number greater than
0) or enter 0 for user defined. In the latter case, you
enter the 9 elements of the convolution kernel along
with a flag if there will be a multiplier (or divisor).
Then enter that scaling factor. All quantities are to
be integers.
The basic algorithm is (j runs through the 3x3
neighborhood):
new[i] = sum (old[i] * k )
j j j
or
new[i] = sum (old[i] * k ) * multiplier
j j j
or
new[i] = sum (old[i] * k ) / divisor
j j j
where k is the corresponding kernel value.
j
It is not a matrix multiply, rather an element by
element multiply and summation.
FILES
*.gif GIF image files
*.pi1 Degas low resolution files
*.pi2 Degas medium resolution files
*.fl flicker files
SEE ALSO
gif(5), showfl(1L), pi1(1L)
Gonzalez and Wintz,
Digital Image Processing
.
Lindley,
Practical Image Processing In C
.
Burger and Gillies,
Interactive Computer Graphics
.
DIAGNOSTICS
Various warnings attempting to isolate corrupted files. The
usual messages about errors openning files, etc. If an error
occurs during a processing function, the prompt line will
indicate the error.
NOTES
Source code has standalone versions (i.e. single entry point)
for both reading
GIF
files and displaying grayscale bitmaps with
flicker.
BUGS
As compiled,
mgif
handles images up to 400,000 pixels or about
640x620 (or any other combination totaling less than 400,000).
It needs dynamic memory but I generally stay away from
GEMDOS
Malloc
(2), prefering libc
malloc
(3) (i.e. off stack in my
library).
GIF
decoding is slow and could be faster. Some of the area
processes (blur, etc.) could also be faster.
Log scaling needs logarithms but I did not want to use floating
point so I get a crude (two significant digit) base 2 log.
The flicker file (*.fl) format is not fully defined.
TODO
Though
mgif
is now fairly complete, there are some things that
would be nice to add. Here is the short list:
*
Merge images
*
Batch processing
*
Save history of changes for batch
*
Histograms by pixel range directly
*
Comparative flicker (i.e. A/B)
AUTHOR
Bill Rosenkranz (rosenkra@convex.com)
Flicker adopted from code by Klaus Pedersen (micro@imada.dk)
VERSION
mgif 3.5 91/6/15 rosenkra