| [Up] [Strel] | Data Types |
| User Feedback |
class Image
{
public:
Image();
Image(const Image& img);
Image(int width, int height, int depth, const char *type, const char *raster);
Image(int width, int height, int depth, const char *type = "uint8", double value = 0);
Image(int pix);
Image(double pix);
Image(const IplImage *img);
Image(const char *filename, int iscolor = -1);
//
~Image();
//
Image& operator=(const Image& img);
operator IplImage*() const;
//
int width() const;
int height() const;
int depth() const;
char *raster() const;
char ***pointers() const;
const char *typestr() const;
int pixsize() const;
String str() const;
//
void putpixel(int x, int y, int z, double value);
double getpixel(int x, int y, int z) const;
//
void save(char *filename) const;
void show(int id = 0, char *title = "OpenCV Viewer") const;
//
Image slice(int x0, int x1, int y0, int y1, int z0, int z1) const;
Image uint8() const;
Image uint16() const;
Image int32() const;
//
int isnull() const;
int isbinary() const;
};
The Morphology Toolbox mainly supports four types of images according to their pixel datatypes : binary, unsigned gray scale uint8 and uint16, and signed gray scale int32. Most functions work for 1D, 2D and 3D images.
The following public methods are intended for use by application programs:
Image()
: default constructor; builds an empty image.
Image(const Image&)
: copy constructor
Image(int width, int height, int depth, const char *type, const char *raster)
: constructor that creates an image with:
w,h,d
,type
(type
is one of "uint8", "uint16", "int32", "binary"
) andraster
pointer is not NULL, with raster initialized from raster
.Image(int width, int height, int depth, const char *type = "uint8", double value = 0)
: constructor that creates a constant image with size w,h,d
, type type
and pixels initialized to valueImage(int pix)
: builds an "int32" image 1x1x1 with value pixImage(double pix)
: builds an "int32" image 1x1x1 with value pixImage(const IplImage *img)
: builds an image from the OpenCV
image pointed by img
.
Image(const char *filename, int iscolor = -1)
: reads an image from file filename
. The second argument may take the values(see the OpenCV
function cvLoadImage
):
>0:
the loaded image will always have 3 channels (RGB image);=0:
the loaded image will always have 1 channel (Grayscale image);<0:
the image will be loaded as is.~Image()
: destructor
Image& operator=(const Image&)
: assignment operator
operator IplImage*() const
: cast for OpenCV
images (creates an OpenCV
image from the object image; the caller becomes responsible for the OpenCV image deallocation with cvReleaseImage).
int width() const
: returns the width of the image
int height() const
: returns the height of the image
int depth() const
: returns the depth of the image
char *raster() const
: returns a pointer to the raster of the image (do not free this memory area)
char ***pointers() const
: returns an array of pointers ptr
, so that an image pixel can be acessed with ptr[z][y][x]String typestr() const
: returns the type of the image as a String
int pixsize() const
: returns the size (in bytes) of the image pixel
String str() const
: returns a string representation of the contents of the image suitable for printing small images
double getpixel(int x, int y, int z) const
: returns the value of the pixel at coordinates x,y,z
as a double
void putpixel(int x, int y, int z, double value)
: set the value of the pixel at coordinates x,y,z
from the double argument valuevoid save(char *filename) const
: saves the image in filename
. The file format is deduced from the filename extension. For supported formats see the OpenCV
function cvSaveImage
.
void show(int id = 0, char *title = "OpenCV Viewer") const
: raises an OpenCV
window and show the image (based on cvShowImage
). The argument id
, an integer in range 0-9, chooses one of 10 possible windows.
Image slice(int x0, int x1, int y0, int y1, int z0, int z1) const
: returns an image formed by the subset defined by the arguments: width from x0 to x1, height from y0 to y1 and depth from z0 to z1
Image uint8() const
: returns an uint8
copy of the image
Image uint16() const
: returns an uint16
copy of the image
Image int32() const
: returns an int32
copy of the image
int isnull() const
: returns 1 if this is an empty image
int isbinary() const
: returns 1 if this is a binary image
The class Image
is a proxy for the internal toolbox image type. It takes care of
chores like memory release and exception catching. When a toolbox function returns an image, an
object of this class is created to be returned to the caller. The object constructor catches
any error ocurred in the function implementation and, in case of error, throws a
morphException
.
To free your code of the memory allocation statements, keep your images created in local space,
so the underlying C++ system will take care of the memory releasing. Only in the case of returning
an image to another procedure, create the image in the heap with the new
operator.
See the code of the demonstrations for examples of use of the Image
class.
| mmBinary | Convert a gray-scale image into a binary image |
| mmUint8 | Convert an image to an uint8 image. |
| mmUint16 | Convert an image to a uint16 image. |
| mmInt32 | Convert an image to an int32 image. |
| mmShow | Display binary or gray-scale images and optionally overlay it with binary images. |
| mmDatatype | Return the image datatype string |
| mmLimits | Get the possible minimum and maximum of an image. |
| [Up] [Strel] | |
| User Feedback | |
| Copyright (c) 1998-2008 by SDC Information Systems |