Fundamentals of MATLAB image processing

Source: Internet
Author: User

Fundamentals of MATLAB image processing

2.2.1 Image File format and image type

1. Several image file formats supported by MATLAB:

⑴jpeg (Joint photogyaphic Expeyts Group): An image compression format called the joint Image Expert group.

⑵bmp (Windows Bitmap): There are 1-bit, 4-bit, 8-bit, 24-bit uncompressed images, and 8-bit RLE (RUN length encoded) images. The contents of the file include the header (a bitmap fileheader data structure), the bitmap information block (bitmap information header bitmap Infoheader and a color table), and the image data.

⑶PCX (Windows Paintbrush): Can process 1-bit, 4-bit, 8-bit, 16-bit, 24-bit image data. File contents include header, image data, and extended color map data.

⑷tiff (Tagged iamge File Format): Handles 1-bit, 4-bit, 8-bit, 24-bit uncompressed images, 1-bit, 4-bit, 8-bit, 24-bit packbit compressed images, 1-bit CCITT compressed images, and more. File contents include header, parameter pointer table and parameter field, parameter data table and image data four part.

⑸png (Portable Network Graphics): Includes 1-bit, 2-bit, 4-bit, 8-bit, and 16-bit grayscale images, 8-bit and 16-bit indexed images, 24-bit and 48-bit true color images.

⑹gif (Graphics interchange Format): Any 1-bit to 8-bit exchangeable image.

⑺HDF (hierarchial data Format): There are 8-bit, 24-bit raster image datasets.

⑻ico (Windows Icon Resource): There are 1-bit, 4-bit, 8-bit uncompressed images.

⑼cur (Windows Cursor Resource): There are 1-bit, 4-bit, 8-bit uncompressed images.

⑽XWD (X Windows Dump): Includes 1-bit, 8-bit zpixmaps,xybitmaps,xypixmmmaps.

⑾ras (Sun Raster image): 1-bit bitmap, 8-bit index, 24-bit True color, and 32-bit true color with transparency.

⑿PBM (Portable Bitmap).

⒀PGM (Portable Graymap).

⒁PPM (Portable pixmap).

2. MATLAB supports five types of images, two-value images, indexed images, grayscale images, RGB images, and multi-frame image arrays. The definitions for them are shown in table 2.1 below.

Table 2.1 image types and their corresponding pixel data types

Image type

Double data

Uint8 and UInt16 data

Two-valued image

Image is an integer matrix of MXN, element value range [0,1]

Image is an integer matrix of MXN, element value range [0,1]

Indexed images

Image is an integer matrix of MXN, element value range [0,p]

Image is an integer matrix of MXN, element value range [0,p-1]

Grayscale image

Floating-point matrix with an image of MXN, element value range [0,1]

Integer matrix with an image of MXN, element value range [0,255] or [0,65535]

RGB image

Floating-point matrix with image mxnx3, element value range [0,1]

An integer matrix with an image of Mxnx3, an element value range [0,255] or [0,65535]

Among them, multi-frame image array is composed of multi-frame images, each frame image can be one of the first four images, but the image that makes up a multi-frame image array must be the same. The cat function can save several independent images of the same size into a multi-frame file. For multi-frame images, you can also extract a single frame from it.

2.2.2 Image type judgment and conversion

1. In MATLAB If you want to determine the type of an image file, you can use the following command:

L ISBW: Returns True if the image is a two-value image.

L Isgray: If the image is a grayscale image, it returns true.

L Isind: Returns True if the image is an indexed image.

L ISRGB: If the image is an RGB image, it returns true.

2. In the MATLAB system, to convert one type of image file to another type of image file, simply read the image data of the previous file with Imread, and then use Imwrite to write in the appropriate format to the latter image file. In addition, to convert grayscale image I to RGB images, you can use cat instructions. The cat function can combine some single images into an image sequence. Each image in the image sequence needs to have the same size, and if it is an indexed image, the color map should be consistent.

In addition, MATLAB provides several functions for conversion of image types. These functions are:

L dither: Convert the image with the Jitter method (dithering). This function enhances the color resolution of the output image by Color jitter (color jitter that changes the color of the edge pixels so that the color around the pixel approximates the color of the original image, thereby exchanging the spatial resolution for the color resolution). This function can convert an RGB image to an indexed image or convert a grayscale image to a two-value image.

L Gray2ind: Grayscale image or binary image conversion to indexed image.

L Grayslice: Sets the threshold value to convert the grayscale image to an indexed image.

L IM2BW: Set threshold to convert grayscale, index, RGB images to two-value images.

L Im2double: Converts an array of images to a double type.

L Im2uint8: Converts an array of images to a uint8 type.

L Im2uint16: Converts an array of images to a uint16 type. The function does not support the conversion of binary image sequences.

L Ind2gray: The indexed image is converted to a grayscale image.

L IND2RGB: The indexed image is converted to an RGB image.

L Mat2gray: Converts a data matrix to a grayscale image.

L RGB2GRAY:RGB image to grayscale image or convert color color map to grayscale color map.

L RGB2IND:RGB Image conversion to indexed image. Contains three different methods: balanced quantization, minimum quantization, and color map mapping.

L Im2java: General image conversion to Java image.

L LABEL2RGB: The logo image is converted to an RGB image.

2.2.3 image Query and read-write

In MATLAB to query the information of an image file, as long as the imfinfo instruction with the file and its full path name. The function call format is:

info = imfinfo (filename,fmt)

info = imfinfo (filename)

The parametric FMT corresponds to all supported image file formats in all image processing toolboxes.

MATLAB provides two important instructions for reading and writing image files, namely the Imread to read data from an image file, and the Imwrite to write data to an image file.

1. The common invocation format for Imread is:

A = Imread (FILENAME,FMT)

The function is to represent the file name in the string filename, and the extension is read in matrix A in the image file represented by FMT. If filename refers to a grayscale image, A is a two-dimensional matrix, and if filename refers to an RGB image, A is a mxnx3 three-dimensional matrix. filename indicates that the file name must be within the scope of the search path for MATLAB, otherwise the full path will be indicated.

Several other important calling formats for Imread are:

[X,map] = Imread (FILENAME.FMT)

[...] = Imread (filename)

[...] = Imread (URL,...)

[...] = Imread (..., idx) (Cur,ico and TIFF only)

[...] = Imread (..., ' frames ', idx) (GIF only)

[...] = Imread (..., ref) (HDF only)

[...] = Imread (..., ' backgroundcolor ', BG) (PNG only)

[A,map,alpha] = Imread (...) (Ico,cur and PNG only)

Some of the above parameters have the following meanings: IDX refers to the read icon (cur, ICO, TIFF) file, the first IDX image, the default value is 1. ' Frame ', IDX refers to the reading of an image frame in a GIF file, and the IDX value can be a quantity, a vector, or ' all '. Ref refers to an integer value. Alpha refers to transparency.

2. The common invocation format for Imwrite is:

Imwrite (A,FILENAME,FMT)

Imwrite (X,MAP,FILENAME,FMT)

Imwrite (..., filename)

Imwrite (..., param1,val1,param2,val2 ...)

where Imwrite (...), param1,val1,param2,val2 ... Allows users to control the output characteristics of some image file formats such as HDF, JPEG, TIFF, etc.

In MATLAB, the default save type is Uint8. Because PNG and TIFF formats support 16-bit images, the save type is uint16 when you save such an image.

Display of 2.2.4 Images

The most basic means of displaying an image is to use the image function. The function also produces a handle to the image object and allows the object's properties to be set. In addition, the IMAGESC function has the function of image, and the difference is that the IMAGESC function automatically scales the input data and displays it in a panchromatic view.

The Imshow function is more commonly used than image and Imagesc, and it can automatically set various properties of the handle image. Imshow can be used to display various types of images. For each type of image, the method is called as follows:

L imshow FileName: Displays the image file.

L imshow (BW): Displays a binary image, BW is a black and white two value image matrix.

L Imshow (X,MAP): Display index image, X is index image matrix, map is color icon.

L Imshow (i): Display grayscale image, I is a two value image matrix.

L Imshow (RGB): Displays RGB image, RGB image matrix.

L Imshow (I,[low High]): Displays non-image data as an image, which takes into account whether the data exceeds the maximum allowable range of the displayed type, where [low high] is used to define the range of data to be displayed.

In addition to the above, MATLAB provides a number of functions for image display functions or their auxiliary functions, which are used for the special display of images.

L Colorbar: Adds a color bar to the display of the image, which is especially useful for understanding the grayscale level of the displayed image.

L GetImage: Get image data.

L Immovie: Make a multi-frame indexed image into a continuous image format. Its invocation format is:

mov = Immovie (d,map)

However, this function is only valid for indexed images, where D is a multi-frame indexed image array, and map is the corresponding color scale for indexed images. For other types of images, you need to first convert them to indexed images.

L Montage: One display of multi-frame images. It can display each frame in a different area of an image, with the same color bar for all the images in the sub-area.

L Movie: plays a multi-frame continuous image.

L Subimage: Displays multiple images within a graphics area.

L Truesize: Adjusts the size of the image display.

L Warp: Displays the texture surface map of the image. The image display method mentioned above can only be displayed on two-dimensional plane, and a powerful function of MATLAB6.5 is to display the planar image on three-dimensional surface of space. This is achieved by the warp function's texture mapping function, which can project planar images onto three-dimensional surfaces with bilinear interpolation.

Zoom: Enlarges or shrinks the image or two-dimensional graphic. Zoom itself is an open key, zoom on is used to turn on zoom mode, zoom off is used to turn off the mode, zoom in is used to enlarge the local image, zoom out is used to zoom out the image.

As for the display of multiple images, it can be divided into two aspects: display different images in different graphics window, can be implemented by the figure instruction, in the same graph window display multi-graph, can be implemented with subplot.

Chapter III Image Operations

3.1 Point operations for images

The point operation maps the input image to an output image, and the grayscale value of each pixel of the output image is determined only by the value of the corresponding input pixel point. It is often used to change the gray range and distribution of images, which is an important tool for image digitization and image display. The point operation is also known as contrast enhancement, contrast stretch, or grayscale transformation because of its action nature. It is sometimes possible to use point arithmetic to overcome the limitations of image digitizing devices before real image processing.

The point operation is actually a grayscale to grayscale mapping process. The point operation does not change the spatial relationship between pixels in the image. Set the input image to a (x, y) and the output image to B (x, y), the point operation can be expressed as:

B (x, y) = f [A (x, y)] (3-1)

The point operation can be determined entirely by the grayscale transformation (Gray-scale transformation) function s=F (R), which describes the mapping between the input grayscale level and the output grayscale level. The point operation of the image is divided into two kinds: linear point operation and nonlinear point operation.

3.1.1 Linear Point Arithmetic

The linear point operation refers to the operation of the gray transformation function F as a linear function.

3.1, when aand 1 o'clock, the output image contrast increases; when ais 1 o'clock, the output image is reduced in contrast ; When a =1,b= 0 o'clock, the output image is a simple copy of the input image; =1,b≠ 0 o'clock, only the grayscale value of the output image is moved up or down, and the effect is to make the entire image brighter or darker. If a is negative, the dark area will lighten, the light area will darken, and the point operation completes the image complement.

In addition to adjusting the contrast, there is a typical application of linear point operation is grayscale standardization. Set the grayscale image to I[w][h], where W represents the image width, H represents the height of the image, then the average grayscale image and square 3.1 linear function

The difference is obtained by the following calculation formula:

Average grayscale:

(3-2)

Variance:

(3-3)

It can be transformed into a transformation function (linear mapping) with the same mean and variance, in the form of the following:

(3-4)

where σ0 and U 0 are the given transformation parameters. Grayscale normalization can be used to generate a number of commonly used average models.

3.1.2 Nonlinear point operation

Nonlinear point operations correspond to nonlinear mapping functions, and typical mappings include square functions, logarithmic functions, intercept functions (window functions), domain value functions, multivalued quantization functions, and so on.

Threshold processing is one of the most common nonlinear point operations, its function is to select a threshold value, the image is binary, and then use the resulting binary image segmentation and Edge tracking processing.

Histogram equalization is also a very common non-linear point operation. It refers to a known gray scale distribution of the image using some kind of nonlinear gray-scale transformation function to calculate the result of the operation into a uniform gray-scale distribution of a new image. After the histogram equalization point arithmetic processing, the actual histogram will present the uneven shape, this is because the gray level's possible number is the limit causes. There may be no pixels at some grayscale levels, and pixels are crowded at other levels of gray.

MATLAB implementation of Point arithmetic:

I=imread (' rice.png ');

Rice=double (I);

rice2=rice*0.5+50;

J=uint8 (RICE2);

Subplot (1,2,1), Imshow (I);

Subplot (1,2,2), Imshow (J);

Fundamentals of MATLAB image processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.