Vision Starter
KitTM
User's Manual
Version 3.00
Ó Copyright 1999, 2002
Cogimatic
All Rights Reserved
Cogimatic
1436
Nighthawk Drive
Santa
Rosa, CA 95409
Phone: (707)539-7977
FAX: (707)539-7977
Email: support@cogimatic.com
WWW: http://www.cogimatic.com
Cogimatic
License Agreement
This is a legal agreement between you,
the end user, and Cogimatic. By using
this software you are agreeing to be bound by the terms of this Agreement. If you do not agree to the terms of this
Agreement, promptly return the unused software and the accompanying items to
the place you obtained them for a full refund.
License Grant
Cogimatic grants you a non-exclusive
license to make as many copies of the enclosed software (the
"SOFTWARE") as you need for back-up purposes. You may use this software on more than one
computer, provided there is no chance it will be used simultaneously on more
than one computer. You may not copy the
enclosed documentation for any purposes.
Redistributable Components
You have a royalty-free right to
reproduce and distribute the redistributable code files
"VISIONSK.DLL" and "VisionStarterKit.dll", provided that
you (a) distribute the files only in conjunction with and as a part of your
software application product; (b) agree to indemnify and hold Cogimatic
harmless from and against any claims or liabilities arising out of the use,
reproduction, or distribution of your software application product.
All Cogimatic libraries, source code,
redistributables, and other files remain Cogimatic's exclusive property.
LIMITED WARRANTY
NO WARRANTIES.
TO THE MAXIMUM EXTENT PERMITTED BY
APPLICABLE LAW, COGIMATIC EXPRESSLY DISCLAIMS ANY WARRANTY FOR THE
SOFTWARE. THE SOFTWARE AND ANY RELATED
DOCUMENTATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND EITHER
EXPRESS OR IMPLIED, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE
REMAINS WITH YOU.
NO LIABILITY FOR CONSEQUENTIAL DAMAGES.
TO THE MAXIMUM EXTENT PERMITTED BY
APPLICABLE LAW, IN NO EVENT SHALL COGIMATIC OR ITS SUPPLIERS BE LIABLE FOR ANY
DAMAGES WHATSOEVER (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF BUSINESS
PROFIT, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, OR ANY OTHER
PECUNIARY LOSS) ARISING OUT OF THE USE OR INABILITY TO USE THIS COGIMATIC
PRODUCT, EVEN IF COGIMATIC HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
Some states/jurisdictions do not allow
the exclusion or limitation of liability for consequential or incidental
damages, so the above limitation may not apply to you.
This agreement shall be governed by the
laws of the State of California and shall inure to the benefit of Cogimatic and
any successors, administrators, heirs and assigns. Any action or proceeding brought by either party against the
other arising out of or related to this agreement shall be brought only in a
STATE or FEDERAL COURT of competent jurisdiction located in San Francisco
County, California. The parties hereby
consent to in personam jurisdiction of said courts.
Information in this document is subject
to change without notice and does not represent a commitment on the part of
Cogimatic.
Borland, Borland C++, C++ Builder, OWL
and Delphi are trademarks of Borland International Corporation.
Microsoft, Microsoft Windows, Visual
Basic and MS DOS are trademarks of Microsoft Corporation.
Other trademarks referenced in this
publication are owned by their respective manufacturers.
TABLE OF CONTENTS
1. Getting Started............... 7
Minimum System
Requirements............... 7
Installation............... 7
Quick Results............... 7
Using the Demo Program............... 7
What’s new with this
release?............... 7
2. Introduction............... 9
Computer Vision............... 9
Image Processing with
the Vision Starter KitTM............... 9
Preview of the
functions offered............... 9
And more............... 10
Creating Applications
using the DLL............... 10
What else may be
needed............... 10
A reminder to make
sure the correct copy of visionsk.dll is present............... 11
3. General notes on
the DLL and class objects............... 12
What is a DLL............... 12
About the new .NET
DLL, ‘VisionStarterKit.dll’............... 12
About the main DLL,
‘visionsk.dll’............... 12
Creating And Using
Images............... 12
More Details on Image
Memory............... 13
4. Delphi class usage............... 14
Creation, Destruction
and Saving of Delphi Image Objects............... 14
Displaying Delphi
Image Objects............... 14
Manipulating Delphi
Image Objects............... 15
Delphi Image Class
Details............... 15
Gr8Image: 8 Bit
Grayscale Images............... 15
Gr32Image: 32 Bit
Grayscale Images............... 18
GrFImage: 32 Bit Float
(Single) Grayscale Images............... 19
RGBImage: 24 Bit Color
Images............... 19
5. C++ Image classes............... 22
Creation, Destruction
and Saving of C++ Image Objects............... 22
Displaying C++ Image
Objects............... 23
Manipulating C++ Image
Objects............... 25
C++ Image Class
Details............... 26
Gr8Image: 8-Bit
Grayscale Images............... 26
Gr32Image: 32-Bit
Grayscale Images............... 28
GrFImage: 32-Bit Float
Grayscale Images............... 28
RGBImage: 24-Bit Color
Images............... 29
6. Visual Basic Image
Classes............... 32
Setting up the VB
Environment............... 32
Creation, Destruction
and Saving of VB Image Objects............... 32
Displaying VB Image
Objects............... 33
Manipulating VB Image
Objects............... 34
VB Image Class Details............... 34
cGray8BitImage: 8-Bit
Grayscale Images............... 34
cGray32BitImage:
32-Bit Grayscale Images............... 38
cGrayFloatImage:
32-Bit Float Grayscale Images............... 38
cFFTImage: Float FFT
Images (written for VB)............... 39
RGB24BitImage: 24-Bit
Color Images............... 39
7. .NET Image Classes............... 43
Setting up the .NET
Environment............... 43
Creation, Destruction
and Saving of .NET Image Objects............... 43
Manipulating and
Displaying .NET Image Objects............... 44
.NET Image Class
Details............... 45
VSKImage: 8-Bit
Grayscale Images............... 45
Gray8BitImage: 8-Bit
Grayscale Images............... 45
Gray32BitImage: 32-Bit
Grayscale Images............... 48
GrayFloatImage: 32-Bit
Float Grayscale Images............... 49
RGBImage: 24-Bit Color
Images............... 50
8. Detailed DLL
Function Descriptions............... 53
Processors, Languages and
Calling Conventions............... 53
8 Bit, 16 Bit and
Floating Point Image Destruction............... 53
24 Bit RGB Image
Destruction............... 53
8 Bit Image Functions............... 53
32 Bit Image Functions............... 75
Float Image Functions............... 77
RGB Image Functions............... 81
Matrix Functions............... 94
A. Book References............... 96
Index............... 97
Chapter
1
IBM PC/AT or compatible running
Windows 98, NT 4.0 or higher. There
should be at least 2M disk space available, and at least 16M RAM is
recommended.
The Vision Starter KitTM (or VSK)
consists primarily of a 32-bit DLL file which is called by your program. To use the DLL, simply copy it to the
directory where your EXE file is located, or to the Windows directory.
To develop programs using the VSK,
first create a directory and copy the self-extracting file (named “unpack.exe”)
to this directory. Then execute the
file. The VSK interface code and
example programs for MSVC 5.0, Delphi and VB 5.0 will appear in separate sub
directories, ready to be copied into your own development directories.
For fast results it is recommended
that you copy the "quick" project of either language to your
development area, and load and run it from your development platform. This program loads an image and displays it,
and contains all the ingredients necessary to develop more advanced
applications using the VSK DLL.
The source code for the Demo program
is also provided as an example of a more involved program. The Demo exercises many functions in the
DLL, but often uses fixed values for passed-parameters in the calls. These fixed values can be replaced by
variables for rapid experimentation.
For example, the convolution filter masks could be altered, etc.
There are a few minor bug fixes in
this release, a new target ‘platform’, called ‘.NET’, and a few new functions
added to the DLL, which have also been added to some of the wrapper classes.
The .NET classes are described in their own chapter in this
manual. Briefly, this new programming
environment offers easier integration of code written in different languages.
In addition, there is a vast class library to speed up object-oriented
development. The VSK image classes have been created for this environment so
that whichever .NET language you prefer, it is likely that the VSK classes can
be imported and available immediately, since they are available as a .NET DLL.
This DLL named ‘VisionStarterKit.dll’, in turn calls the original
‘visionsk.dll’. When you deploy an application using these classes, you merely
copy both DLLs along with your EXE file into the same directory on the target
computer. No interaction with the Windows registry is necessary.
As for the new functions, there are two subject areas. The
first concerns Windows graphics resources and display settings. There is now
the ability to create an image based on a handle to a bitmap, or based on a
handle to a display context. These functions are meant for non-palletized
displays. That is, if your display settings are using only 256 colors or less,
then you are using a palette, and the functions won’t succeed. They are meant
for graphics environments where the selected bitmap has pixels whose colors are
fully specified. For example, 16-bit displays use RGB pixel values, where each
pixel holds 5 or 6 bit values for each color (red, green and blue).
The second area involves finding
bright points inside regions and returning them in an array, or finding bright
blobs inside regions and returning these in an array. These functions can be
useful for template matching. The result of a template match operation is a new
image with varying tones of gray. The brighter pixels represent a good match
between the original image and the template. The blob functions offer a
convenient way to find bright clusters, one cluster per ‘find’. By combining
the two operations, you can get a list of locations where the template was
found in the original image.
Chapter
2
Although it is assumed that the
reader is already familiar with image processing, a brief introduction seems in
order. Computer vision is a field which
uses computers to extract and analyze information from images in order to
identify (or measure) objects of interest.
Applications abound, including text and handwriting recognition,
astronomy, artificial intelligence and industrial quality control.
The image is often processed in
stages. For example let us consider an
application that reads dates on coins passed under a camera. The software accepts an image of the coin
and must determine the date of the coin.
The first stage might be a filter the to remove noise and correct for
uneven illumination. Next the image
might be scanned to find the location of the coin, by searching for a dark
circular shape. This region might then
be resized to some convenient dimensions, and then perhaps some spatial moments (or an FFT) would be calculated. These moments might be compared to a database for a match to
indicate the orientation of the coin and ensure that it was facing heads
up. With the orientation established
the date region could be extracted.
This new sub-image might then be converted to a line drawing and fed to
a text recognition function, which might be a highly customized algorithm.
Due to the large amount of
information contained in images, past approaches to vision systems often used
dedicated hardware for image processing.
But desktop computers have become powerful enough to perform many computer
vision tasks at reasonable speed.
The kit provides many of the fundamental image processing
functions commonly used in vision systems.
It is intended for programmers and others who program computers:
students, scientists, engineers and hobbyists.
The emphasis is on utility for vision applications. The functions provided are fully described
in the literature of the field. The kit
was designed to allow the developer to focus on higher level design issues, not
on tedious coding of standard algorithms.
The good news is that most of the standard algorithms, and even some
exotic ones are in the kit, and all for low price.
Convolution: the user can specify masks of up to 127 by 127 for both
integer and floating point convolutions.
There is a very fast 3 by 3 integer convolution, median filtering and a
fast mean filter.
Point
Operations: the usual point (brightness) operations, such as
thresholding, contrast, negatives, clipping, logarithms, bitwise and generic.
Cutting and
Pasting: rectangular chunks can be lifted from images and pasted to
other images at any point. Images can
also be cut and pasted to/from the Windows Clipboard.
Geometrical: translation with bilinear interpolation, rotation by any
floating point value, or by 90 degrees, fast zoom, flipping and polynomial
warping.
Morphological: erode, dilate, open, close and Laplacian of Gaussian edge
detection operator.
Profiles and
Histograms: line profiles of any length and direction; row, column and
overall image histograms; horizontal, and vertical projections.
Prepackaged
Shapes: generate images as ramps, mound, gaussian, cone, pyramid,
rectangle, circle, etc.
Image Pairwise
Combinations: linear, multiply pixels, divide, add, difference, use
max/min, and, or, etc.
Transforms: Fourier (FFT and IFFT) and Hough.
Template
Matching.
Blob Detection: Typically used with Template Matching, bright blobs are
detected, and their coordinates returned.
Hue Changing.
There are also floating point and
integer-based images with limited operations.
The integer size allows for averaging images together (for noise
removal), and the floating point allows for adding, multiplying images and
accurate FFT work.
There are some useful matrix
operations, such as multiplication, finding the inverse, finding the
pseudo-inverse and solving matrix equations.
Finally there is a vector form of the FFT (for one dimensional arrays, such as sound
clips).
Purchase of the Vision Starter Kit
entitles the purchaser to create and distribute applications which use the
DLL. The DLL itself can be distributed
with the application as long as its name is not changed (VISIONSK.DLL). However, information about the interface and
source code included in the Vision Starter Kit must not be distributed.
Programs using .NET will also need the VisionStarterKit.dll
along with VISIONSK.DLL. The VisionStarterKit.dll file is a C# “wrapper dll”
which converts the functionality of the original dll into a suite of .NET
classes, and is meant to work with VB.NET and C# applications. Other .NET
languages should also be able to use the DLL. As long as both dlls, along with
your application file (an exe) all occupy the same directory, the appication
should be able to load and call the dlls.
Currently the supported file format
is the Windows BMP format. This is a
standard image file format, but the developer may need to purchase a separate
file conversion program from another vendor to convert images if they are not
in a BMP format (also known as DIB format,
for Device Independent Bitmap, typically in a file with a .BMP extension).
On the other hand, most development
languages offer tools or controls to read and write image files in other
formats. For example, one might load a JPEG file into a VB Image control, and
create an RGBImage from its bitmap handle. With .NET, many different image file
formats are supported, and it is possible to create a Gray8Image directly from
an Image class instance. The .NET library loads and converts these files to the
familiar BMP format. See the VB.NET example program, which loads the full
variety of image formats this way.
The first release of visionsk.dll
was a 16-bit program, and used the cdecl calling convention.
Later, a preliminary version of the DLL emerged as part of the ImageRGB
control, an activeX component for color image processing. That version is 32-bits, but also uses the
cdecl calling convention. The current
version of visionsk.dll is 32-bit, but uses the more accessible stdcall calling convention.
Therefore, the earlier DLLs will not work with programs designed to call
the current product. So if an earlier
DLL is still located in your path, it may be found and loaded by Windows before
the correct, current version. Since
Windows uses the first DLL it finds, improper versions will fail to load
properly, causing the requesting application to fail. Care must be taken to ensure that only the correct DLL is visible
to the system.
Chapter
3
The term DLL stands for "Dynamic Link Library", meaning a
library of functions linked to your application (EXE) dynamically, not statically (as in the DOS world). Instead of packing the functions into your
EXE file at link time, only a list of them is stored. The functions instead live in the DLL, which is loaded by Windows
when your EXE asks for the DLL to be loaded.
Assuming that Windows finds the DLL as requested, your application can
now call these functions. In fact,
other applications can use these same functions simultaneously. The benefit is smaller EXE sizes, the
ability to have many applications running simultaneously all using the DLL, and
a compiler-independent function library which can be called by C, Pascal, Basic
and other languages and environments running under Windows.
This DLL is the class library meant
for users of Microsoft’s .NET environment.
Just like the VB, Delphi and C classes, this DLL has the wrapper classes
for .NET applications. As a .NET library, the code within the DLL is not
machine code, but is intermediate code which is converted to machine code at
run time by the .NET runtime environment. VB.NET, C# and C++.NET (managed C++)
applications make this DLL part of their application at design time, and
install it along with ‘visionsk.dll’ to the deployed directory, using the
so-called ‘xcopy install’ technique. This mode of deployment simply requires
that the executable and DLLs occupy the same directory, and doesn’t require
using the Windows Registry.
This DLL offers functions to create,
process, save and discard images. The
DLL by itself is a powerful tool, but those who use C++ or Delphi can use an
extra feature: simple image classes. The image classes are a layer of refinement
over the direct functions in the DLL.
The main advantage is that you don't have to hold onto the handle (see
the next section), since it is embedded within the image object. Even those who use the direct functions may
wish to study the "methods" of the classes, since they serve to
partition the functionality of the DLL in a clear way. For those who don't use the classes, the
next section applies.
The DLL has functions to create and
destroy images. The image itself is
actually a memory block which holds some bookkeeping flags and the actual pixel
data of the image. The image creation
functions allocate memory from the global heap and return a handle to this memory block, or 0 if there is an error. The other functions in the DLL operate on
the image through this handle, which is always passed as a parameter. The resulting image can be saved as a BMP
file or copied to the Clipboard and pasted into another application. When done with the image, there is a single
"Destroy" function which must be called to dispose of the
image. After this the handle should be
discarded, since it no longer refers to a valid memory block.
This is a quick note about those
"bookkeeping flags" mentioned previously. There is a type flag (byte, integer, or float) and a status
indicator for diagnostics, which has one value during the lifetime of the
object (memory block), but which gets marked as invalid just before the object
is destroyed (that is, its memory is freed).
In this way, a subsequent (erroneous) use of that global block
can be detected.
The memory pointed to by the handle
is checked briefly for integrity before any operation proceeds. The type flag
is checked for agreement with the function requested, and the status indicator
is checked for validity. The user can
deliberately check this integrity by calling the corresponding "isOkay" function (with the handle), which returns False only
if the block is invalid or the image height or width is zero.
Chapter
4
Image objects are declared as
variables and initialized with one of the 'Create' methods available.
This example loads Image1 from file and loads Image2 from Image1:
function
T(var Image1:Gr8Image;var Image2:Gr8Image):Boolean;
var
isSave : Boolean ;
begin
Image1.Free;
Image1:= Gr8Image.CreateFromDIBFile('X.DIB',StdWts);
Image2.Free ;
Image2:= Gr8Image.CreateFromGr8( Image1 );
isSave:= Image2.SaveToDIBFile('Y.DIB');
Result:= isSave;
end;
The Free method releases the current
buffer memory, and Create aquires a new appropriately sized buffer before
loading the data. If the image object
has not been 'created', its memory handle will be invalid and the DLL will
return a result of False from all functions passed this handle. Care must be taken to call Create only once
per object, since any existing handle will be lost and its memory not returned
to Windows' global heap.
To paint a gray image onto a device
context, first the device context must be loaded with a grayscale
palette. After this the Image can be
told to paint itself on the device context, by passing the context's
handle. The Delphi PaintBox is used in this example.
Note that the functions 'makeGrayPalette' and 'getGrayPaletteHandle' are already available in the 'GR8.PAS' interface unit.
(The function makeGrayPalette creates a Windows palette when the unit
loads, and the function getGrayPaletteHandle makes this handle available.)
procedure
TForm1.PaintBox1Paint(Sender: TObject);
var
hdc : THandle ;
hPal: HPalette ;
hOldPal : HPalette ;
begin
hdc := PaintBox1.Canvas.Handle ;
hPal:= getGrayPaletteHandle ;
hOldPal := SelectPalette( hdc, hPal, False ) ;
RealizePalette( hdc ) ;
ImageResult.PaintOnDC( hDC, 0, 0, 0, 0 ) ;
hOldPal := SelectPalette( hdc, hOldPal,
True ) ;
end;
The PaintOnDC method parameters specify
to paint to destination point (x,y)=(0,0) from source point (x,y)=(0,0). While it is also possible to copy the image
to a Delphi Bitmap object, and assign this to a TPicture, the PaintBox simplifies memory usage and reduces the
number of constructs to keep track of.
Here is a simple example applying a
Mean Filter to an image object.
Note that the mask width and height must be odd numbers, as with the
convolution functions. Also, since some
operations take time (especially with large images), it's best to use an
hourglass during processing to indicate a busy state to the user.
procedure
TForm1.Smooth1Click(Sender: TObject);
var
isOkay : Boolean ;
ht,wd
: Integer ;
begin
isModified := True ;
ht:= 3 ;
wd:= 5 ;
Screen.Cursor := crHourglass ;
isOkay := ImageResult.FastMeanFilter(wd, ht) ;
Screen.Cursor := crDefault ;
PaintBox1.Invalidate ;
if not isOkay then
MessageDlg('Filter Error.', mtWarning,
[mbOK], 0);
end;
What follows is the class interface
for the 8, 16 and 32 bit (float) grayscale image classes. The methods are almost identical with their
counterparts in the DLL functions described in detail in chapter 6. Please see that chapter for more details.
Gr8Image
= class ;
Gr32Image=
class ;
GrFImage
= class ;
Gr8Image
= class( TObject )
private
hGr8 : THandle ;
Gr8Image = class( TObject )
private
hGr8
: THandle ;
public
constructor
Create ;
constructor
CreateFromGr8( Image: Gr8Image ) ;
constructor
CreateFromGr32( Image: Gr32Image ) ;
constructor
CreateFromGrF( Image: GrFImage ) ;
constructor
CreateBlank( width: Integer; height: Integer ) ;
constructor
CreateFromBM( hBm: HBitmap; pEntry: PTPaletteEntry ;
numEntry:
Integer; wts : ColorWts ) ;
constructor
CreateFromHBMHPAL( hBm: HBitmap; hPal: Hpalette;
wts
: ColorWts ) ;
constructor
CreateFromDIBPtr( pDib: HPByte; lSize: LongInt;
wts
: ColorWts ) ;
constructor
CreateFromDIBHnd( hDIB: THandle; wts : ColorWts ) ;
constructor
CreateFromDIBFile( FileName: String; wts : ColorWts );
destructor Destroy ; override ;
procedure Free ;
function
GetRequiredDIBSize : LongInt ;
function
SaveToDIBPtr( pDib: HPByte; lSize: LongInt ) : Boolean ;
function
SaveToDIBHnd( hDIB: THandle ) : Boolean ;
function
SaveToDIBFile( FileName: String ) : Boolean ;
function
Handle : THandle ;
function
IsOkay : Boolean ;
function
Width : Integer ;
function
Height : Integer ;
function
CopyFromGr8( srceImage : Gr8Image ) : Boolean ;
function
CopyFromGr32( srceImage : Gr32Image ) : Boolean ;
function
CopyFromGrF( srceImage : GrFImage ) : Boolean ;
function
PasteToXYFromArray( pSrceBits: HPByte; x: Integer;
y:
Integer; width: Integer; height: Integer ):
Boolean;
functin
PasteToXYFrom00( SrceImage: Gr8Image;
x:
Integer; y: Integer ) : Boolean ;
function
PasteToArrayFromXY( pDestBits: HPByte; x: Integer;
y:
Integer; width: Integer; height: Integer;
maxBytes:
LongInt ) : Boolean ;
function
PasteTo00FromXY( SrceImage: Gr8Image; x: Integer;
y:
Integer ) : Boolean ;
function
StretchOnDC( hDC: THDC; destX: Integer; destY: Integer;
destW:
Integer; destH: Integer; srceX: Integer;
srceY:
Integer; srceW: Integer; srceH: Integer ) :
Boolean ;
function
PaintOnDC( hDC: THDC; destX: Integer; destY: Integer;
srceX:
Integer; srceY: Integer) : Boolean ;
function
GetMinMax( var minVal: Byte; var maxVal: Byte ):Boolean;
function
EqualizeHist : Boolean ;
function
GetHist( var Hist: HistArray ) : Boolean ;
function
GetRowHist( var Hist: HistArray; row: Integer ):Boolean;
function
GetColHist( var Hist: HistArray; col: Integer ):Boolean ;
function
ConvolveInt3x3( iMatrix: IntArray3x3 ) : Boolean ;
function
ConvolveFloat3x3( sMatrix: SngArray3x3 ) : Boolean ;
function
ConvolveIntNxM( pMatrix: PInteger;
wd:
Integer; ht: Integer ) : Boolean ;
function
ConvolveFloatNxM( pMatrix: PSingle;
wd:
Integer; ht: Integer) : Boolean ;
function
CalcFFT( RealFFT: Gr8Image; ImagFFT: Gr8Image;
var
qReal: Quantize; var qImag: Quantize) : Boolean ;
function
CalcIFFT( RealFFT: Gr8Image; ImagFFT: Gr8Image;
var
qReal: Quantize; var qImag: Quantize) : Boolean ;
function
CalcFFTfull( RealFFT: Gr8Image; ImagFFT: Gr8Image;
FreqFFT:
Gr8Image; PhaseFFT: Gr8Image;
var
qReal: Quantize;var qImag : Quantize;
var
qFreq: Quantize;var qPhase: Quantize):Boolean;
function
MedianFilter( maskWd: Integer; maskHt: Integer ) :
Boolean
;
function
MeanFilter( maskWd: Integer; maskHt: Integer):Boolean ;
function
FastMeanFilter( maskWd: Integer; maskHt: Integer ) :
Boolean
;
function
InvGradFilter( maskWd: Integer; maskHt: Integer ):
Boolean
;
function
MomentsM( var m: DblArray4x4 ) : Boolean ;
function
MomentsUM( var u: DblArray4x4; var m: DblArray4x4 ):
Boolean
;
function
MomentsVUM( var v: DblArray4x4; var u: DblArray4x4;
var
m: DblArray4x4 ) : Boolean ;
function
MomentsHVUM( var h: DblArray7; var v: DblArray4x4;
var
u: DblArray4x4; var m: DblArray4x4 ) : Boolean ;
function
RemapBrightness( ConversionTable: BytArray256):Boolean ;
function
Threshold( value: Byte ) : Boolean ;
function
LinearCombineInt( SrceImage: Gr8Image; x: Integer;
y:
Integer; w1: Integer; w2: Integer;
scale:
Integer; offset: Integer;
mustABSVal:
Boolean ) : Boolean ;
function
LinearCombineFloat( SrceImage: Gr8Image; x: Integer;
y:
Integer; w1: Single; w2: Single;
offset: Single;
mustABSVal:
Boolean ) : Boolean ;
function
ResizeCopyFrom( SourceImage: Gr8Image ) : Boolean ;
function
Erase( background: Byte ) : Boolean ;
function
FlipX : Boolean ;
function
FlipY : Boolean ;
function
TranslateInt( shiftX: Integer; shiftY: Integer;
bkgnd:
Byte ): Boolean ;
function
TranslateFloat( shiftX: Single; shiftY: Single;
bkgnd:
Byte): Boolean ;
function
Rescale( scaleX: Single; scaleY: Single; bkgnd: Byte):
Boolean;
function
TranslateThenScale( shiftX: Single; shiftY: Single;
scaleX:
Single; scaleY: Single;bkgnd: Byte):Boolean ;
function
Rotate90( numTimes: Integer) : Boolean ;
function
Rotate( numDegrees: Single; bkgnd: Byte) : Boolean ;
function
PolyWarpFromCoefs( pXCoefs: Array of Single;
pYCoefs:
Array of Single;
numCoefs:
Integer; bkgnd: Byte ) : Boolean ;
function
PolyWarpFromPoints( pSrcePts: Array of PairSingle;
pDestPts:
Array of PairSingle;
numPts:
Integer; degree: Integer;
var
isSingular: Boolean; bkgnd: Byte) : Boolean ;
function
GetPixelValue( var value: Byte; x: Integer;
y:Integer):Boolean;
function
SetPixelValue( value: Byte; x: Integer; y: Integer):
Boolean
;
function
CalcPixelValue( var value: Single; x: Single; y: Single;
bkgnd:
Byte) : Boolean ;
function
GetLineProfile( pLine: PByte; num: Integer;
x0:
Single; y0: Single; x1: Single; y1: Single;
mustScale:
Boolean; bkgnd: Byte) : Boolean ;
function
GetHProjection( pProj: PByte; num: Integer ) : Boolean ;
function
GetVProjection( pProj: PByte; num: Integer ) : Boolean ;
function
GetGoodThreshold( var value: Byte ) : Boolean ;
function
Segment : Boolean ;
function
Erode : Boolean ;
function
Dilate : Boolean ;
function
Close : Boolean ;
function
Open : Boolean ;
function
TemplateMatch( TemplateImage: Gr8Image ) : Boolean ;
function
HoughTransformTo(DestImage: Gr8Image;
threshold:
Byte ) : Boolean ;
function
GetEdgesLOGI( sigma: Single; Threshold: Integer ) :
Boolean
;
function
GetEdgesLOGF( sigma: Single; Threshold: Integer ) :
Boolean
;
function
Slice( a: Byte; b: Byte ) : Boolean ;
function
LogRange : Boolean ;
function
ALogRange : Boolean ;
function
Contrast( a: Byte; b: Byte; ay:Byte; by:Byte ) : Boolean;
function
ClipNoise( a: Byte; b: Byte ) : Boolean ;
function
Negative : Boolean ;
function
BitInverse : Boolean ;
function
Operate( operand: Byte; operation: Integer ) : Boolean ;
function
CombineWith( OtherImage: Gr8Image; operation:
Integer):Boolean;
function
MakeShape( shapeType: Integer ) : Boolean ;
{-----------------------
Functions NOT in DLL -------------------}
function
CopyToClipboard : Boolean ;
end
Gr32Image = class( TObject )
private
hGr32
: THandle ;
public
constructor
Create ;
constructor
CreateFromGr8( Image: Gr8Image ) ;
constructor
CreateFromGr32( Image: Gr32Image ) ;
constructor
CreateFromGrF( Image: GrFImage ) ;
constructor
CreateBlank( width: Integer; height: Integer )
;
destructor Destroy ; override ;
procedure Free ;
function
Handle : THandle ;
function
IsOkay : Boolean ;
function
Width : Integer ;
function
Height : Integer ;
function
CopyFromGr8( srceImage : Gr8Image ) : Boolean ;
function
CopyFromGr32( srceImage : Gr32Image ) : Boolean ;
function
CopyFromGrF( srceImage : GrFImage ) : Boolean ;
function
AddConst( a : Integer ) : Boolean ;
function
Add( otherImage : Gr32Image ) : Boolean ;
function
MultConst( a : Integer ) : Boolean ;
function
MultConstF( a : Single ) : Boolean ;
function
GetMinMax( var minVal: Integer; var maxVal: Integer )
:
Boolean ;
function
GetDataPtr : HPInteger ;
end ;
GrFImage = class( TObject )
private
hGrF
: THandle ;
public
constructor
Create ;
constructor
CreateFromGr8( Image: Gr8Image ) ;
constructor
CreateFromGr32( Image: Gr32Image ) ;
constructor
CreateFromGrF( Image: GrFImage ) ;
constructor
CreateBlank( width: Integer; height: Integer )
;
destructor Destroy ; override ;
procedure Free ;
function
Handle : THandle ;
function
IsOkay : Boolean ;
function
Width : Integer ;
function
Height : Integer ;
function
CopyFromGr8( srceImage : Gr8Image ) : Boolean ;
function
CopyFromGr32( srceImage : Gr32Image ) : Boolean ;
function
CopyFromGrF( srceImage : GrFImage ) : Boolean ;
function
AddConst( a : Single ) : Boolean ;
function
Add( otherImage : GrFImage ) : Boolean ;
function
MultConst( a : Single ) : Boolean ;
function
Mult( otherImage: GrFImage ) : Boolean ;
function
ScaleAndOffset( scale : Single; offset : Single ):Boolean ;
function
GetMinMax( var minVal: Single; var maxVal: Single):Boolean ;
function
GetDataPtr : HPSingle ;
function
GetPixelValue( var value: Single; x: Integer;
y:Integer):Boolean;
function
SetPixelValue( value: Single; x: Integer; y: Integer):
Boolean
;
function
CalcFFT( var Imaginary: GrFImage; isReordering : Boolean):
Boolean ;
function
CalcIFFT( var Imaginary: GrFImage; isReordering : Boolean):
Boolean
;
function
ConvertToFreqAndPhase( var ImaginaryFFT: GrFImage ):
Boolean
;
function
ConvertFromFreqAndPhase( var PhaseFFT : GrFImage ):
Boolean
;
end ;
RGBImage = class( TObject )
private
hRGBImage
: hRGB ;
public
constructor
Create ;
constructor
CreateBlank( width: Integer; height: Integer ) ;
constructor
CreateFromRGB( Image: RGBImage) ;
constructor
CreateFromGr8( Image: Gr8Image ) ;
constructor
CreateFromBM( hBm: HBitmap; pEntry: PTPaletteEntry;
numEntry:
Integer ) ;
constructor
CreateFromHBMHPAL( hBm: HBitmap; hPal: HPalette ) ;
constructor
CreateFromDIBPtr( pDib: HPByte; lSize: LongInt ) ;
constructor
CreateFromDIBHnd( hDIB: THandle ) ;
constructor
CreateFromDIBFile( FileName: String ) ;
destructor Destroy ; override ;
procedure Free ;
function
Create8BitPalette : HPalette ;
function
GetRequiredDIBSize : LongInt ;
function
SaveToDIBPtr( pDib: HPByte; lSize: LongInt ) : Boolean ;
function
SaveToDIBHnd( hDIB: THandle ) : Boolean ;
function
SaveToDIBFile( FileName: String ) : Boolean ;
function
GetRequired8BitDIBSize : LongInt ;
function
SaveTo8BitDIBPtr( pDib: HPByte; lSize: LongInt ) : Boolean ;
function
SaveTo8BitDIBHnd( hDIB: THandle ) : Boolean ;
function
SaveTo8BitDIBFile( FileName: String ) : Boolean ;
function
Handle : THandle ;
function
IsOkay : Boolean ;
function
Width : Integer ;
function
Height : Integer ;
function
CopyFromGr8( srceImage : Gr8Image ) : Boolean ;
function
PasteToXYFrom00( SrceImage : RGBImage;
x:
Integer; y: Integer ) : Boolean ;
function
PasteTo00FromXY( SrceImage: RGBImage;
x:
Integer; y: Integer ) : Boolean ;
function
PasteToGray00FromXY( DestImage: Gr8Image;
x:
Integer; y: Integer; wts : ColorWts ) : Boolean ;
function
StretchOnDC( hDC: THDC; destX: Integer; destY: Integer;
destW:
Integer; destH: Integer;
srceX:
Integer; srceY: Integer;
srceW:
Integer; srceH: Integer ) : Boolean ;
function
PaintOnDC( hDC: THDC; destX: Integer; destY: Integer;
srceX:
Integer; srceY: Integer) : Boolean ;
function
GetMinMax( var minVal: RGB_Value; var maxVal: RGB_Value ):
Boolean
;
function
EqualizeHist : Boolean ;
function
ConvolveInt3x3( iMatrix: IntArray3x3 ) : Boolean ;
function
ConvolveFloat3x3( sMatrix: SngArray3x3 ) : Boolean ;
function
ConvolveIntNxM(pMatrix: PInteger;
wd:
Integer; ht: Integer ) : Boolean ;
function
ConvolveFloatNxM( pMatrix: Psingle; wd: Integer;
ht:
Integer): Boolean ;
function
MedianFilter( maskWd: Integer; maskHt: Integer ) : Boolean ;
function
MeanFilter( maskWd: Integer; maskHt: Integer
) : Boolean ;
function
FastMeanFilter( maskWd: Integer; maskHt: Integer):Boolean ;
function
InvGradFilter( maskWd: Integer; maskHt: Integer):Boolean ;
function
LinearCombineInt( SrceImage: RGBImage; x: Integer;
y:Integer;
w1: Integer; w2: Integer;
scale:
Integer; offset: Integer;
mustABSVal:
Boolean ) : Boolean ;
function
LinearCombineFloat( SrceImage: RGBImage; x: Integer;
y:
Integer;w1: Single; w2: Single; offset: Single;
mustABSVal:
Boolean ) : Boolean ;
function
ResizeCopyFrom( SourceImage: RGBImage) : Boolean ;
function
Erase( background: RGB_Value ) : Boolean ;
function
FlipX : Boolean ;
function
FlipY : Boolean ;
function
TranslateInt( shiftX: Integer; shiftY: Integer;
bkgnd:
RGB_Value ): Boolean ;
function
TranslateFloat( shiftX: Single; shiftY: Single;
bkgnd:
RGB_Value): Boolean ;
function
Rescale( scaleX: Single; scaleY: Single; bkgnd: RGB_Value):
Boolean;
function
TranslateThenScale( shiftX: Single; shiftY: Single;
scaleX:
Single; scaleY: Single; bkgnd: RGB_Value ) :
Boolean
;
function
Rotate90( numTimes: Integer ) : Boolean ;
function
Rotate( numDegrees: Single; bkgnd: RGB_Value) : Boolean ;
function
PolyWarpFromCoefs( pXCoefs: Array of Single;
pYCoefs:
Array of Single;
numCoefs: Integer; bkgnd: RGB_Value ) :
Boolean ;
function
PolyWarpFromPoints( pSrcePts: Array of PairSingle;
pDestPts:
Array of PairSingle;
numPts:
Integer; degree: Integer;
var
isSingular: Boolean;
bkgnd:
RGB_Value) : Boolean ;
function
GetPixelValue( var value: RGB_Value; x: Integer;
y:Integer):Boolean;
function
SetPixelValue( value: RGB_Value; x: Integer; y: Integer):
Boolean
;
function
CalcPixelValue( var value: RGB_Value; x: Single; y: Single;
bkgnd:
RGB_Value) : Boolean ;
function
TemplateMatch( TemplateImage: RGBImage) : Boolean ;
function
Contrast( a:Byte; b:Byte; ay:Byte; by:Byte ): Boolean;
function
Negative : Boolean ;
function
Operate( operand: RGB_Value; operation: Integer):Boolean ;
function
CombineWith( OtherImage: RGBImage; operation: Integer ):
Boolean
;
function
ConvertToHSI: Boolean ;
function
ConvertToRGB: Boolean ;
function
ChangeHueByDegrees( numDegrees: Single ) : Boolean ;
{-----------------------
Functions NOT in DLL ---------------------}
function
CopyToClipboard : Boolean ;
end ;
Chapter
5
The MSVC sample program uses the
“archive” concept, in keeping with the MSVC Document/View architecture. Although the file load and save methods
would be easier to use, the following code does illustrate loading and saving
with buffers, adhering to an archive design.
void
CRGBDemoDoc::Serialize(CArchive& ar)
{
BYTE * pBuf=NULL ;
if (ar.IsStoring())
{
//
TODO: add storing code here
int
len = m_pMyImage->GetRequiredDIBFileSize();
pBuf
= new BYTE[len];
BOOL
isOk = (pBuf != NULL);
if
( isOk )
isOk = m_pMyImage->SaveToDIBFileBuffer(
pBuf, len );
if
( isOk )
ar.Write( pBuf, len);
else
{
CString badWrMsg = _T("Failed to save
image!");
AfxMessageBox( badWrMsg );
}
}
else
{
//
TODO: add loading code here
BOOL isReadOk = FALSE ;
const
CFile* fp = ar.GetFile();
long
len = fp->GetLength() ;
pBuf
= new BYTE[len];
if
( pBuf != NULL )
{
ar.Read( pBuf, len);
RGBImage *pTemp = new RGBImage(pBuf, len,
TRUE);
if ( pTemp != NULL )
if
( pTemp->IsOkay() )
{
isReadOk =
TRUE ;
delete m_pMyImage ;
m_pMyImage = pTemp ;
}
}
if
( ! isReadOk )
{
CString badRdMsg = _T("Failed to load
image!");
AfxMessageBox( badRdMsg );
}
}
if ( pBuf != NULL )
delete [] pBuf ;
}
The following sample program was
presented with the Borland C++ version 4.53 OWL class library, and should work for 32-bit
versions now. Other libraries should be
similar. C++ Image objects are declared
using a variety of constructors. This
example loads temp from file and copies Image1 from temp:
BOOL
ImageLoadSave(Gr8Image & Image1, const char
*pFilename)
{
Gr8Image temp(
pFilename );
BOOL isOkay
= temp.IsOkay();
if ( isOkay )
isOkay
= temp.SaveToDIBFile( "Y.DIB" );
if ( isOkay )
{
Image1 = temp;
isOkay
= Image1.IsOkay();
}
return( isOkay );
}
The image object 'temp' uses one of
its constructors to load itself from the named file. The constructor uses default color weights
(Red=.3, Green=.59, Blue=.11) since the weights parameter is not specified in
the call. Temp then saves itself to the
DIB file 'Y.DIB'. The
assignment operator, '=', first releases the buffer of Image1, and then creates
a new appropriately sized buffer before copying its data from temp. Temp's destructor will release its buffer
when temp goes out of scope.
The image paints itself in the
OnDraw function of MFC, as follows.
The code uses a color image, and
it is assumed that the palette currently selected into the display context (DC)
has enough colors to render the image appropriately.
void
CRGBDemoView::OnDraw(CDC* pDC)
{
CRGBDemoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CRect rect;
GetClientRect( &rect ) ;
RGBImage* pImage = pDoc->getMyImage();
if ( pImage != NULL )
{
if
( m_isViewStretch )
pImage->StretchOnDC(*pDC, 0,0,
rect.Width(),rect.Height(), 0, 0,
pImage->Width(), pImage->Height());
else
pImage->PaintOnDC(*pDC, 0,0, 0,0);
}
}
Recently PC graphics cards are able
to render many colors simultaneously, eliminating the need for palette
manipulation. For computers with less
powerful graphics cards, the following code sample from the 16-bit version of
the kit may be helpful. To paint a gray
image onto such a device context, first the device context must be loaded with
a grayscale palette. The following code
and discussion is from the previous version of the kit, and worked with 16-bit
Borland C++, version 4.53, but should also work with version 5.0 and perhaps
with C++ Builder.
The
function 'loadGrayPalette()' creates a grayscale palette on the fly, and selects and
realizes it into the DC. After this the
Image can be told to paint itself on the device context, by passing the
context's handle. After painting is
complete, the original palette is reselected into the DC, and the temporary
palette destroyed. A more efficient
technique would create a grayscale palette for the duration of the application,
as with the Delphi sample program.
void
loadGrayPalette( TDC & dc )
{
int i;
// Gray Palette with 64 grays + current system colors
PALETTEENTRY pEs[256];
for ( i=0; i<64; ++i )
{
pEs[i].peRed = i*4;
pEs[i].peGreen = i*4;
pEs[i].peBlue = i*4;
pEs[i].peFlags = 0;
}
TPalette
memPalette( pEs, 64 );
dc.SelectObject( memPalette );
dc.RealizePalette();
}
void
TDrawWindow::EvPaint()
{
TPaintDC dc(HWindow);
// use Gray Palette with 64 grays + current
system colors
loadGrayPalette( dc ) ;
//display on display context
ImageResult.PaintOnDC( HDC(dc),0,0,0,0);
dc.RestorePalette();
}
The PaintOnDC method parameters
specify to paint to destination point (x,y)=(0,0) from source point
(x,y)=(0,0).
Here is a simple example applying a
MeanFilter to an image object.
Note that the mask width and height must be odd numbers, as with the
convolution functions. Also, since some
operations take time (especially with large images), it's best to use an
hourglass cursor during processing to indicate a busy. This example is from the MSVC demo program.
void
CRGBDemoDoc::OnEditMeanfilter()
{
// TODO: Add your command handler code here
CWaitCursor waitCursorWhileAlive
;
if ( m_pMyImage )
m_pMyImage->FastMeanFilter(3,3);
SetModifiedFlag(TRUE);
UpdateAllViews(NULL,0,NULL); // redisplay all my views
}
Here
is an example from the previous version of the DLL, which used Borland OWL,
version 4.53. Borland 5.0 and C++
Builder should be similar.
void
TDrawWindow::CmSmooth()
{
BOOL isOkay = FALSE ;
int
wd=7, ht=5;// mask sizes must be odd, like convolve
SetCursor( 0, IDC_WAIT );
isOkay = ImageResult.FastMeanFilter( wd, ht );
SetCursor( 0, IDC_ARROW );
if ( isOkay )
Invalidate( TRUE );
else
MessageBox("Smooth
Error","Error",MB_ICONINFORMATION | MB_OK);
}
What follows is the class interface
for the 8-bit, 32-bit and float grayscale image classes and the RGB class. The methods are almost identical with their
conterparts in the DLL, whose functions described in detail in chapter 6. Please see that chapter for more details.
class Gr8Image {
protected:
HANDLE
hGr8 ;
public:
const
Gr8Image & operator = ( const Gr8Image & Image ) ;
Gr8Image()
;
Gr8Image(
const Gr8Image & Image ) ;
Gr8Image(
const Gr32Image & SrceImage ) ;
Gr8Image(
const GrFImage & SrceImage ) ;
Gr8Image(
int width, int height ) ;
Gr8Image(
HBITMAP hBitmap, const PALETTEENTRY *pEntry,
int
numEntry, const COLOR_WTS *pWts=NULL) ;
Gr8Image(
HBITMAP hBitmap, HPALETTE hPalette,
const
COLOR_WTS *pWts=NULL);
Gr8Image(
HANDLE hDIB, const COLOR_WTS *pWts=NULL ) ;
Gr8Image(
const BYTE * pBuffer, long lSize, BOOL isFromFile=TRUE,
const
COLOR_WTS *pWts=NULL);
Gr8Image(
const char * pFileName, const COLOR_WTS *pWts=NULL ) ;
~Gr8Image();
HANDLE
Handle() const { return ( hGr8 ) ; } ;
long
GetRequiredDIBSize() const ;
long
GetRequiredDIBFileSize() const ;
BOOL
SaveToDIBPtr( BYTE * pDib, long
lBufSize ) const ;
BOOL
SaveToDIBHnd( HANDLE hDIB ) const ;
BOOL
SaveToDIBFileBuffer( BYTE *pDIBFileBuffer, long lBufSize) const;
BOOL
SaveToDIBFile( const char * pFileName ) const ;
BOOL
IsOkay() const ;
int Width() const ;
int Height() const ;
BOOL
PasteToXYFromArray( const BYTE *
pSrceBits,
int
x, int y, int width, int height );
BOOL
PasteToXYFrom00( const Gr8Image & SrceImage, int x, int y );
BOOLPasteToArrayFromXY(
BYTE * pDestBits, int x, int y,
int
width, int height, long maxBytes );
BOOLPasteTo00FromXY(
const Gr8Image & SrceImage, int x, int y );
BOOLStretchOnDC(
HDC hDC, int destX, int destY,
int
destW, int destH, int srceX, int srceY,
int
srceW, int srceH) const;
BOOL
PaintOnDC( HDC hDC, int destX, int destY,
int
srceX, int srceY) const ;
BOOL
GetMinMax( BYTE & minVal, BYTE & maxVal ) const ;
BOOL
EqualizeHist();
BOOL
GetHist( long pHist[256] ) const ;
BOOL
GetRowHist( long pHist[256], int row ) const ;
BOOL
GetColHist( long pHist[256], int col ) const ;
BOOL
ConvolveInt3x3( const int Matrix[3][3] );
BOOL
ConvolveFloat3x3( const float Matrix[3][3] );
BOOL
ConvolveIntNxM( const int *pMatrix, int wd, int ht );
BOOL
ConvolveFloatNxM( const float
*pMatrix,int wd, int ht);
BOOL
CalcFFT( Gr8Image & RealFFT, Gr8Image & ImagFFT,
FFTquant
& qReal, FFTquant & qImag) const ;
BOOL
CalcIFFT( Gr8Image & RealFFT, Gr8Image & ImagFFT,
FFTquant
& qReal, FFTquant & qImag) const ;
BOOL
CalcFFTfull( Gr8Image & RealFFT, Gr8Image & ImagFFT,
Gr8Image
& FreqFFT, Gr8Image & PhaseFFT,
FFTquant
& qReal, FFTquant & qImag,
FFTquant
& qFreq, FFTquant & qPhase ) const ;
BOOL
MedianFilter( int maskWd, int maskHt );
BOOL
MeanFilter( int maskWd, int maskHt );
BOOL FastMeanFilter(
int maskWd, int maskHt );
BOOL
InvGradFilter( int maskWd, int maskHt );
BOOL
MomentsM( double m[4][4] ) const ;
BOOL
MomentsUM( double u[4][4], double m[4][4] ) const ;
BOOL
MomentsVUM( double v[4][4],
double
u[4][4], double m[4][4] ) const ;
BOOL
MomentsHVUM( double h[7], double v[4][4],
double
u[4][4], double m[4][4] ) const ;
BOOL
RemapBrightness( BYTE ConversionTable[256] );
BOOL
Threshold( BYTE value );
BOOL
LinearCombineInt( const Gr8Image & Image,
int
x, int y, int w1, int w2, int scale,
int
offset, BOOL mustABSVal );
BOOL
LinearCombineFloat( const Gr8Image & Image,
int
x, int y, float w1, float w2,
float
offset, BOOL mustABSVal );
BOOL
ResizeCopyFrom( const Gr8Image & Image );
BOOL
Erase( BYTE background );
BOOL
FlipX();
BOOL
FlipY();
BOOL
TranslateInt( int shiftX,int shiftY, BYTE bkgnd);
BOOL
TranslateFloat( float shiftX, float shiftY,BYTE bkgnd );
BOOL
Rescale( float scaleX, float scaleY, BYTE bkgnd);
BOOL
TranslateThenScale( float shiftX, float shiftY,
float
scaleX, float scaleY, BYTE bkgnd );
BOOL
Rotate90( int numTimes );
BOOL
Rotate( float numDegrees, BYTE bkgnd);
BOOL
PolyWarpFromCoefs( float *pXCoefs, float *pYCoefs,
int
numCoefs, BYTE bkgnd );
BOOL
PolyWarpFromPoints(
const
PairFloat *pSrcePts, const PairFloat *pDestPts,
int
numPts, int degree, BOOL & isSingular, BYTE bkgnd );
BOOL
GetPixelValue( BYTE & value, int x, int y ) const ;
BOOL
SetPixelValue( BYTE value, int x, int y ) ;
BOOL
CalcPixelValue( float & value, float x, float y, BYTE bkgnd)
const
;
BOOL
GetLineProfile( BYTE *pLine, int num,
float
x0, float y0, float x1, float y1,
BOOL
mustScale, BYTE bkgnd) const ;
BOOL
GetHProjection( BYTE *pProj, int num ) const ;
BOOL
GetVProjection( BYTE *pProj, int num ) const ;
BOOL
GetGoodThreshold( BYTE & value ) const ;
BOOL
Segment();
BOOL
Erode();
BOOL
Dilate();
BOOL
Close();
BOOL
Open();
BOOL
TemplateMatch( const Gr8Image & TemplateImage );
BOOL
HoughTransformTo( Gr8Image &
DestImage, BYTE threshold) const;
BOOL
GetEdgesLOGI( const float sigma, int Threshold);
BOOL
GetEdgesLOGF( const float sigma, int Threshold);
BOOL
Slice( BYTE a, BYTE b );
BOOL
LogRange();
BOOL
ALogRange();
BOOL
Contrast( BYTE a,BYTE b, BYTE ay, BYTE by );
BOOL
ClipNoise( BYTE a, BYTE b );
BOOL
Negative();
BOOL
BitInverse();
BOOL
Operate( BYTE operand, int operation );
BOOL
CombineWith( const Gr8Image & OtherImage, int operation );
BOOL
MakeShape( int shapeType );
} ;
class Gr32Image {
protected:
HANDLE
hGr32 ;
public:
const
Gr32Image & operator = ( const Gr32Image & Image ) ;
Gr32Image();
Gr32Image(
const Gr8Image & Image ) ;
Gr32Image(
const Gr32Image & Image ) ;
Gr32Image(
const GrFImage & Image ) ;
Gr32Image(
int width, int height );
~Gr32Image();
HANDLE
Handle() const { return ( hGr32 ) ; } ;
BOOL
IsOkay() const ;
BOOL
Width() const ;
BOOL
Height() const ;
BOOL
CopyFrom( const Gr8Image & SrceImage ) ;
BOOL
CopyFrom( const Gr32Image & SrceImage ) ;
BOOL
CopyFrom( const GrFImage & SrceImage ) ;
BOOL
AddConst( int a ) ;
BOOL
Add( const Gr32Image & OtherImage ) ;
BOOL
MultConst( int a ) ;
BOOL
MultConstF( float a ) ;
BOOL
GetMinMax( int & minVal, int & maxVal ) const ;
HPINT GetDataPtr() ;
} ;
class GrFImage {
protected:
HANDLE
hGrF ;
public:
const
GrFImage & operator = ( const GrFImage & Image ) ;
GrFImage()
;
GrFImage(
const GrFImage & Image ) ;
GrFImage(
const Gr8Image & Image ) ;
GrFImage(
const Gr32Image & Image ) ;
GrFImage(
int width, int height ) ;
~GrFImage()
;
HANDLE
Handle() const { return ( hGrF ) ; } ;
BOOL
IsOkay() const ;
BOOL
Width() const ;
BOOL
Height() const ;
BOOL
CopyFrom( const Gr8Image & SrceImage ) ;
BOOL
CopyFrom( const Gr32Image & SrceImage ) ;
BOOL
CopyFrom( const GrFImage & SrceImage ) ;
BOOL
AddConst( float a ) ;
BOOL
Add( const GrFImage & hOtherImage ) ;
BOOL
MultConst( float a ) ;
BOOL
Mult( const GrFImage & hOtherImage ) ;
BOOL
ScaleAndOffset( float scale, float offset ) ;
BOOL
GetMinMax( float & minVal, float & maxVal ) const ;
HPFLOAT
GetDataPtr() ;
BOOL
GetPixelValue( float & value, int x, int y ) const ;
BOOL
SetPixelValue( float value, int x, int y ) ;
BOOL
CalcFFT( GrFImage & Imaginary, BOOL
isReordering ) ;
BOOL
CalcIFFT( GrFImage & Imaginary, BOOL isReordering ) ;
BOOL
ConvertToFreqAndPhase( GrFImage & ImaginaryFFT ) ;
BOOL
ConvertFromFreqAndPhase( GrFImage & PhaseFFT ) ;
} ;
class RGBImage {
protected:
RGBHANDLES*pRGB
;
public:
const
RGBImage & operator = ( const RGBImage & Image ) ;
RGBImage()
;
RGBImage(
const RGBImage & SrceImage ) ;
RGBImage(
const Gr8Image & SrceImage ) ;
RGBImage(
const Gr32Image & SrceImage ) ;
RGBImage(
const GrFImage & SrceImage ) ;
RGBImage(
int width, int height ) ;
RGBImage(
HBITMAP hBitmap, const PALETTEENTRY *pEntry,int numEntry);
RGBImage(
HBITMAP hBitmap, HPALETTE hPalette );
RGBImage(
HANDLE hDIB ) ;
RGBImage(
const BYTE * pBuffer, long lSize, BOOL isFromFile=TRUE) ;
RGBImage(
const char * pFileName ) ;
~RGBImage();
const
RGBHANDLES*Handle() const { return ( pRGB ) ; } ;
HPALETTE
CreateCustomPalette() const ;
long
GetRequiredDIBSize() const ;
long
GetRequiredDIBFileSize() const ;
BOOL
SaveToDIBPtr( BYTE * pDib, long
lBufSize ) const ;
BOOL
SaveToDIBHnd( HANDLE hDIB ) const ;
BOOL
SaveToDIBFileBuffer( BYTE *pDIBFileBuffer,long lBufSize) const;
BOOL
SaveToDIBFile( const char * pFileName ) const ;
long
GetRequired8BitDIBSize() const ;
long
GetRequired8BitDIBFileSize() const ;
BOOL
SaveTo8BitDIBPtr( BYTE * pDib, long
lBufSize ) const ;
BOOL
SaveTo8BitDIBHnd( HANDLE hDIB ) const ;
BOOL
SaveTo8BitDIBFileBuffer( BYTE
*pDIBFileBuffer,
long
lBufSize ) const ;
BOOL
SaveTo8BitDIBFile( const char * pFileName ) const ;
BOOL
IsOkay() const ;
int
Width() const ;
int
Height() const ;
BOOL
PasteToXYFrom00( const RGBImage & SrceImage, int x, int y );
BOOL
PasteTo00FromXY( const RGBImage & SrceImage, int x, int y );
BOOL
StretchOnDC(HDC hDC,
int
destX, int destY, int destW, int destH,
int
srceX, int srceY, int srceW, int srceH) const;
BOOL
PaintOnDC( HDC hDC, int destX, int destY,
int
srceX, int srceY) const ;
BOOL
GetMinMax( RGB_VALUE & minVal, RGB_VALUE & maxVal) const ;
BOOL
EqualizeHist();
BOOL
ConvolveInt3x3( const int Matrix[3][3] );
BOOL
ConvolveFloat3x3( const float Matrix[3][3] );
BOOL
ConvolveIntNxM( const int *pMatrix, int wd, int ht );
BOOL
ConvolveFloatNxM( const float
*pMatrix,int wd, int ht);
BOOL
MedianFilter( int maskWd, int maskHt );
BOOL
MeanFilter( int maskWd, int maskHt );
BOOL
FastMeanFilter( int maskWd, int maskHt );
BOOL
InvGradFilter( int maskWd, int maskHt );
BOOL
LinearCombineInt( const RGBImage & Image,
int
x, int y, int w1, int w2, int scale,
int
offset, BOOL mustABSVal );
BOOL
LinearCombineFloat( const RGBImage & Image,
int
x, int y, float w1, float w2,
float
offset, BOOL mustABSVal );
BOOL
ResizeCopyFrom( const RGBImage & Image );
BOOL
Erase( RGB_VALUE background );
BOOL
FlipX();
BOOL
FlipY();
BOOL
TranslateInt( int shiftX,int shiftY, RGB_VALUE bkgnd);
BOOL
TranslateFloat( float shiftX, float shiftY,
RGB_VALUE
bkgnd );
BOOL
Rescale( float scaleX, float scaleY, RGB_VALUE bkgnd);
BOOL
TranslateThenScale( float shiftX, float shiftY,
float
scaleX, float scaleY, RGB_VALUE bkgnd );
BOOL
Rotate90( int numTimes );// Rev 2.59
BOOL
Rotate( float numDegrees, RGB_VALUE bkgnd);
BOOL
PolyWarpFromCoefs( const float *pXCoefs,
const
float *pYCoefs, int numCoefs, RGB_VALUE bkgnd );
BOOL
PolyWarpFromPoints(
const
PairFloat *pSrcePts, const PairFloat *pDestPts,
int
numPts, int degree, BOOL & isSingular,
RGB_VALUE
bkgnd );
BOOL
GetPixelValue( RGB_VALUE & value, int x, int y ) const ;
BOOL
SetPixelValue( RGB_VALUE value, int x, int y ) ;
BOOL
CalcPixelValue( RGB_VALUE & value, float x, float y,
RGB_VALUE
bkgnd) const ;
BOOL
TemplateMatch( const RGBImage & TemplateImage );
BOOL
Contrast( BYTE a,BYTE b, BYTE ay, BYTE by );
BOOL
Negative();
BOOL
Operate( RGB_VALUE color, int operation );
BOOL
CombineWith( const RGBImage & OtherImage, int operation );
BOOL
ConvertFromRGBToHSI() ;
BOOL
ConvertFromHSIToRGB() ;
BOOL
ChangeHueByDegrees( float numDegrees ) ;
} ;
Chapter 6
The main class
modules, listed at the end of this chapter, are located in the parent directory. The individual sample projects with their
forms and other files are located in subdirectories. Each project will need to be edited so that the class modules
living “upstairs” can be found. That
is, the file paths held by the project should be updated to point to the
directory where the class files are to be found. Once that is done, the project should compile and run.
There is one other
tricky aspect to working with DLLs and VB.
If the DLL’s path is not in the current environment (set by autoexec.bat
or held in the user profiles), then the DLL can still be found by the
application as long as it is located in the same directory as the
executable. During development, the
“executable” is really VB itself, the currently running application, and so the
DLL needs to be situated in the VB directory.
But after VB has created an executable program, say “myprogram.exe”,
then that program will call the DLL itself, and so the DLL now needs to be
located in the same directory as “myprogram.exe”. Of course, if the DLL is in the current path, then it will be
found no matter where the executable lives.
The sample program uses Visual Basic
version 5.0. VB Image objects are
declared using a variety of constructors.
This example loads an 8-bit image from a BMP file into the global
variable gray8.
Private gray8
As New cGray8BitImage
Private
gray8RealFFT As New cGray8BitImage
Private
gray8ImagFFT As New cGray8BitImage
Private
Filename As String
Private Sub
mnuFileOpen_Click()
Dim sFile As String
With dlgCommonDialog
'set the flags and attributes of the
'common dialog control
.filter = "BMP Files
(*.BMP)|*.BMP"
.ShowOpen
If Len(.Filename) = 0 Then
Exit Sub
End If
sFile = .Filename
End With
'To Do
'process the opened file
If gray8.LoadFromBMPFile(sFile) Then
Filename = sFile
PictureDisplay.Refresh
Else
MsgBox "Error loading File "
+ sFile
End If
End Sub
The image object 'gray8' uses one of
its constructors to load itself from the named file. The constructor uses default color weights
(Red=.3, Green=.59, Blue=.11) since the weights parameter is not specified in
the call.
The following code saves gray8 to
the DIB file whose name is held in the global variable ‘Filename’.
Private Sub
mnuFileSave_Click()
If Not gray8.SaveToBMPFile(Filename) Then
MsgBox "Error saving File to
" + Filename
End
If
End Sub
To paint a gray image onto a device
context, first the device context must be loaded with an acceptible
palette. The example program displays
the image in a PictureBox named PictureDisplay. A handle to its display context (HDC) is passed to the gray8
paint functions, either PaintOnDCStretch() or PaintOnDC(). It is assumed in this program that the
PictureBox will be able to display the gray hues of the image. Many Pcs are able to display thousands of
colors simultaneously, so palette conflicts seldom arise.
Private Sub
PictureDisplay_Paint()
Dim isOkay As Boolean
Dim wd, ht
wd = gray8.width()
ht = gray8.height()
If mnuViewStretch.Checked Then
isOkay = gray8.PaintOnDCStretch(PictureDisplay.hDC,
0, 0,
PictureDisplay.ScaleWidth, PictureDisplay.ScaleHeight,
0, 0, wd, ht)
Else
isOkay =
gray8.PaintOnDC(PictureDisplay.hDC, 0, 0, 0, 0)
End If
End Sub
The PaintOnDC method parameters
specify to paint to destination point (x,y)=(0,0) from source point
(x,y)=(0,0).
Here is a simple example applying a
MeanFilter to an image object.
Note that the mask width and height must be odd numbers, as with the
convolution functions. Also, since some
operations take time (especially with large images), it's best to use an
hourglass cursor during processing to indicate a busy, which has not done in this
case.
Private Sub
mnuFilterMean_Click()
Dim isOkay As Boolean
isOkay = gray8.FastMeanFilter(3, 3)
If isOkay Then
PictureDisplay.Refresh
Else
MsgBox "Error filtering
image"
End If
End Sub
What follows is the class interface
for the 8, 16 and 32 bit (float) grayscale, 24-bit RGB image classes and a
special FFT-dedicated class. The methods are almost identical with their
conterparts in the DLL functions described in detail in chapter 8. Please see that chapter for more
details. Note that the FFT class,
cFFTImage, does not directly access the DLL.
Instead it calls on the cGrayFloatImage class for most of its
operations.
Public
Property Get myHandle() As Long
Public
Sub getQuantization(ByRef dcLevel As Single,
ByRef
scaleX As Single,
ByRef
offset As Single)
Public
Sub setQuantization(ByVal dcLevel As Single,
ByVal
scaleX As Single,
ByVal
offset As Single)
Public
Function resize(ByVal width As Long, ByVal height As Long)
As
Boolean
Public
Function PaintOnDCStretch(ByVal hDC As Long,
ByVal
destX As Long, ByVal destY As Long,
ByVal
destW As Long, ByVal destH As Long,
ByVal
srceX As Long, ByVal srceY As Long,
ByVal
srceW As Long, ByVal srceH As Long) As Boolean
Public
Function PaintOnDC(ByVal hDC As Long,
ByVal
destX As Long, ByVal destY As Long,
ByVal
srceX As Long, ByVal srceY As Long) As Boolean
Public
Function CreateFromCopy(ByVal sourceImage As cGray8BitImage)
As
Boolean
Public
Function CreateFromGrayFloatCopy(
ByVal
sourceImage As cGrayFloatImage) As Boolean
Public
Function CreateFromGray32Copy(
ByVal
sourceImage As cGray32BitImage) As Boolean
Public
Function CreateFromBitmap(ByVal hBitmap As Long,
ByRef
pEntry As Byte, ByVal numEntry As Long)As Boolean
Public
Function CreateFromHBMHPAL(ByVal hBitmap As Long,
ByVal
hPalette As Long) As Boolean
Public
Function CreateFromDIBBuffer(ByRef buffer() As Byte)As Boolean
Public
Function CreateFromDIBHnd(ByVal hDIB As Long) As Boolean
Public
Function LoadFromBMPFile(ByVal filename As String) As Boolean
Public
Function GetRequiredDIBSize() As Long
Public
Function SaveToBufferAsDIB(ByRef buffer() As Byte) As Boolean
Public
Function SaveToDIBHnd(ByVal hDIB As Long) As Boolean
Public
Function SaveToBMPFile(ByVal filename As String) As Boolean
Public
Function isOkay() As Boolean
Public
Function width() As Long
Public
Function height() As Long
Public
Function PasteToXYFromArray(ByRef buffer() As Byte,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function PasteToXYFromOtherImage(
ByVal
sourceImage As cGray8BitImage,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function PasteToArrayFromXY(ByRef buffer() As Byte,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function PasteFromOtherImageXY(
ByVal
sourceImage As cGray8BitImage,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function CopyFromStretchedImage(
ByVal
sourceImage As cGray8BitImage) As Boolean
Public
Function GetMinMaxPixel(ByRef min As Byte, ByRef max As Byte)
As
Boolean
Public
Function EqualizeHistogram() As Boolean
Public
Function ImageHistogram(ByRef Histogram() As Long) As Boolean
Public
Function GetRowHistogram(ByRef Histogram() As Long,
ByVal
row As Long) As Boolean
Public
Function GetColumnHistogram(ByRef Histogram() As Long,
ByVal
column As Long) As Boolean
Public
Function MedianFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function MeanFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function FastMeanFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function InverseGradFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function ConvolveLong3x3(ByRef iMatrix() As Long) As Boolean
Public
Function ConvolveSingle3x3(ByRef sMatrix() As Single)
As
Boolean
Public
Function ConvolveLongNxM(ByRef iMatrix() As Long) As Boolean
Public
Function ConvolveSingleNxM(ByRef sMatrix() As Single)
As
Boolean
Public
Function EdgesLOG(ByVal sigma As Single,
ByVal
threshold As Long) As Boolean
Public
Function EdgesLOG2(ByVal sigma As Single,
ByVal
threshold As Long) As Boolean
Public
Function resizeToPowerOfTwo() As Boolean
Public
Function CalcFFT(ByRef RealPartOfFFT As cGray8BitImage,
ByRef
ImagPartOfFFT As cGray8BitImage) As Boolean
Public
Function CalcInverseFFT(ByRef RealPartOfFFT As cGray8BitImage,
ByRef
ImagPartOfFFT As cGray8BitImage) As Boolean
Public
Function CalcFFTWithExtra(
ByRef
RealPartOfFFT As cGray8BitImage,
ByRef
ImagPartOfFFT As cGray8BitImage,
ByRef
FreqPartOfFFT As cGray8BitImage,
ByRef
PhasPartOfFFT As cGray8BitImage) As Boolean
Public
Function BrightnessLog() As Boolean
Public
Function BrightnessInverseLog() As Boolean
Public
Function Contrast(ByVal increase As Boolean) As Boolean
Public
Function ClipNoise(ByVal low As Byte, ByVal high As Byte)
As
Boolean
Public
Function BrightnessSlice(ByVal low As Byte,
ByVal
high As Byte) As Boolean
Public
Function BrightnessNegative() As Boolean
Public
Function BrightnessReverseBits() As Boolean
Public
Function BrightnessOperate(ByVal operand As Byte,
ByVal
operation As Long) As Boolean
Public
Function GetThreshold(ByRef threshold As Byte) As Boolean
Public
Function BrightnessThreshold(ByVal thresh As Byte) As Boolean
Public
Function BrightnessRemap(ByRef ConversionTable() As Byte)
As
Boolean
Public
Function EraseImage() As Boolean
Public
Function SetAllPixels(ByVal background As Byte) As Boolean
Public
Function BrightnessSegment() As Boolean
Public
Function ErodeImage() As Boolean
Public
Function DilateImage() As Boolean
Public
Function CloseImage() As Boolean
Public
Function OpenImage() As Boolean
Public
Function FlipX() As Boolean
Public
Function FlipY() As Boolean
Public
Function TranslateFast(ByVal shiftX As Long,
ByVal
shiftY As Long) As Boolean
Public
Function TranslateAccurate(ByVal shiftX As Single,
ByVal
shiftY As Single) As Boolean
Public
Function Rescale(ByVal scaleX As Single,
ByVal
scaleY As Single) As Boolean
Public
Function TranslateThenScale(ByVal shiftX As Single,
ByVal
shiftY As Single,
ByVal
scaleX As Single, ByVal scaleY As Single) As
Public
Function Rotate90(ByVal numTimes As Long) As Boolean
Public
Function Rotate(ByVal numDegrees As Single) As Boolean
Public
Function CalcPolyWarpCoefsFromData(ByRef XCoefs() As Single,
ByRef
YCoefs() As Single, ByVal numCoefs As Long,
ByRef
SrcePtsX() As Single, ByRef SrcePtsY() As Single,
ByRef
DestPtsX() As Single, ByRef DestPtsY() As Single,
ByVal
numPts As Long, ByVal degree As Long,
ByRef
isSingular As Boolean) As Boolean
Public
Function WarpBasedOnCoefs(ByRef pXCoefs() As Single,
ByRef
pYCoefs() As Single, numCoefs As Long) As Boolean
Public
Function WarpBasedOnDataPoints(ByRef SrcePtsX() As Single,
ByRef
SrcePtsY() As Single, ByRef DestPtsX() As Single,
ByRef
DestPtsY() As Single, ByVal numPts As Long,
ByVal
degree As Long, ByRef isSingular As Boolean)
As
Boolean
Public
Function GetPixelValue(ByRef value As Byte, ByVal x As Long,
ByVal
y As Long) As Boolean
Public
Function SetPixelValue(ByVal value As Byte, ByVal x As Long,
ByVal y As Long) As Boolean
Public
Function CalcPixelValue(ByRef value As Single,
ByVal
x As Single, ByVal y As Single) As Boolean
Public
Function GetLineProfile(ByRef LineValues() As Byte,
ByVal
num As Long,
ByVal
x0 As Single, ByVal y0 As Single,
ByVal
x1 As Single, ByVal y1 As Single,
ByVal
mustScale As Boolean) As Boolean
Public
Function GetHorizontalProjection(ByRef Projection() As Byte)
As
Boolean
Public
Function GetVerticalProjection(ByRef Projection() As Byte)
As
Boolean
Public
Function GetMomentsM(ByRef Spatial4x4() As Double) As Boolean
Public
Function GetMomentsUM(ByRef Central4x4() As Double,
ByRef
Spatial4x4() As Double) As Boolean
Public
Function GetMomentsVUM(ByRef Normalized4x4() As Double,
ByRef
Central4x4() As Double,
ByRef
Spatial4x4() As Double) As Boolean
Public
Function GetMomentsHVUM(ByRef H7x1() As Double,
ByRef
Normalized4x4() As Double,
ByRef
Central4x4() As Double,
ByRef
Spatial4x4() As Double) As Boolean
Public
Function LinearCombineInt(ByVal sourceImage As cGray8BitImage,
ByVal
x As Long, ByVal y As Long, ByVal w1 As Long,
ByVal
w2 As Long, ByVal scaleVal As Long,
ByVal
offset As Long, ByVal mustABSVal As Boolean)
As
Boolean
Public
Function LinearCombineFloat(
ByVal
sourceImage As cGray8BitImage,
ByVal
x As Long, ByVal y As Long,
ByVal
w1 As Single, ByVal w2 As Single,
ByVal
scaleVal As Single, ByVal offset As Single,
ByVal
mustABSVal As Boolean) As Boolean
Public
Function TemplateMatch(ByVal templateImage As cGray8BitImage)
As
Boolean
Public
Function CalcRhoThetaFromSlopeInt(ByVal slope As Single,
ByVal
intercept As Single, ByRef rho As Single,
ByRef
theta As Single) As Boolean
Public
Function CalcSlopeIntFromRhoTheta(ByVal rho As Single,
ByVal
theta As Single, ByRef slope As Single,
ByRef
intercept As Single) As Boolean
Public
Function CalcRhoThetaFromHoughXY(ByVal x As Long,
ByVal
y As Long, ByVal nx As Long, ByVal ny As Long,
ByVal
W As Long, ByVal H As Long,
ByRef
rho As Single, ByRef theta As Single) As Boolean
Public
Function HoughTransformTo(
ByVal
destinationImage As cGray8BitImage,
ByVal
threshold As Byte) As Boolean
Public
Function CombineWithImageUsingOperation(
ByVal
sourceImage As cGray8BitImage,
ByVal
operation As Long) As Boolean
Public
Function makeShape(ByVal shapeType As Long) As Boolean
Public
Function copyToClipboard() As Boolean
Public
Function pasteFromClipboard() As Boolean
Public
Property Get myHandle() As Long
Public
Function resize(ByVal width As Long, ByVal height As Long)
As
Boolean
Public
Function CreateFromCopy(ByVal sourceImage As cGray32BitImage)
As
Boolean
Public
Function CreateFromGray8Copy(
ByVal
sourceImage As cGray8BitImage) As Boolean
Public
Function CreateFromGrayFloatCopy(
ByVal
sourceImage As cGrayFloatImage) As Boolean
Public
Function isOkay() As Boolean
Public
Function width() As Long
Public
Function height() As Long
Public
Function PasteFromOtherImage(
ByVal
sourceImage As cGray32BitImage) As Boolean
Public Function GetMinMaxPixel(ByRef
min As Long, ByRef max As Long)
As
Boolean
Public
Function AddConstant(ByVal pixel As Long) As Boolean
Public
Function MultiplyConstant(ByVal pixel As Long) As Boolean
Public
Function MultiplySingleConstant(ByVal pixel As Single)
As
Boolean
Public
Function AddImage(ByVal sourceImage As cGray32BitImage)
As
Boolean
Public
Property Get myHandle() As Long
Public
Function resize(ByVal width As Long, ByVal height As Long)
As
Boolean
Public
Function CreateFromCopy(ByVal sourceImage As cGrayFloatImage)
As
Boolean
Public
Function CreateFromGray8Copy(
ByVal
sourceImage As cGray8BitImage) As Boolean
Public
Function CreateFromGray32Copy(
ByVal
sourceImage As cGray32BitImage) As Boolean
Public
Function isOkay() As Boolean
Public
Function width() As Long
Public
Function height() As Long
Public
Function PasteFromOtherImage(
ByVal
sourceImage As cGrayFloatImage) As Boolean
Public
Function GetMinMaxPixel(ByRef min As Single,
ByRef
max As Single) As Boolean
Public
Function AddConstant(ByVal pixel As Single) As Boolean
Public
Function MultiplyConstant(ByVal pixel As Single) As Boolean
Public
Function AddImage(ByVal sourceImage As cGrayFloatImage)
As
Boolean
Public
Function MultImage(ByVal sourceImage As cGrayFloatImage)
As
Boolean
Public
Function RescaleWithOffset(ByVal scaleVal As Single,
ByVal
offset As Single) As Boolean
Public
Function GetPixelValue(ByRef pixel As Single, ByVal x As Long,
ByVal
y As Long) As Boolean
Public
Function SetPixelValue(ByVal pixel As Single, ByVal x As Long,
ByVal
y As Long) As Boolean
Public
Function CalcFFTwithImaginaryImage(
ByVal
imaginaryImage As cGrayFloatImage) As Boolean
Public
Function CalcIFFTwithImaginaryImage(
ByVal
imaginaryImage As cGrayFloatImage) As Boolean
Public
Function ConvertToFreqAndPhase(
ByVal
imaginaryImage As cGrayFloatImage) As Boolean
Public
Function ConvertFromFreqAndPhase(
ByVal
phaseImage As cGrayFloatImage) As Boolean
Public
Property Get status() As FFT_Description
Public
Function CreateFromCopy(ByVal real As cGrayFloatImage)
As
Boolean
Public
Function CreateFrom8BitCopy(ByVal real As cGray8BitImage)
As
Boolean
Function
isOkay() As Boolean
Public
Function fft() As Boolean
Public
Function ifft() As Boolean
Public
Function ToFrequencyAndPhase() As Boolean
Public
Function ToRealAndImaginary() As Boolean
Public
Function GetRealComponent(ByRef anImage As cGrayFloatImage)
As
Boolean
Public
Function GetImaginaryComponent(
ByRef
anImage As cGrayFloatImage) As Boolean
Public
Function GetFrequencyComponent(
ByRef
anImage As cGrayFloatImage) As Boolean
Public
Function GetPhaseComponent(ByRef anImage As cGrayFloatImage)
As
Boolean
Public
Function GetGray8Frequency(ByRef anImage As cGray8BitImage,
ByRef
dcPixel As Single, ByRef scaleVal As Single,
ByRef
offset As Single) As Boolean
Public
Function GetGray8Phase(ByRef anImage As cGray8BitImage,
ByRef
dcPixel As Single, ByRef scaleVal As Single,
ByRef
offset As Single) As Boolean
Public
Function GetGray8Real(ByRef anImage As cGray8BitImage,
ByRef
dcPixel As Single, ByRef scaleVal As Single,
ByRef
offset As Single) As Boolean
Public
Function GetGray8Imaginary(ByRef anImage As cGray8BitImage,
ByRef
dcPixel As Single, ByRef scaleVal As Single,
ByRef
offset As Single) As Boolean
Public
Property Get myHandle() As Long
Public
Function resize(ByVal width As Long, ByVal height As Long)
As
Boolean
Public
Function PaintOnDCStretch(ByVal hDC As Long,
ByVal
destX As Long, ByVal destY As Long,
ByVal
destW As Long, ByVal destH As Long,
ByVal
srceX As Long, ByVal srceY As Long,
ByVal
srceW As Long, ByVal srceH As Long) As Boolean
Public
Function PaintOnDC(ByVal hDC As Long,
ByVal
destX As Long, ByVal destY As Long,
ByVal
srceX As Long, ByVal srceY As Long) As Boolean
Public
Function CreateFromCopy(ByVal sourceImage As cRGB24BitImage)
As
Boolean
Public
Function CreateFromGrayImage(
ByVal
sourceImage As cGray8BitImage) As Boolean
Public
Function CreateFrom3GrayImages(
ByVal
ImageRed As cGray8BitImage,
ByVal ImageGreen As cGray8BitImage,
ByVal ImageBlue As cGray8BitImage) As
Boolean
Public
Function CreateFromBitmap(ByVal hBitmap As Long,
ByRef
pEntry As Byte, ByVal numEntry As Long) As Boolean
Public
Function CreateFromHBMHPAL(ByVal hBitmap As Long,
ByVal
hPalette As Long) As Boolean
Public
Function CreateFromDIBBuffer(ByRef buffer()As Byte) As Boolean
Public
Function CreateFromDIBHnd(ByVal hDIB As Long) As Boolean
Public
Function LoadFromBMPFile(ByVal Filename As String) As Boolean
Public
Function GetRequiredDIBSize() As Long
Public
Function SaveToBufferAsDIB(ByRef buffer() As Byte) As Boolean
Public
Function SaveToDIBHnd(ByVal hDIB As Long) As Boolean
Public
Function SaveToBMPFile(ByVal Filename As String) As Boolean
Public
Function isOkay() As Boolean
Public
Function width() As Long
Public
Function height() As Long
Public
Function PasteToGray8ImageFromXY(
ByVal
destImage As cGray8BitImage,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function PasteToXYFromOtherImage(
ByVal
sourceImage As cRGB24BitImage,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function PasteFromOtherImageXY(
ByVal
sourceImage As cRGB24BitImage,
ByVal
x As Long, ByVal y As Long) As Boolean
Public
Function CopyFromStretchedImage(
ByVal
sourceImage As cRGB24BitImage) As Boolean
Public
Function GetMinMaxPixel(ByRef minPixel As Long,
ByRef
maxPixel As Long) As Boolean
Public
Function EqualizeHistogram() As Boolean
Public
Function MedianFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function MeanFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function FastMeanFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function InverseGradFilter(ByVal wd As Long, ByVal ht As Long)
As
Boolean
Public
Function ConvolveLong3x3(ByRef iMatrix() As Long) As Boolean
Public
Function ConvolveSingle3x3(ByRef sMatrix() As Single)
As
Boolean
Public
Function ConvolveLongNxM(ByRef iMatrix() As Long) As Boolean
Public
Function ConvolveSingleNxM(ByRef sMatrix() As Single)
As
Boolean
Public
Function Contrast(ByVal increase As Boolean) As Boolean
Public
Function BrightnessNegative() As Boolean
Public
Function BrightnessOperate(ByVal operation As Long,
ByVal
operand As Long) As Boolean
Public
Function EraseImage() As Boolean
Public
Function SetAllPixels(ByVal background As Byte) As Boolean
Public
Function FlipX() As Boolean
Public
Function FlipY() As Boolean
Public
Function TranslateFast(ByVal shiftX As Long,
ByVal
shiftY As Long) As Boolean
Public
Function TranslateAccurate(ByVal shiftX As Single,
ByVal
shiftY As Single) As Boolean
Public
Function Rescale(ByVal scaleX As Single,
ByVal
scaleY As Single) As Boolean
Public
Function TranslateThenScale(ByVal shiftX As Single,
ByVal
shiftY As Single, ByVal scaleX As Single,
ByVal
scaleY As Single) As Boolean
Public
Function Rotate90(ByVal numTimes As Long) As Boolean
Public
Function Rotate(ByVal numDegrees As Single) As Boolean
Public
Function CalcPolyWarpCoefsFromData(ByRef XCoefs() As Single,
ByRef
YCoefs() As Single, ByVal numCoefs As Long,
ByRef
SrcePtsX() As Single, ByRef SrcePtsY() As Single,
ByRef
DestPtsX() As Single, ByRef DestPtsY() As Single,
ByVal
numPts As Long, ByVal degree As Long,
ByRef
isSingular As Boolean) As Boolean
Public
Function WarpBasedOnCoefs(ByRef pXCoefs() As Single,
ByRef
pYCoefs() As Single, numCoefs As Long) As Boolean
Public
Function WarpBasedOnDataPoints(ByRef SrcePtsX() As Single,
ByRef
SrcePtsY() As Single, ByRef DestPtsX() As Single,
ByRef
DestPtsY() As Single, ByVal numPts As Long,
ByVal
degree As Long, ByRef isSingular As Boolean)
As
Boolean
Public
Function GetPixelValue(ByRef value As Long, ByVal x As Long,
ByVal
y As Long) As Boolean
Public
Function SetPixelValue(ByVal value As Long, ByVal x As Long,
ByVal
y As Long) As Boolean
Public
Function CalcPixelValue(ByRef value As Long,
ByVal
x As Single, ByVal y As Single) As Boolean
Public
Function LinearCombineInt(ByVal sourceImage As cRGB24BitImage,
ByVal
x As Long, ByVal y As Long,
ByVal
w1 As Long, ByVal w2 As Long,
ByVal
scaleVal As Long, ByVal offset As Long,
ByVal
mustABSVal As Boolean) As Boolean
Public
Function LinearCombineFloat(
ByVal
sourceImage As cRGB24BitImage,
ByVal
x As Long, ByVal y As Long, ByVal w1 As Single,
ByVal
w2 As Single, ByVal scaleVal As Single,
ByVal
offset As Single, ByVal mustABSVal As Boolean)
As
Boolean
Public
Function TemplateMatch(ByVal templateImage As cRGB24BitImage)
As
Boolean
Public
Function CombineWithImageUsingOperation(
ByVal
sourceImage As cRGB24BitImage,
ByVal
operation As Long) As Boolean
Public
Function CreateSimpleShape(ByVal shape As Long,
ByVal
color As Long) As Boolean
Public
Function ViewAsHSI() As Boolean
Public
Function ViewAsRGB() As Boolean
Public
Function ChangeHueByDegrees(ByVal numDegrees As Single)
As
Boolean
Public
Function copyToClipboard() As Boolean
Public
Function pasteFromClipboard() As Boolean
Chapter
7