6. Specific area processing __matlab image processing

Source: Internet
Author: User

When doing image processing, it is sometimes necessary to process only one particular region of the image, rather than the entire image. For example, to the user selected a specific area for the mean filter or contrast enhancement, MATLAB can only be specific to the region to deal with.

More MATLAB image processing video please click http://study.163.com/course/courseMain.htm?courseId=1003594013

1. Designation of areas of interest

The processing of specific areas in MATLAB is achieved by the two-value mask. When a user selects an area, a two-valued image with the same size as the original is generated, the selected area is white, and the remainder is black. The mask image enables selective processing of specific areas.

The MATLAB image processing Toolbox provides 3 functions for generating a two-value mask to select specific areas, described separately below.

(1) Roipoly:

The Roipoly function is used to select the polygon region in the image. The Roipoly function returns the binary image bw, with a pixel value of 1 (white) in the selected region, and a value of 0 (black) for the remainder. This binary image can be used as a mask to select a target or background from the operation of the original. The syntax format is as follows:

Bw=roipoly (I,c,r)

BW = Roipoly (I)
BW = Roipoly (x,y,i,xi,yi)
[Bw,xi,yi] = Roipoly (⋯)
[X,y,bw,xi,yi] = Roipoly (⋯)


Bw=roipoly (I,C,R) is the coordinates of the x and Y axes that specify the corners of the polygon with Vector C and R.

Bw=roipoly (I) is to allow the user to interactively select the Polygon area, select corner points, use the SPACEBAR and Del keys to undo the selection, press Enter to confirm the selection.

Bw=roipoly (X,y,i,xi,yi) establishes a non-default coordinate system with vector x and y, and then selects the polygon region specified by the Vector Xi and Yi in the specified coordinate system.
[Bw,xi,yi]=roipoly (⋯) interactively selects the polygon region and returns the coordinates of the polygon's corner point.
[X,y,bw,xi,yi]=roipoly (⋯) interactively selects the polygon region and returns the coordinates of the polygon vertex under the specified coordinate system x,y.

Cases:

I=imread (' eight.tif ');
%matlab with the material map, do not need to specify the path, in the work path of MATLAB, C:\Program Files\matlab\r2014a\toolbox\images\imdata
c=[222 272 300 270 221 194];
R=[21 21 75 121 121 75];
Bw=roipoly (I,C,R);
Imshow (I), title (' original artwork ');
Figure,imshow (BW), title (' Selected area ');

(2) Roicolor

MATLAB Image Processing Toolbox provides the Roicolor function can be RGB image and grayscale image implementation by grayscale or brightness value selection area, the syntax format is:
BW = Roicolor (A,low,high)
BW = Roicolor (a,v)

BW = Roicolor (A,low,high) indicates that the image is split by the specified grayscale range, and returns a binary mask Bw,[low high] as a grayscale range for the area you want to select, or 0 (black) if the grayscale value is in this range. If low is greater than high, it is returned as an empty matrix.

Bw=roicolor (A,V) is the gray value specified in the vector v to select the range.

Cases:

I=imread (' rice.png ');
>>%matlab with the material map, do not need to specify the path, in the work path of MATLAB, C:\Program Files\matlab\r2014a\toolbox\images\imdata

>> Bw=roicolor (i,128,255);
The grayscale value of >>% image I returns 1 (i.e. white) in the range of [128 255], not within [128 255], and returns 0 (i.e. black);
>> figure,imshow (I), title (' original artwork ');
>> figure,imshow (BW), title (' Selected area ');


(3) Poly2mask

This function converts the specified polygon region to a two-value mask. Statement is formatted as
BW = Poly2mask (x,y,m,n)
X and y represent two vectors, specifying a polygon region, the size of BW is MXN, the pixel within the specified range in BW is 1 (white), and the pixel outside the specified range is 0 (black). If the area specified by x and Y is not closed, the poly2mask automatically closes the polygon.

Cases:

x = [63 186 54 190 63];
y = [60 60 209 204 60];
BW = Poly2mask (x,y,256,256);
Imshow (BW)
Hold on
Plot (x,y, ' B ', ' linewidth ', 2)


2. Specific area filter

MATLAB Image Processing Toolbox provides an area filter function ROIFILT2, its syntax format is:
J = ROIFILT2 (H,I,BW)
J = ROIFILT2 (i,bw,fun)
J = ROIFILT2 (I,bw,fun,p1,p2,⋯)

J = ROIFILT2 (H,I,BW) uses filter h to filter image I using the two-value mask BW selection.
J=ROIFILT2 (I,bw,fun) and J=ROIFILT2 (I,bw,fun,p1,p2,⋯) function operation fun for image I with two value mask BW, where fun is the string that describes the function operation, and the parameter is P1, P2, and ... returns the image J in the Select The pixels in the region are the result of the fun operation of the image I, and the remaining pixel values are the original values of I.

Cases:

I = Imread (' eight.tif ');
c = [222 272 300 270 221 194];
R = [21 21 75 121 121 75];
BW = Roipoly (i,c,r);% specifies polygons defined by the filter area as C and R
h = fspecial (' unsharp ');% specified filter operator is Unsharp
J = ROIFILT2 (H,I,BW);
Figure,imshow (I), title (' original artwork ');
>> figure,imshow (BW), title (' Filtered area ');
>> figure,imshow (J), title (' Filter output for selected area ');




3. Specific area fill

The MATLAB Image Processing Toolbox provides a function Roifill for filling a specific area with a syntax format:

J = Roifill (i,c,r)
J = Roifill (I)
J = Roifill (I,BW)
[J,BW] = Roifill (⋯)
J = Roifill (x,y,i,xi,yi)
[X,y,j,bw,xi,yi] = Roifill (⋯)

where J=roifill (i,c,r) fills the polygons specified by vectors c and R, and C and R are the x and y coordinates of each vertex of the polygon respectively. It is through solving the boundary Laplace equation, using the gray level of the polygon boundary point to interpolate the point which is worth to the interior of the polygon. You can usually "erase" small chunks of the image by using a fill for the specified range.

J=roifill (I) represents the area where the fill is selected by user interaction. When you select the corner point of the polygon, press Enter to indicate the end, and the SPACEBAR or Del key indicates that a selection is canceled.
J=roifill (I,BW) uses the mask image BW to select the area.
[J,bw]=roifill (⋯) returns the mask image BW while populating the area.
J=roifill (X,y,i,xi,yi) and [X,y,j,bw,xi,yi]=roifill (⋯) indicate that the polygon region specified by Vector Xi and Yi is populated under the specified coordinate system x?y.

Cases:

I=imread (' eight.tif ');
%matlab with the material map, do not need to specify the path, in the work path of MATLAB, C:\Program Files\matlab\r2014a\toolbox\images\imdata
c=[222 272 300 270 221 194];
R=[21 21 75 121 121 75];
J=roifill (I,C,R);
Figure,imshow (I), title (' original artwork ');
>> figure,imshow (J), title (' filled figure ');


More MATLAB image processing video please click http://study.163.com/course/courseMain.htm?courseId=1003594013

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.