Program Theory

6

Click here to load reader

Transcript of Program Theory

Page 1: Program Theory

%-------------- IMAGE READING -----------------------------------------

A=imread('\Final_Bitemark\07_edited.jpg');

C=rgb2gray(A);

%----------------------------------------------------------------------

Explanation :

%------- IMAGE READING ------------

The statements followed by ‘%’ sign are all comment statement.

IMREAD Read image from graphics file.

A = IMREAD(FILENAME,FMT) reads a grayscale or color image from the

file

specified by the string FILENAME. If the file is not in the current

directory, or in a directory on the MATLAB path, specify the full

pathname.

The text string FMT specifies the format of the file by its standard

file extension. For example, specify 'gif' for Graphics Interchange

Format files. To see a list of supported formats, with their file

extensions, use the IMFORMATS function. If IMREAD cannot find a file

named FILENAME, it looks for a file named FILENAME.FMT.

RGB2GRAY Convert RGB image or colormap to grayscale.

RGB2GRAY converts RGB images to grayscale by eliminating the

hue and saturation information while retaining the

luminance.

I = RGB2GRAY(RGB) converts the truecolor image RGB to the

grayscale intensity image I.

Page 2: Program Theory

%-------------- GRAY TO LOGICAL IMAGE CONVERSION ----------------------

----

[m n]=size(C);

B=false(m,n);

for i=1:m

for j=1:n

if C(i,j)<20

B(i,j)=255;

end

end

end

%----------------------------------------------------------------------

----

Explanation:

SIZE Size of array.

D = SIZE(X), for M-by-N matrix X, returns the two-element row vector

D = [M,N] containing the number of rows and columns in the matrix.

For N-D arrays, SIZE(X) returns a 1-by-N vector of dimension

lengths.

Trailing singleton dimensions are ignored.

[M,N] = SIZE(X) for matrix X, returns the number of rows and columns

in

X as separate output variables.

FALSE False array.

FALSE is short-hand for logical(0).

FALSE(N) is an N-by-N matrix of logical zeros.

FALSE(M,N) or FALSE([M,N]) is an M-by-N matrix of logical zeros.

FALSE(M,N,P,...) or FALSE([M N P ...]) is an M-by-N-by-P-by-...

array of logical zeros.

FALSE(SIZE(A)) is the same size as A and all logical zeros.

for i=1:m

for j=1:n

if C(i,j)<20

B(i,j)=255;

end

end

end

The above for loop, traverses through the image and converts the image

into logical image.

It checks the pixel values in the original grayscale image ‘C’ having

values less than 20 (Black pixels) and makes the corresponding pixels

white (255) in the logical image ‘B’.

Page 3: Program Theory

%--------------- DISPLAYING ALL THE IMAGE FORMS -----------------------

figure,imshow(A);

figure,imshow(C);

figure,imshow(B);

%----------------------------------------------------------------------

The above three statements displays the RGB image ‘A’, the grayscale

image ‘C’ and the logical image ‘B’.

%---------------- SPLITTING THE IMAGE INTO UPPER AND LOWER JAW --------

Upper_Jaw = imcrop(B);

Lower_Jaw = imcrop(B);

%----------------------------------------------------------------------

Explanation:

IMCROP Crop image.

I = IMCROP creates an interactive image cropping tool, associated

with the image displayed in the current figure, called the target

image. The tool is a moveable, resizable rectangle that is

interactively placed and manipulated using the mouse. After

positioning the tool, the user crops the target image by either

double clicking on the tool or choosing 'Crop Image' from the tool's

context menu. The cropped image, I, is returned. The cropping tool

can be deleted by pressing backspace, escape, or delete, or via the

'Cancel' option from the context menu. If the tool is deleted, all

return values are set to empty.

Page 4: Program Theory

%-------------- FINDING THE NO. OF TEETH IN UPPER & LOWER JAW ---------

No_Upper_Jaw_Teeth = bwconncomp(Upper_Jaw);

No_Lower_Jaw_Teeth = bwconncomp(Lower_Jaw);

%----------------------------------------------------------------------

Explanation :

CC = BWCONNCOMP(BW)

Returns the connected components CC found in BW.

BW is a binary image that can have any dimension. CC is a structure

with four fields:

Connectivity Connectivity of the connected components (objects).

ImageSize Size of BW.

NumObjects Number of connected components (objects) in BW.

PixelIdxList 1-by-NumObjects cell array where the kth element

in the cell array is a vector containing the linear

indices of the pixels in the kth object.

Page 5: Program Theory

%--------------- DECLARATION OF STRUCTURE FOR PARAMETER COLLECTION ----

Bite_Upper =

struct('Centroid',{0,0,0,0},'MajorAxisLength',{0,0,0,0},'Orientation',{

0,0,0,0});

%----------------------------------------------------------------------

Explanation:

S = STRUCT('field1',VALUES1,'field2',VALUES2,...)

creates a structure array with the specified fields and values. The

value arrays VALUES1, VALUES2, etc. must be cell arrays of the same

size, scalar cells or single values. Corresponding elements of the

value arrays are placed into corresponding structure array elements.

The size of the resulting structure is the same size as the value cell

arrays or 1-by-1 if none of the values is a cell.

{0,0,0,0} – specifies that there are four teeth whose ‘centroid’,

‘MajorAxisLength’ and ‘Orientation’ is to be calculated.

Page 6: Program Theory

%------------ EXTRACTING PARAMETERS OF EACH TEETH IN UPPER JAW --------

for i=1:No_Upper_Jaw_Teeth.NumObjects

Teeth_Extract = false(size(Upper_Jaw));

Teeth_Extract(No_Upper_Jaw_Teeth.PixelIdxList{i}) = true;

figure,imshow(Teeth_Extract);

rp =

regionprops(Teeth_Extract,'Centroid','MajorAxisLength','Orientation');

Bite_Upper(i).Centroid = rp.Centroid;

Bite_Upper(i).MajorAxisLength = rp.MajorAxisLength;

Bite_Upper(i).Orientation = rp.Orientation;

end

%----------------------------------------------------------------------

Explanation:

REGIONPROPS Measure properties of image regions.

STATS = REGIONPROPS(BW,PROPERTIES) measures a set of properties for

each connected component (object) in the binary image BW, which must

be a logical array; it can have any dimension.

PROPERTIES can be a comma-separated list of strings, a cell array

% containing strings, the string 'all', or the string 'basic'. The

set of valid measurement strings includes:

Shape Measurements

'Area' 'EulerNumber' 'Orientation'

'BoundingBox' 'Extent' 'Perimeter'

'Centroid' 'Extrema' 'PixelIdxList'

'ConvexArea' 'FilledArea' 'PixelList'

'ConvexHull' 'FilledImage' 'Solidity'

'ConvexImage' 'Image' 'SubarrayIdx'

'Eccentricity' 'MajorAxisLength'

'EquivDiameter' 'MinorAxisLength'

Pixel Value Measurements (requires grayscale image as an input)

'MaxIntensity'

'MeanIntensity'

'MinIntensity'

'PixelValues'

'WeightedCentroid'

From the above properties mentioned we are only using the three

properties namely Centroid, MajorAxisLength and Orientation.