Note: Descriptions are shown in the official language in which they were submitted.
~;~8347'7
Y09-82-040X
CORRECTION OF SHADING EFFECTS IN VIDEO IMAGES
DESCRIPTION
BACKGROUND OF THE INVENTION
1. Field of the Invention
The present invention relates to image data enhancement
apparatus and methods, and more particularly to apparatus
and methods of flltering undesired shading effects from
video images.
2. Description of the Prior Art
1~83477
Y09-82-040X 2
In the prior art there are many image data processing
systems available. Some examples of systems representative
of the prior art are the following.
U.S. patent 3,621,129 to Fisher relates to devices for
enhancing images by quantizing picture element levels into
binary digital signals employing a threshold which is
derived from the gray scale values of the image under
analysis. The apparatus of the patent examines gray scale
values of picture elements immediately preceding and
succeeding a feature under analysis and a variable threshold
i~ generated which i~ derived from a mean value between the
maximum black signal level immediately before and after the
feature under analysis.
The patented system does not acquire a histogram of
distribution of gray ~cale intensity levels in the entire
image to provide a uniform correction but rather provides
only a localized threshold calculation.
U.S. Patent 3,979,555 to Oppitek relates to a histogram
equalized system that adaptively redistributes the intensity
levels of video signals in order to provide an
1283477
Yo9-82-040X 3
equal number of elements at all display intensity levels.
This patented system does not relate generally to a
method of correcting shading effects in video images where a
correction value is calculated from the variations in
background level in the entire image.
U.S. patent 3,800,078 to Cochran teaches a digitally
compensated scanning system wherein an initial scan of black
or background information is stored in a look-up table and
compared to desired data signals to eliminate undesired
variations or noise resulting from photodiode leakage
current or other noise sources.
This patent does not show a method of correction
shading effects in video images in which a histogram of
distribution of gray scale intensity levels i~ acquired and
u~ed to calculate a threshold value and range of permissable
background gray scale values that generates a correction
signal which, when combined with the raw data provides an
output signal that is corrected for undesired shading
effects.
1283477
Y09-82-040X 4
U.S. Patent 4,232,400 to Yamamoto shows an echo control
system for an adaptive echo canceller which cancels an echo
signal while successively estimating the transmission
characteri~tic of an echo path that includes means for
filtering by convolution a transmitted signal including echo
characteristics.
The patent does not teach a method of correcting
~hading effects in video images using a histogram of
distribution of gray scale intensity levels for calculating
maximum white, maximum black and threshold values and
generating a correction signal to eliminated shading
effects.
An article entitled "Digital Processing Techniques for
Encoding of Graphics" by Ting and Prasada, which appeared in
the Proceedings of the IEEE, V01. 68, No. 7, July 1980 at
page 757 and following, providec a survey of techniques for
preproce~ing input documents having noise contents which
croate poor data compression ratio~.
The article discusses a piece-wise local approach to
shading correction in which a number of ~mall overlapping
samples or windows are examined and a threshold is
1283477
Y09-82-040X 5
established for each of these windows. The approach
presents a potential problem with respect to different
thre~hold~ at either side of a boundary between adjacent
windows. Discontinuities in the threshold going form window
to window may result in undesired effects in the image. The
article does not present a global shading correction
algorithm in which the shading for the image is corrected
without discontinuity.
Other articles digcussing the general problem of
thresholding are found in IEEE Transactions on Systems, Man,
and Cybernetics, Vol. SMC-8, No. 8, August 1978, at pps.
622-632. The segmentation of an image into background and
foreground regions is discussed as well as the general
technique of background sampling in the region of an object
and the difficulties in the choice of background samples.
However, a slmple and effective method and means for
correcting shading efects in video image~ i8 not found
among this art.
It will therefore be seen that the prior art discussed
above neither teaches nor suggests the present invention as
disclosed and claimed herein.
lZ834'77
YO9-82-040X 6
SUMMARY OF THE INVENTION
Accordingly, it is an object of the present invention
to provide methods and means for correcting shading effects
in video images having a plurality of picture elements where
each picture element or pel may be represented by a gray
scale intensity value. The method of the invention involves
e.g., in suitable computer means, the steps of generating a
histogram of distribution of gray scale intensity values of
picture elements in the original image, and calculating a
maximum white gray scale value, a maximum black gray scale
value and an intermediate gray scale value, such as the
median, from the histogram. The image polarity, that is the
background colour. may then be determined empirically by
noting which of the gray scale extremes is located closest
to the intermediate value. A range of permitted background
gray scale lnten~ity values i9 then selected such as by
calculating the distance between the median and the
background or ma~ority colour extreme and setting the range
as twice that distance centered at the median. Having
established these parameters, two approaches are presented
for correcting for shading effects.
~83477
Y09-82-040X 7
In the first embodiment a lookup table (LUT) iq
constructed which remaps the original image to a correction
image. The original intensity value of each pel i5 compared
with the median value and the LUT output represents the
difference between the two. If the difference is outside
the permitted range, no correction is made; otherwise, the
difference is used to correct the original intensity. A
neighbourhood sampling procedure is carried out for each pel
to obtain an average value for each correction.
In the latter embodiment a first background image is
created, e.g., in a "reference" buffer, by sampling the gray
scale intensity value of each pel in the original image to
be corrected and using a suitable lock-up table ~LUT) to
remap the image from 8 bits to 5 bits with all values
outside the permitted or acceptable range set to that of the
neare~t colour extreme. A duplicate background image is
then created from the remapped image, e.g., in another or
"neighbouring" buffer. Sampling of the gray scale intensity
values of a number of pels in a predetermined region around
a first pel in the duplicate image is then carried out and
the gray scale value of the corresponding pel in the first
background image to be corrected for shading is changed to
the largest
. .
1283477
Y09-82-040X 8
value (assuming the majority colour extreme to be larger)
among those of the first pel and the sampled pels. This
operation may be accomplished using a 10 bit LUT by making
the 5 bits representing the first pel value the low order
input and those of the sampled neighbouring pel the high
order input. The duplicate background image is then
changed to conform to the changed first background image and
the sampling procedure is carried out over a larger
surrounding region and a larger number of pels with the
corresponding changes in the first background image. This
procedure may be repeated until a background image with the
desired level of shading corrections is achieved.
It i# another object of the present invention to
correct shading effects in video images as above by further
including the step of determining, during the sampling over
the ~urrounding reglon, if the corrected gray scale value of
oach pel in the background image is less than a
predetermined value. This is accompli~hed by detecting
"low" pel values or poor whites (poorwht) and storing
indications of such in an overlay plane, which
. j~ .
1283477
Y09-82-040X 9
indications are changed when appropriate during successive
samplings. subsequent samplings may then be carried out
only on pels with low value indication8 until the desired
correction level i 8 achieved.
It is yet another object of the present invention to
correct shading effects about the edges of video images and
a method and means for this purpose is also described.
Therefore, an apparatus for correction shading effects
in video images according to the present invention employs
an image proce~sing system including: a plurality of full
image buffers; means for generation an histogram of, and
providing the histogram calculations for, the image to be
corrected; means for creating a background image and a
duplicate background image in the buffers; means for
controlling the operation of the image processor for
sampling the gray scale inten~ity values of picture elements
ln a region around a current picture element to be corrected
in the duplicate background image; means for correcting the
value of the corresponding current picture element in the
background gray scale value determined from the previous
step; means for executing the sampling and
lX83477
YO9-82-040X 10
correcting steps for each picture element in the duplicate
and background images and conforming the former to the
latter upon completing all of the correction; and means for
repeating the proceeding ~tepg to provide a uniform shading
correction throughout a video image.
The foregoing and other objects, features and
advantages of the invention will be apparent from the more
particular deæcription of the preferred embodiments of the
invention, a~ illuQtrated in the accompanying drawing.
BRIEF DESCRIPTION OF THE DRAWINGS
FIG. 1.1 illustrates a character of a video image
intercepted by a scale line to produce a video signal.
FIG. 1.2 shows an idealized video signal generated from
tho scannod character of FIG. 1.1
FIG. 1.3 show~ a video signal as in FIG. 1.2 including
ehadlng defects from camera characteri~tics, lighting or the
like.
~83477
YO9-82-040X 11
FIG. 2 is a general block diagram of apparatus
according to the present invention for correcting shading
defects in a video image.
FIG. 3.1 is a diagram illustrating a histogram of the
number of occurences of pel intensity values before shading
corrections.
FIG. 3.2 is a histogram as in FIG. 3.1 after shading
correction has been performed in accordance with the
apparatus and method of the present invention.
FIG. 4.1 is a general diagram of the steps involved in
analyzing a histogram to determine parameters to be used for
the shading correction.
FIG. 4.2 i~ a flow chart of the steps used in
doterminlng image background colour.
FIG. 4.3 is a flow chart of the steps used in
determining the poor white (POORWHT) range.
FIG. 5.1 i3 a general flow chart illustrating the
operation of the shading correction filter.
1~83477
Y09-82-040X 12
FIG. 5.2 shows the steps involved in inverting the
image when the background colour has been determined to be
black.
FIG. 5.3 shows the steps involved in creating a
background image in a five bit representation.
FIG. 5.4 shows the steps used to create the look-up
tables for selecting the whiter of two background image
values .
FIG. 5.5 is a flow chart of the initial maximum white
selection process carried out in a small neighbourhood
around each pel of the background image.
EIG 5.6 is a flow chart of the maximum white selection
process carried out in large neighbourhood wherever the
maximum white image remains in the POORWHT.
EIG. 5.7 is a flow chart of the summation process used
to filter any noise in the maximum white background image.
EIG. 6.1 i8 a diagram showing an uncorrected video
signal having a concave ~hading defect.
~83477
YO9-82-040X 13
FIG. 6.2 is a diagram showing the concave shading
defect isolated from the video signal in accordance with the
present lnvention.
FIG. 6.3 is a diagram showing the shading corrected
video ~ignal in accordance with the present invention.
DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENT
Most images captured from television cameras have
substantial shading problems, even when the cameras
incorporate shading correction circuitry. The shading, or
low a partial frequency variations, in the image can cause
problem~ when the image is to be converted by thresholding
to a graphics image having one one or two bits per pel
(picture element). Apparatus and methods are disclosed
herein for correcting these shading effects and while those
skilled in the art may adapt the invention to use in many
different ways drawing from the following description, the
present invention may be particularly implemented using a
commercially available image proce~sor, such as a Grinnell
GMR-270, operating under the control of a digital data
processing ~ystem, such
'~.
~83477
Y09-82-040X 14
as the IBM* Series I, so that the description will be
directed to such an implementation.
Referring firstly to FIGS. 1.1, 1.2 and 1.3, the
generation of a video signal with shading effects will be
discussed. FIG. 1.1 shows a text data character such as 0
being intercepted by a horizontal scan line.
Ideally, a black character on a white paper background
would produce a video signal such as is shown in FIG. 1.2
having a relatively uniform flat background white level
except for areas where black text data occurs at which point
the video signal would switch to the black level.
As can be seen in FIG. 1.3, the actual video signal
representative of the 0 of FIG. 1.1 includes shading effects
which create ambiguities in separating text data from
background in an image. It can be seen in FIG. 1.3, that
the shading of the white paper background causes a gray
#cale variation in areas where no text data appears which
can inhibit efficient data compression and transmission and
create undesired artifacts in the transmitted image.
* Registered Trademark
1283477
YO9-82-040X 15
Referring now to FIG. 2, a block diagram of apparatus
according to the present invention is illustrated. A video
signal containing image data is stored in image buffer 12 in
such a way that access may be had to an intensity value for
each pel in an image. The data in image buffer 12 is
~ampled by an histogram acquisition circuit 14 to determine
the gray scale level distribution of pels in the image. FIG.
3.1 shows the form of a resulting histogram for a graphics
image before shading correction. Note that for a black
data-on-white background graphics image the majority of pels
are normally near the white intensity values since in a
black-on-white graphics image there are usually many more
background pel positions than there are data pel positions.
There are many techniques for acquiring and presenting
histogram information including that shown in U.S. Patent
3,979,555 discussed above. Once the histogram has been
acquired it is then analyzed to determine certain working
parameters to be used in carrying out the shading
correction. This analysis may be accomplished in a general
purpose computer 16 and the output provided to a ~hading
correction filter 20 which may be an image or other suitable
processor.
1'~83477
Y09-82-040X 16
FIG. 4.1 shows the sequence of steps to be followed in
deriving parameters from the histogram for used in shading
correction techniques described in this application.
The first three steps in FIG. 4.1 involve calculation
of the median (MED), minimum (MIN) and maximum (MAX) gray
scale intensity levels in the image. The calculation of
these parameters and the calculation of the background
colour may be carried out in various ways. The simplest
technique would be to identify levels in the image. The
calculation of these parameters and the calculation of the
background colour may be carried out in various ways. The
simplest technique would be to identify the background
colour with the extreme closest median, and this will work
well for most images. However, experimental studies have
shown that unless an image background can be clearly
classified as black, it should be cla~ified as white. This
cla~slfication technique is shown in FIG. 4.2. For
convenience, define WDIF a~ the difference between the white
extreme (MAX). For an image background to be classified as
black, 2 x BDIG should be less than WDIF.
After the background colour is determined, another
parameter, POORWHT, is derived which is used as a measure
1~3477
Y09-82-040X 17
of the range of background intensities for which the shading
correction requires sampling over larger neighbourhood as
will be described. The procedure for determining POORWHT,
shown in FIG. 4.3, is derived empirically. Similarly to
define an acceptable background range R, we define DIF as
the magnitude of the difference between the median and the
background extreme. The lower limit of the background
intensities LN is set at MED-DIF, and the upper limit LP is
MED + DIF. The total background range R is from LN to LP.
If the background intensity range can be cleanly
discriminated from foreground intensities, LN is set to O
and LP is set at 31. This permits range R to be identified
by 5 bits, as will be seen. POORWHT is then set to 2. All
images classified as black background are automatically
placed in this class. If the discrimination is not very
good (WDIF2 2 x BDIF). POORWHT is increased to 5, and if
the discrimination is very poor (MIN2 MED-DIF), POORWHT is
increased to 12. The intensity range from MIN to MIN + R x
(POORWHT-1)/32) ls defined as the background intensity range
where the shading correction requires sampling over a larger
neighbourhood .
Once the background colour has been identified and MED, DIF
and POORWHT obtained from the histogram, the shading
1'~83477
Y09-82-040X 18
correction is performed. Two embodiments will be described
but first it should be understood that the shading
correction methods and apparatus according to the present
invention are based upon the following sampling concept.
Gray scale values of the pels in a general neighbourhood
around a given pel in an image to be corrected are sampled.
the samples must be far enough from the pel being corrected
and from each other that any data related information
content shows essentially no correlation between samples or
with the pel being corrected. The samples should be closely
enough spaced, however, that an accurate estimate of the low
spatial frequency shading effects can be obtained. As a
practical matter, samples should be taken at a radius
distance from the given pel greater than the character size
of ht text data and perhaps in the range of 10 to 20 pel
distances from that pel.
In a first embodiment of the invention a look-up table is
constructed whlch remaps the original image to a correction
image. Access is made to a look-up table which has as an
input a multibit digital data signal representing the gray
scale intensity value for one of a number of samples in the
selected neighbourhood around a given or current pel being
corrected. The output from
1'~83477
Y09-82-040X 19
this look-up is a signal representing the difference between
the input intensity value of the neighbouring pel being
sampled and the median previously calculated, except that if
the difference value determined exceeds the permitted range
R for background, as determined above, the corrective output
of the look-up table for that current pel is set to ~ero,
representing no correction made. In this embodiment of the
invention, further samples are taken in the selected
neighbourhood point by point around the current pel to be
corrected and the corrective outputs or correction terms
generated by the look-up table are summed. An average value
is obtained by dividing the sum of the correction terms by
the number of samples taken. This averaged correction value
is used to correct the current pel intensity value for
shading effects in shading correction filter 20. The
shading corrected intensity value of the current pel is
determined by the following equation:
X' = X + (M-A)
where X' is the corrected value of the current pel;
X is the original value of the current pel;
1~83477
YO9-82-040X 20
M is the median value; and
A is the average value of the neighbourhood background
determined above, 80 that (M-A) is the average correction
value for the neighbourhood sample.
Thi~ creates a correction image which is the difference
between the signal image and the median for all pixels in
the originals image with intensities within the background
image R. For all pixels in the original image at MIN or
below in intensity, the correction image is zero.
Since the method set forth with respect to this embodiment
determines an average background from a group of samples
around the current pel, if samples are taken in an all black
area such as off the edge of the frame. a skewed average
will result causing an erroneou~ correction. Therefore, for
pels in the band around the perimeter of the image, the
average ls taken including sample~ at the opposite edge of
the image as if the image had been wrapped around so that
the corresponding opposite edges were ad;acent. Although
~his technique i9 an improvement since, for example, shading
at the right
1~83477
Y09-82-040X 21
and left edges of an image may not be the same due to
external conditions.
Referring now to FIGS. 5.1 - 5.7, a second embodiment of the
present invention which deals with the edge problem will now
be described.
For purposes of explanation, a brief description of the
Grinnell GMR-270 image processor will be given. The
embodiment is not limited to his particular processor,
however. The Grinnell GMR-270 image processor has four
input look-up table (LUTs) each having an 8 bit input and 8
bit output. the eight input bits correspond to 256
different possible outputs. the 4 input LUTs are arranged
in pairs to provide two 16 bit inputs to an arithmetic logic
unit (ALU). The high order input tables provide the most
significant 8 bits and the low order input tables provide
the least significant 8 bits to their respective inputs. The
output of the ALU is 16 bits and a carry bit. The 10 least
significant bits of the ALU output can be fed to an output
LUT which produces an 8 bit output. This output table
therefore has 1024 input states, but only 256 unique output
states. The ALU carry bit can be written to overlay bit
planes. One of the overlays can be used to switch be-
1;~8347~
Y09-82-040X 22
tween two logical functions in the ALU. The other can be
directed to the most significant unput bit of the output LUT
in place of the normal processor output to that input bit of
the table.
Inputs to the image processor are obtained from several
image buffers. In the description below two buffers will be
used, on called the background image or reference (REF)
buffer, and the other called the duplicate image or
neighbourhood buffer. Panning circuitry in the GMR-270 can
be used to provide an offset between an image in the
reference buffer and an image in the neighbourhood buffer.
Note that an additional buffer is used to keep a copy of the
original image, as the images in both the neighbourhood
buffer and the reference buffer will be transformed during
the development of the shading correction.
Referring again to FIGS. 5.1 - 5.7, the first step i9 to
invert the image and parameter values if the background
colour is black. The sequence of steps to do this is shown
in FIG. 5.2. The "exclu~ive or' operation shown in FIG. 5.2
is equivalent to subtracting the value from 255. Inverting
1mages with blacX backgrounds is desirable for the
implementation in th- Grinnell GMR-270,
1'~83477
Y09-82-040X 23
since neighbourhood æamples which wouLd be taken from
outside the image boundaries are forced to black in this
implementation. Note that if the image is inverted before
the shading correction is performed, it is reinverted after
the shading correction in complete.
The six steps shown in FIg. 5.1 following the invert of the
black background images are described in greater detail in
FIGS. 5.3 through 5.7.
As is seen in FIG. 5.3, the upper and lower limits for
background intensity, LP and LN are calculated. a typical
gray scale signal may have 8 bits representing 256 discrete
gray scale levels ranging from white to black. the high
order input tables are cleared to give zero output for all
inputs, and a table is written to a low order input table to
convert the image from its original 8 bit form to a 5 bit
background intensity image. The reduction can conceptually
be divided into three steps. First, the intensity range of
the image is restricted to fall within the limits LN and LP
by clamping all pel intensities above LP to LP and all pel
intensities below LN to LN. Next, the minimum intensity is
reduced to zero by subtracting LN from the result of the
first step. Finally, the dynamic range of the resulting
1'~83477
Y09-82-040X 24
image is scaled to the interval O to 31 (5 bits) by
multiplying the intensity by 32/R. An example of a look-up
table which will do this sequence as a single operation is
shown in appended Table I. The reduction of the background
intensity range to 5 bit representation is required only
because of the signal path limitations of the particular
image processor being used in the GMR-270.
The next step is the development of a background image which
contains the maximum white value among a set of pels that
includes the current pel being corrected and a sample of
neighbourhood pels in a small region around the current pel.
FIG. 5.4 shows the steps required to set the LUTs for this
operation. The first two steps in FIG 5.4 shows the steps
required to set the LUTs for this operation. The first two
steps in FIG. 5.4 set the LUTs for the neighbourhood
background image input. Both tables have as input the 5 bit
neighbourhood image. Their effect is to multiply the input
image by 32. The high order LUT i~ shown in the top section
of appended Table V. Note that the first POORWHT entries
(from O to POORWHT-l) in the top section have the most
significant bit of the output set. The third step in FIG.
5.4 sets the he LUTs for the reference image input. The high
order table is zeroed
1283477
Y09-82-040X 25
except for the first POORWHT entries, where the table output
is set to hex 80. The ALU will add the outputs of these two
sets of input tables to create a composite 10 bit signal to
feed to the output LUT. If both inputs are less that
POORWHT, the addition of the two input signals in the ALU
will set the carry.
The fourth step in FIG. 5.4 creates the output LUT. The
function of this table is to compare the two 5 bit pel
values and choose the larger of the two. Table II
(appended) shows the look-up table transfer function for
selecting a maximum white intensity value from the two
inputs each of which have been mapped to five bit wide
signals.
Once the LUTs have been set, the small neighbourhood
maxwhite selection is done. FIG. 5.5 is a flow chart of the
steps. This maxwhite selection technique allow~ tho
sampling of a relatively large number of neighbourhood pels
ln very few steps. The desired neighbouring pel offset
values are broken into short lists, with three offsets per
list. For each offset in a given list a comparison is made
between the neighbourhood pel and the reference pel to
select the maximum white. The comparison i8 done for all
pels in the image and the
~X834'77
Y09-82-040X 26
result is stored in the reference image buffer, replacing
the existing reference image. When the list is complete,
the reference image contains the maximum white intensity
among the four values sampled, i.e., the reference value and
the three neighbourhood values. The reference image is then
copied to the neighbourhood buffer and, if more is to be
done, a new list is started. At the end of the second list
the maximum white has been obtained from a sample of sixteen
pelæ. In practice only two lists are processed, but if a
third list of three offsets were processed the maximum white
would be obtained from a sample of 64 pels. Note that after
each compari~on if both neighbourhood and reference
background images re in the POORWHT range the overlay bit i9
set.
A flow chart for the large neighbourhood maxwhite æelection
is shown in FIG. 5.6. The LUTs are the same and the basic
selection process is identical to the small neighbourhood
maxwhite selection, except that the offsets used are larger
and only reference image pels where the bit in the overlay
is set to flag a POORWHT background intensity are compared
with the neighbourhood pels. If after processing a given
oset, an acceptable maximum
~ .
1~834~7
Y09-82-040X 27
white value is obtained, the bit is cleared in the overlay
and the correction then remains unchanged for the reæt of
the large neighbourhood offset values. If an acceptable
maximum white value is not obtained, the process is
iteratively repeated until a predetermined limit of
iterations is achieved or an acceptable maximum white value
is found.
At the end of the large neighbourhood maxwhite selection the
maximum white estimate for each pel is the result of
comparison of up to eighty different pels - the original
reference pel and up to 79 neighbours in the vicinity of the
difference pel. The comparison i8 obtained, however, with a
relatively small number of processing steps. Note that for
pels near the edges and corners of the image th e sample
size i8 ~maller. All samples taken outside the image are
black, and therefore are re~ected by the maximum white
comparison process. However, since the sample size is still
large, the probability of a bad correction value near edges
and corners is extremely small.
After the maximum white e~timate is obtained, a filtering is
achieved by summing three nearest neighbour intensity values
with the current pel. The summation is
1283477
Y09-82-040X 28
replaced by a multiply by four at the edges of the image in
accordance with the overlay control described above. FIG.
5.7 contains the flow chart for this filtering operation.
In operation, a mask is set in two separate overlay planes
wherein the mask applies to the entire image is set to the
"off" condition and to the band of pels around the perimeter
of the image if set to the "on" condition. During normal
processing of pels of pels in the centre of the image, the
first overlay plane is set "off", causing the proce~sor to
sum the reference pel with the neighbourhood pel. For pels
in the edge band around the perimeter, the first overlay is
set "on", inhibiting summation and leaving the reference pel
intact for the first two summations over all pels in the
image.
The second overlay plane controls the output LUT operation.
When the third and final summation is made, the second
overlay is fod to the most significant bit of the processor
output LUT. If the overlay bit i8 set "off", a protrait of
the output LUT is ~elected which transfers the ALU output
without change to the reference buffer. If the overlay bit
is set "on", the multiply by four table shown in (appended)
Table III is selected, and the
1283477
Y09-82-040X 29
input is multiplied by four before storage in the reference
buffer. This technique greatly reduces the effect of edges
on this filtering operation.
The result of the steps described in FIG. 5.7 is a smooth
background intensity image having values from 0 to 127. The
summation process averages any noise produced by the maximum
white selection process.
As shown in FIG. 5.1, the background intensity image must
now be remapped to a correction value, using a table which
rescales the background image to the correct dynamic range
and shifts the zero correction point to correspond to the
median. Table IV (appended) gives an example of the low
order and high order input LUTs required for this remapping.
The background image as interpreted by this table, is added
to the original image. The result, clamped to the range
from 0 to 255, i8 the Rhading corrected image.
The nonlinear shading filter described above provides a
variable pass band filtering by enabling lower pass band
whenever the correction derived from earlier operation
indicates a failure of the correction together with
~'~83477
Y09-82-040X 30
noise averaging as a final step with lock out of the
averaging at the borders of the image.
It will be seen therefore that apparatus and methods have
been presented for simply and effectively correcting for
shading effects in video images particularly in graphics
form.
For convenience, a specific example of basic code that can
be used with the disclosed apparatus for histogram analysis
and shading correction is appended.
Y09-82-040X lZ834~7
TABLE I
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0202 0304 0505 0607 0808 O90a ObOb OcOd
OeOe OflO 1112 1213 1415 1516 1718 1819
lalb lblc ldle lelf lflf lflf lflf lflf
lflf lflf lflf lflf lflf lflf lflf lflf
lflf lflf lflf lflf lflf lflf lflf lflf
lflf lflf lflf lflf lflf lflf lflf lflf
lflf lflf lflf lflf lflf lflf lflf lflf
lflf lflf lflf lflf lflf lflf lflf lflf
lflf lflf lflf lflf lflf lflf lflf lflf
lflf lflf lffl lffl lflf lflf lflf lflf
3/
Y09-82-040X
lZ83477
TABLE II
0001 0203 0405 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0101 0203 0405 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0202 0203 0405 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0303 0303 0405 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0404 0404 0405 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0505 0505 0505 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0606 0606 0606 0607 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0707 0707 0707 0707 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0808 0808 0808 0808 0809 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
0909 0909 0909 0909 0909 OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
OaOa OaOa OaOa OaOa OaOa OaOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
ObOb ObOb ObOb ObOb ObOb ObOb OcOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
OcOc OcOc OcOc OcOc OcOc OcOc OcOc OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
OdOd OdOd OdOd OdOd OdOd OdOd OdOd OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
OeOe OeOe OeOe OeOe OeOe OeOe OeOe OeOf
1011 1213 1415 1617 1819 lalb lcld lelf
OfOf 00f OfOf OfOf OfO OfOf OfOf OfOf
1011 1213 1415 1617 1819 lalb lcld lelf
1010 1010 1010 1010 1010 1010 1010 1010
"~, ,
Y09-82-040X 1~83477
TABLE II (continued)
0111 1213 1415 1617 1819 lalb lcld lelf
1111 1111 1111 1111 1111 1111 1111 1111
1111 1213 141S 1617 1819 lalb lcld lelf
1212 1212 1212 1212 1212 1212 1212 1212
1212 1213 1415 1617 1819 lalb lcld lelf
1313 1313 1313 1313 1313 1313 1313 1313
1313 1313 1415 1617 1819 lalb lcld lelf
1414 1414 1414 1414 1414 1414 1414 1414
1414 1414 1415 1617 1819 lalb lcld lelf
1515 1515 1515 1515 1515 1515 1515 1515
1515 1515 1515 1617 1819 lalb lcld lelf
1616 1616 1616 1616 1616 1616 1616 1616
1616 1616 1616 1617 1819 lalb lcld lelf
1717 1717 1717 1717 1717 1717 1717 1717
1717 1717 1717 1717 1819 lalb lcld lelf
1818 1818 1818 1818 1818 1818 1818 1818
1818 1818 1818 1818 1819 lalb lcld lelf
1919 1919 1919 1919 1919 1919 1919 1919
1919 1919 1919 1919 1919 lalb lcld lelf
lala lala lala lala lala lala lala lala
lala lala lala lala lala lblc lcld lelf
'blb lblb lblb lblb lblb lblb lblb lblb
lblb lblb lblb lblb lblb lblb lcld lelf
lclc lclc lclc lclc lclc lclc lclc lclc
lclc lclc lclc lclc lclc lclc lcld lelf
ldld ldld ldld ldld ldld ldld ldld ldld
ldld ldld ldld ldld ldld ldld ldld lelf
lele lele lele lele lele lele lele lele
lele lele lele lele lele lele lele lelf
lfl 11f 11 11 11f lflf 11f lflf
lfl 11 11 11f lfl lfl lflf lflf
3~
YO9 - 82 - 040X
~83477
TABL13 I I I
0004 080c 1014 181c 2024 282c 3034 383c
4044 484c 5054 585c 6064 686c 7074 787c
8034 888c 9094 989c aOa4 a8ac bOb4 b8bc
cOc4 c8cc dOd4 d8dc eOe4 e8ec fOf4 f8fc
0104 O90c 1114 l91c 2124 292c 3134 393c
4144 494c 5154 595c 6164 696c 7174 797c
8184 898c 9194 999c ala4 a9ac blb4 b9bc
clc4 c9cc dld4 d9dc ele4 e9ec flf4 f9fc
0204 OaOc 1214 lalc 2224 2a2c 3234 3a3c
4244 4a4c 5254 5a5c 6204 6a6c 7274 7a7c
8234 8a8c 9294 9a9c a2a4 aaac b2b4 babc
c2c4 cacc d2d4 dadc e2e4 eaec f2f4 fafc
0304 ObOc 1314 lblc 2324 2b2c 3334 3b3c
4344 4b4c 5354 5b5c 6364 5b6c 7374 7b7c
8384 8b8c 9394 9b9c a3a4 abac b3b4 bbbc
c3c4 cbcc d3d4 dbdc e3e4 ebec f3f4 fbfc
3~
~r
Y09-82-040X lZ83477
TABLE IV
1414 1413 1313 1212 1211 1111 1010 lOOf
OfO OeOc OeOd OdOd OcOc OcOb ObOb OaOa
OaO9 0909 0808 0807 0707 0606 0605 0505
0404 0403 0303 0202 0201 0101 0000 0000
ffff fffe fefe fdfd fdfc fcfc fbfb fbfa
fafa 9f9 f9f8 f8f8 f7f7 f7f6 f6f6 f5f5
f5f4 f4f4 f3f3 f3f2 f2f2 flfl flfO fOfO
efef efee eeee eded edec eccc ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
ebeb ebeb ebeb ebeb ebeb ebeb ebeb ebeb
Sign Bit for Remapping to True Correction
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000 0000 0000 0000 0000
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfO OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
OfOf OfOf OfOf OfOf OfOf OfOf OfOf OfOf
Y09-82-040X
~283477
TABLE V
8080 8080 8080 8COO 0101 0101 0101 0101
0202 0202 0202 0202 0303 0303 0303 0303
0404 040g 0404 0404 0505 0505 0505 0505
0606 0606 0606 0606 0707 0707 0707 0707
0808 0808 0808 0808 0909 0909 0909 0909
OaOa OaOa OaOa OaOa ObOb ObOb ObOb ObOb
OcOc OcOc OcOc OcOc OdOd OdOd OdOd OdOd
OeOe OeOe OeOe OeOe OfOf OfOf OfOf OfOf
1010 1010 1010 1010 1111 1111 1111 1111
1212 1212 1212 1212 1313 1313 1313 1313
1414 1414 1414 1414 1515 1515 1515 1515
1616 1616 1616 1616 1717 1717 1717 1717
1818 1818 1818 1818 1919 1919 1919 1919
lala lala lala lala lblb lblb lblb lblb
lclc lclc lclc lclc ldld ldld ldld ldld
lele lele lele lele lflf lflf lflf lflf
0020 4060 808a cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0002 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
0020 4060 80aO cOeO 0020 4060 80aO cOeO
3G
Y09-82-040X
1;~83477
Preferred embodiment of histogram analysis and shading perception filter
pigmentstion for a GMR-270
function hstgr;
(process histogram of image to derive nalues for the maximum, minimum
and median. Determine the background colour of the image and the range
of the background colour of the image and the range of background values
which would probably be considered back in the sampling process for the
shading correcion. Histogram data is stored in cmdbuf. A 480x512 pixwl
image requires 18 bit precision for the histogram data. To avoid edge
effects, the histogram is obtained for a 472xS04 pixwl area centered in
the middle of hte 480x512 image. The high order 16 bits of the histo-
gram data re in the 1st 256 half words, hte low order 16 bits are in the
next 256 half words. A half word is defined to be 16 bits. All
varuables referenced in this code are half words in storage or 16 bit
registers.)
half hgh(base bl) hgl(base bl+512);
(First calculate the median. The 1st 256 words contain the high order
16 bits. Sum these, ignoring loss of precision of the least significant
2 bits)
nr=472 (height of data for histogram)
nc=504 (width of data for histogram)
tvarO=srl nr 1 (number or rows in image/2)
b2=expl srl nc 2 (number of columns in image/4)
b2=-expl * tvarO expl b2 (b2 is nc*nr/8)
bl=addr omdbuf (set to bottom of historgram data)
bsubl=bl (save bottom)
bl-+bl 510 (point to top of histogram data)
bO-O (zero sum)
be8in (sum over high from top down)
bO=+ bO expl hgh
if b2 lgt bO
bl=- bl 2
repeat
endif
endbe8in
if bl llt bsubl
bl=bsubl
endif
med=expl srl expl - bl expl bsubl
bl=addr obdbuf
bliml=bl
09-82-040X 1~834~
(zero total state cnt)
bO=O (use for low order part of sum) (get min
level - sum from bottom up)
begin
bO--~ bO expl hgh (sum high)
if bO llt 32
bl=~ bl 2
repeat
endif
endbegin
(now count down til 1st zero found)
begin
if hgl>O
if bl lgt bliml
bl=- bl 2
repeat
endif
endif
endbegin
min= srl expl - bl expl bliml 1
~now get max level - sum from top down)
bliml=~ bliml 510 (point to top of histogram data)
bl=bliml
bO=O (low order word of sum)
begin
bO=~ bO expl hgh (sum high)
if bO llt 32
bl=- bl 2
~repeat
endif
endbegin
(now go up til 1st zero encountered)
begin
if hgl>O
if bl llt bliml
if bl=~ bl 2
repeat
entif
endif
endbegin
max=expl srl expl - bl - expl bliml 510 1
dif=- med min (black dif)
lf sll dif 1 ~ - max med (if image is clearly white on black bkgnd)
color=O (white on black background)
else (image was prob black on white background)
(black dif must be twice white dif for clean graphics images)
color=l
dif=-max med (white dif)
endif
poorwht=2 . (init for clean graphics image)
lf color=l (white background)
dif=-max med (recalc in ca8e grayscale image)
'' 3~7
~, . .
Y09-82-040X
lX83477
if -med min ~ sll dif 1 (check for low dynamic range/gray
scale)
poorwht=7(low pass shading correction more often)
endif
if min > -med dif (really low dynamic range/gray scale)
poorwht=12(do low pass still more often)
endif
endif endfn
function deshade;
(Note: This implementation of the shading correction algorithm is
explicitly for the grinnell GMR-270 image processor. This image
procossor consists of a 16 bit ALU with two 16 bit input paths.
Data from image memorles is fed through four 8x8 lookup tables
(tables O and 1 feed one input lf the ~LU, and tables 2 and 3 feed
the other). The low order 10 bits of the output can be fed through
a lOx8 output table (table 4) if desired. The processor also
allows one to select between two different ALU funcions based on a
select bit from a one bit/pixel memory called overlay 8. Either
the most significant bit or the carry bit of the processor can be
written to overlay 8. For processor operations 3 image memories,
memO, mem6 and mem/, can be used. MemO can be panned to address
neighbouring plxels.
Correct for shading of the video imsge as follows:
1. Image is in memO,6 and 7 at start. All processor tables re 1:1,
but overlay B.8 i8 still set. If color=O, invert in 0.7. Write
look up talbe for med-video dif (5 bit output)
with min white=O, msx white=31, allowable white range med+/-dif.
Remsp im~ge to 5 bit dlf in 0.6. Reset talbes. Wrlte table4 to
select max white between two pixels.
2. Do neighbourhood convolution to select mixwh te for block 4 pixels.
Write overlay 8 wherever maxwhite values are both small. Final
step of convolution wlll leave overlay 8 set where maxwhite selec-
tion did not work form any neighbour tried. Copy maxwhite to memO
~nd repeat to get maxwhite for 16 pixels around current pixel.
Copy result to memO when convolution complete.
3. Do large neighbourhood convolution for pixels where the small
neighbourhood convolution gives a poor shading correction.
'poorwht' defines the number of white states tout of 32! which are
in the 'poor' category. 'poorwht' is set in hstgr; for clearly
black/white im~ges it is 2, for images which have some range of
grays it is 7, and for images which have the histogram of grayscale
image it is 12. Erase overlay 8 when doing the final imsge move to
set up for step 4.
4. Sum maxwhite for 4 pixels- 3 nearest neighbours and current pixel - -
except at edge of image. Feed result to lookup table to get shad-
ing correction.
5. Now correct imsge by adding correction to video.
Return result to mem),6. invert in O if needed.
-
3~
Y09-82-040X
lZ~33477
based bO
half bufptr bufptr2 bufptr4 bufptr6 bufptr8 bufptrlO
bufputl2 bufptrl4 bufptrl6 bufptrl8 bufptr20 bufptr22
bufptr24 bufptr26 bufptr28 bufptr30:
h~lf xd(b~se b2) yd(baseb2+12) md(base b2+24);
statlc
half xs(6) ys(6) ms(6) x1(6) yl(6) ml(6) sf(6) yf(6) mf(6);
init xs _2 _1 2 _4 1 5; (x,y,ms for maxwhite selection)
init ys 2 _2 1 _2 _S 3;
init ms O O 1 0 0 2; (copy 6 to O if ms=l, exit if ms=2)
init xl _28 _12 60 28 0 0
init yl 44 _52 _4 _32 0 0;
init ml O O O 1 0 0;
init xf 1 _1 0 0 0 0; (x,y,mf for final averaging)
init yf _l _l 1 0 0 0;
init mf O O 1 1 1 1; (exit when mf =0)
bO=addr omdbuf
bOst=bO
if color=O
tvarO= eor 255 max (note that inversion interchanges max and min)
med= eor 255 med (invert median, meaximum and minimum)
max= eor 255 min
min= tvarO
bufptr = hex aO10
bufptr2 = hex c800
bufptr4 = hex caOO (memO to 0,1,2,3)
bufptr6 = hex cc36 (clamp 2,3, invert 0,1)
bufptr8 = hex 8081 (enable 0,7)
bufptrlO= hex aOOO (write the inverted image to 0,7)
bufptrl2= hex aOOl (select vidoe driver)
bufptrl4= hex ca28 (invert image display to outputs a,c)
bO= +bO 16
entif
zerotbl 5 (tblO,2: zero hi8h order input tables)
shdtbl5 (tbll: 5 bit wite covering range med+/-dif)
bufptr = hex aOOl (select video driver per bitO only)
bufptr2 = hex c837 (video a from 7, b from 3, c from 7)
bufptr4 = hex aO10
bufptr6 = hex aO10
bufptr8 = hex ca30 (tbl4 on, carry to overlay)
bufptrlO = hex cc34 (memO only, thru tbl 1)
bufptrl2 = hex 8341 (enable memO,6,8,9)
bufptrl4 = hex cOOO (5 bit white to memO,6, clear overlays 8,9)
bO=+bO 16
(set up for convolution with nearest neighbours)
mtable 1 _3 (tblO; shift high order input down 3 bits)
setbits (set bits to flag poor white valueY)
mtable 2 5 (tbll: shift low order input up 5 bits)
zerotbl 4 (tbl2: zeroed)
~ 4~
Y09-82-040X
lZ83477
setbits (set bits to flag poor white values)
mxwhite4 (tbl4: table to select maximum white)
(tbl3 is still 1:1)
b2zb9
rtn=writgl bOst wxpl -bO bOst O rcadd (write instructions to Grinnell)
lf rtn-=O stop = sll color 1 1 endif
(Select max white for 5 bit states in memO, mem6 via convolution)
bO=bOst
b2=addr xs
begin (high-pass maxwhite selection)
bufptr = hex aOO9 (select zoom and pan)
bufptr2 = hex bOOO (point to x offset)
bufptr4 = bex cOOc (pan enabled, zoom=l, blanking at edge)
bufptr6 =~hex dOff xd (set x offset)
bufptr8 =+hex dOff (set y offset)
bufptrlO= hex aO10 (select processor)
bufptrl2= hex c8fO (memO to tbls 0,1; mem6 to tbls 2,3)
bufptrl4= hex ca30 (tbl4 on, carry to overlay)
bufptrl6= hex cc30 (add maxwhite to shifted maxwhite)
bufptrl8= hex 8140 (enable mem6, overlay 8)
bufptr20= hex cOOO (write to mem6, overlay 8)
bO= + bO 22
if md- o (repeat operation with new neighbour)
b2--+ b2 2
repeat
else (copy maxwhite in mem6 to memO)
bufptr = hex aO08 (select zoom and pan)
bufptr2 = hex cOOO (disable zoon amd pan)
bufptr4 = hex aO40 (enable digitizer 0)
bufptr6 = hex 8001 (select memO)
bufptr8 = hex c80f (input from 6, camera input zeroed)
bufptrlO= hex d200 (copy 6 to 0)
bO= + bO 12
if md=l
b2=~ b2 2
repeat (repeat unitl md=2)
endif
endbegin (leave loop hwen md=2)
b2=addr xl
begin (low-pass maxwhite selection)
bufptr = hex aO08 (select ~oon and pan)
bufptr2 = hex bOOO (point to x offset)
bufptr4 = hex cOOc (pan enabled, zoom=l, blanking at edge)
bufptr6 =+hex dOff xd (set x offset)
bufptr8 =+hex dOff yd (set y offset)
bufptrlO= hex aO10 (select processor)
bufptrl2= hex c8fO (memO to tbls 0,1; mem6 to tbls 2,3)
bufptrl4= hex call (tbll4 on, processor toggling on)
bufptrl6= hex cc31 (keep maxwhite as-is if overlay 8 not set)
bufptrl8= hex ce30 (add maxwhite to shifted maxwhite if ovly set)
bufptr20~ hex 8040 (enable mem6)
4/
YO9-82-040X
lZ83477
bufptr22= hex cOOO (write to mem6)
bO= + bO 24
if md= O (repeat operation with new neighbour)
b2=+ b2 2
repeat
endif
endbegin (leave loop when md-=O)
b2=b9
rtn=writgl bOst expl -bO bOst O rcadd (write instructions to Grinnell)
if rtn~=O stop - sll colour 1 1 endif
bO--bOst
zerobtl 5 (zero high order input tables)
(move image from mem6 to memO, clearing overlay 8 as well)
bufptr = hex ~008 (select zoom and pan)
bufptr2 = hex cOOO (disable zoom and pan)
bufptr4 = hex aOlO (select processor)
bufptr6 = hex c8ff (mem6 to tbis 0,1,2,3)
bufptr8 = hex ca30 ttbl4 on, carry to output)
bufptrlO= hex cc31 (add, clamp 0,1)
bufptrl2= hex 8101 (enable memO, overlay 8)
bufptrl4= hex cOOO (copy 6 to 0, clear overlay 8)
bO=+bOl6
tbll21 hex la (make tbls 1,3 1st 1/4 of tbl4 1:1)
shdtblx4 (3rd quadrant of tbl4 4x for border pixels)
(set overlay masks to block averaging of edge pixels)
bufptr = hex 8300 (select overlays 8,9)
bufptr2 = hex 1300 (select subchannels 8,9)
bufptr4 = hex 2800 (set normal write mode)
bufptr6 = hex 4800 (Ea-O)
bufptr8 = hex 51ff (Eb=lll)
bufptrlO= hex 6800 (La=O)
bufptrl2= hex 7400 (Lb=O, write bottom line of masks)
bufptrl4- hex 4800 (Ea=O)
bufptrl6= hex 51ff (Eb=511)
bufptrl8- hex 69df (Las479)
bufptr20= hex 7400 (Lb=O, write top line of masks)
bufptr22= hex 4800 (Ea=O)
bufptr24= hex SOOO (Eb=O)
bufptr26= hex 6800 (La=O)
bufptr28= hex 75df (Lb=479, write right side of masks)
bO-+bO 30
bufptr = hex 49ff tEa=5ll)
bufptr2 = hex 5000 (Eb=O)
bufptr4 = hex 6800 (La=O)
bufptr6 = hex 75df (Lb=479, wirte right side of masks)
bO=~bO 8
b2=addr xf
begin (average 4 maxwhite values, keep edge as-is)
bufptr = hex aO08 (select zoom and pan)
bufptr2 = hex bOOO (point to x offset)
bufptr4 = hex cOOc (pan enabled, zoom=l, blanking at edge)
bufptr6 =+hex doff xd (set x offset)
~L2
. . .
Y -82-040X
lZ83477
bufptr8 =+hex dOff yd (set y offset)
bufptrlO= hex aO10 (select processor)
bufptrl2= hex c8fO (memO to tbls 0,1; mem6 to tbls 2,3)
bufptrl4= hex cc30 (add if overlay not set)
bufptrl6= hex ce31 (2,3 only if overlay set no averaging)
lf md=O
bufptrl8= hex call (tbl4 on, proc tog on, tbl tog off)
bufptr20= hex 8040 (enable mem6)
bufptr22= hex cOOO (write to mem6, overlay 8)
bO=+bO 24
b2=+b2 2
repeat
else (sum of 4 maxwhite, normalize edges to 4x)
bufptrl8= hex ca35 (tbl4 on, proc & tbl tog on, carry to ovly)
bufptr20= hex 8340 (enable mem6, ovly 8.8 &9.9)
bufptr22= hex cOOO (write to mem6, clear overlays)
bO=+bO 24
endif
endbegin
(now rebuild max white via tbls 0,1. Original image in 7, shading
correction in 6. Tbl3 still 1:1, tbl 2 zeroed)
shdtblx (maxwhite toshsding correction in 0,1)
clip4 (tbl4 1:1 for real video lnput range)
bufptr = hex aO08 (sslect zoom and pan)
bufptr2 = hex cOOO (disable zoom and pan)
bufptr4 = hex aO10 (select processor)
bufptr6 = hex c8ff (mem6 to 0,1)
bufptr8 = hex cadO (mem7 to 2,3, tbl4 selected)
bufptrlO= hex cc30 (add 0,1 to 2,3)
bufptrl2= hex 80cl (memO,6,7 enabled)
bufptrl4= hex cOOO (write to memO,6; clear mem7)
bufptrl6= hex aOOl (select video driver) . -
bufptrl8= hex c804 (restore output a,c to memO)
bO= +bO 20
tbll21 hex Of (all input tables)
lf colour=O
tvarO = eor 255 max (note inversion interchanges max, min)
med= eor 255 med
max= oer 255 min
min= tvarO
bufptr = hex aO10 (select processor)
bufptr2 = hex c800 (memO to 0,1,2,3)
bufptr4 = hex caOO (deselect tbl4)
bufptr6 = hex cc36 ~clamp 2,3, invert 0,1)
bufptr8 = hex 8041 (enable memO,6)
bufptrlO= hex cOOO (write the inverted image to 0,6)bufptrl2= hex aOOl (select video driverO)
bufptrl4= hex caOO (resotre normal output from inverted)
bO--+bO 16
endif
b2=b9
rtn=writgl bOst expl -bO bOst O rcadd(srite instructions to Grlnnell)
43
.. ~ ~ . .
Y09-82-040X ~X83477
if rtn~=O stopO endif endfn (end of shading correction function)
function setbits:
('or' flrst poorwht table vslues with hex 80 to flag low intensities)
bsubO=bO (save instruction pointer)
bO=-bO 258 (back up to start of table)
bl=+bO expl poorwht (set limit for loop)
begin (set msbs for poorwht entries)
if bO llt bl
bytptr= or bytptr hex 80
bO ~+ bO 1
repeat
endif
endbegin
bO=bsubO (restore instruction pointer) endfn
function shdtblS;
(Generate table for medlan-video, limited to a maximum of dif and
scaled to fit in S bits. Offset table output such taht min white i8 ),
max white is 31. Generate in packed form.)
bufptr = hex aO10 (select processor)
bufptr2=hex c222 (write to table 1)
bufptr4=hex bOOO (zero address counter)
bufptr6-hex a210 (select byte unpacking too)
bufptr8-hex c480 (download 256 packed bytes)
bO=+ bO 10
ln=-med dif (min limit)
lp=+med dif (max limit)
if ln~O (zero output to video input of ln)
zero bO expl ln
bOS+ bO expl srl dif 1
endif
bl-expl srl dif 1
b2~0
b3sO
be8in
if b2 bl
blS+ bl expl dif (incr in steps of dif)
if b3 31 (limit b3 to S bits or less)
b3s+ b3 1
endif
endif
bytptr=expl b3
b2=~ b2 16 (incr in steps of 16. equiv to incr of ln by 1)
bOS+ bO 1
if ln<lp
ln=~ ln 1
repeat
endif
endbegin
4~
Y09-82-040X
12834~7
lf lp<255
flll bO 31 expl -255 lp (flll at bO with 31 for 255-lp bytes)
bO=+ bO expl -255 lp
else
bO =- bO expl -lp 255 (back up if any overshoot)
endif
bufptr = hex aO10 (deselect byte unpacking)
bO=+ bO 2 endfn
function mxwhite4;
(Wrlte 10 x 8 max white select table to processor table4.
The two white values are in hte low and high 5 bit sections of
the input, unsigned, with values O to 31, each.
Wrlte out in packed form.)
static
byte databl(32);
lnit databl
O 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31;
bufptr =hex aO10 (select processor)
bufptr2-hex c230 (secect table 4)
bufptr4=hex bOOO (zero-address counter)
bufptr6--hex a210 (select bytepacking)
bufptr8--hex c400 (download 512 bytes in packed form)
bO-+ bO 10
bsubO--bO
bl=bO
b2=addr datatbl
copy bO b2 32 (copy initial buffer)
bO=+bO 32
copy bO b2 32 (twice)
bO=+bO 32
b2GbsubO
copy bO b2 b4 (replicate 1st 64)
bO=+bO 64
copy bO b2 128 (replicate 1st 128)
bO=~bO 128
copy bO b2 256 (complete 1st 512 table entries)
bO=~bsubO 32 tback up bO to 1st fill point)
(bO points to fill srea in loop)
bl=l (counter for high order white)
begin (do 1st half of table4)
fill bO expl bl expl bl (fill in bl for bl entrles)
bO=~bO 32
bl=~ bl 1
if bl~l6
repeat
endif
endbegin
bufptr--hex c400 (download 256 words in packed form)
bO=~ bO 2
~5
Y09-82-040X
1~8~477
copy bO bsub 512 (copy 1st half of table to 2nd half)
begin (do 2nd half of table4)
fill bO expl bl expl bl (overwrite where needed)
bO=+ bO 32
if bl<31
bl=+ bl 1
repeat
endif
endbegin
bufptr = hex aO10 (deselect byte unpacking)
bO=+ bO 2 endfn
function shdtblx4;
(make 3rd quadrsnt of tbl4 4x)
bufptr = hex aO10 (select processor)
bufptr2 - hex c230 (select table 4 only)
bufptr4 = hex b200 (set address at upper half of table)
bufptr6 = hex a210 (select bytepacking)
bufptr8 = hex c480 (downlosd 256 bytes in apcked form)
bO=+bO 10
bsubO=+bO 256
bl-hex 0004 (~nit start of tablt)
b2-hex 0808
begin (4x tsble)
bufptr=expl bl
bO=+bO 2
if bO llt bsubO
bl=~bl expl b2
repest
endif
endbegin
bufptr=hex aO10 (deselect byte unpacking)
bO=+bO 2 endfn
function shdtblx;
(Gener8te tables for medi8n-video, expanding sum of four 5 bit
m8xwhite values to true difference (dif). High order table should be
Of for negative output. Output is added to video to correct for
shading. Generate in packed form.
Write to tables 0,1.)
bufptr = hex aO10 (select processor)
bufptr2 = hex c222 (select table 1)
bufptr4 = hex bOOO (zero address)
bufptr6 = hex a210 (select bytepacking)
bufptr8 = hex c480 (download 256 bytes in packed form)
bO=+ bO 10
bsubO~bO 128
bl=expl - sll dif 6 dif (init output of table at 63 x diff)
be8in (generate rest of 32 output states)
bO =~ bO 1
if bO llt bsubO
~G
Y09-82-040X
lX834'77
bl=- bl expl dif
repeat
endif
endbegin (last output is _dif)
fill bO expl _dif 128 (fill out rest of table with _dif)
bO=+ bO 128
bufptr = hex aO10 (select processor again)
bufptr2 = hex c221 (write totable 0)
bufptr4 = hex bOOO (zero address)
bufptr6 = hex a210 (select bytepacking)
bufptr8 = hex c480 (download 256 bytes in packed form)
bO=+ bO 10
zero bO 64 (first 64 output states are positive)
bO=+ bO 64
fill bO 15 192 (set sign bits for rest)
bO=+ bO 2 endfn
function mtable msk(h) s(h);
(write processor tsbles specified by msk - download in packed form)
(if to table 4, downlaod 512 bytes, rest take 256)
bufptr -hex aO10
if msk<O (if msk negative, create signed table)
msk=_msk
bufptr2=+hex c220 msk (write to tables set in msk)
bufptr4=hex bO80 (address conter-_128)
bl-_128
else
bl=O
bufptr2=+hex c220 msk (write to tables set in msk)
bufptr4=hex bOOO (address counter=O)
entif
bufptr6=hex a210 (select processor and byte unpacking)
bufptr8=hex c480 (download 128 packed words)
bsubO=+bO 266 (256 + init sequence length)
if msk=hex 10 (special case for table 4)
if ~<0 (expecting more than 8 bits, 90 extend divide table)
bl= expa sll expa bl l (double tbl length, so double bl)
if bl < O (signed divide)
bufptr4=hex b300 (start at _ 256 address)
endif
bufptr8=hex c400 (download 256 packed words)
bsubO=+bO 522 (512 + init sequence length)
endif
endif
bO=+ bO 10 (init sequence length)
if s~O (multiply)
begin
bytptr= expl and 255 sll expl bl s
bO=+ bO 1
if bO llt bsubO
~7
Y09-82-040X
1;~8347~
bl=+ bl 1
repeat
endif
endbegln
else (divide)
8-_8
begin
bytptr= expl and 255 srl expl bl s
bO=+ bO 1
lf bO llt bsubO
bl=+bl 1
repeat
endif
endbegin
endif
bufptr= hex zO10 (deselect byte unpacking)
bO=+ bO 2 endfn
function zeorbtl msk(h);
(zero the table defined by msk. Output in apcked form)
bufptr =hex aO10
bufptr2=+hex c220 msk (write to tables set in msk)
bufptr4-hex bOOO (zero address conter)
bufptr6-hex a210 (select byte unpacklng too)
bufptr8=hex c480 (download 256 bytes in packed form)
bO--+ bO 10
zero bO 256 (fill the table with zeros)
bO=+ bO 256
bufptr=hex aO10 (deselect byte unpacking mode)
bO=+ bO 2 endfn
function tbll21 msk(h);
(Write 1:1 processor tables specified by msk - download in packed
form) ~If to table 4, download to quadrants specified by hi8h order
byte of msk. the first nibble gives the startin8 address, the second
glves the final address. If both are zero, do the zeroth quadrant only.
the table loading must be contiguous. Thus, to download all four
quadrants of tbl4. msk should be hex 4010.)
bufptr = hex aO10 (select processor)
bufptr2=+hex c220 and ehx OOlf msk (write to tables set in msk)
bsubl=expa srl and msk hex fOOO 4 (end of table - may be zero)
msk=and hex OfOO msk (address of start of table)
bufptr4=hex a210 (select both processor and byte unpacking)
bufptr6=or ehx bOOO msk (starting table address)
bufptr8 = hex c480 (downlaod 128 packed words)
bO=~ bO 10 (init sequence length)
bsubO=+bO 256 (point to end of 1st sectlon)
bl=l
b2=hex 0202
be8in
bufptr= expl bl
bO=+ bO 2
Y09-82-040X
~283477
if bO llt bsubO
bl=+bl expl b2
repeat
endif
endbegin
msk=+msk hex 100 (point to address of current end of table)
if bsubl>expl msk (real end of table > current end of table)
bl=-bsubl expl msk (address differnece)
bl=+bl srl expl bl 7 (total number of bytes to copy)
movechar bO -bsubO 258 expl bl (replicatel:l table)
bO=+bO expl bl
endfif
bufptr = ehx aO10 (deselect bytepacking)
bO=+bO 2 endfn
function clip4;
(clip to real video in table4. Generate table4 in packed form)
tbll21 hex 10 (lst quadrant of table 4)
bufptr = hex a210 (select bytepacking)
bufptr2= hex c480 (start second quadrant)
bO=+ bO 256
bufptr-hex c400 (download 512 bytes in packed form)
bO=+ bO
fill bO hex 00 512 (clamp video below O to O)
bO=+ bO 512
bufptr=hex aO10 (deselect byte unpacking)
bO=+ bO 2 endfn
~7