Friday, December 18, 2015

Matlab functions and image processing toolbox functions summary (I)

imread: load an image into matlab workspace

imshow: show an loaded image or synthetic image by some special matrix

example:
img_color = imread('forest.jpeg', 'jpg');
imshow(img_color);

the figure being shown is as follows:
rgb2gray: convert a color image to an gray-level image

example: 
img_gray = rgb2gray(img_color);


imhist: demonstrate the histogram of an image. note this routine can only apply to gray-level image. the answer is color image is generally abundant with intensity values, (255x255x255), such a sparse intensity over weight demonstration is of little meaningfulness.

example:
imhist(img_gray);

the result is as follows:
histeq: do the histogram equalization to specific image

example:
img_eq = histeq(img_gray);
imshow(img_eq);

the result is as follows:
graythresh: compute the threshold for a given image
im2bw: convert an image into black-white image

note above the above function are tended to use jointly
gt = graythresh(img_gray);
img_bw = im2bw(img_gray, gt);
imshow(img_bw);

the result is as follows:
note the above example is operated upon image with data type unsigned char. however it could also be operated on float number. refer to the following example, but before that, let's introduce another function:
im2double: convert the intensity value into double float number

so the final example is:
img_f = im2double(img_gray);
imshow(im2bw(img_f, graythresh(img_f)));

it will display the identical image.

imadjust: adjust the intensity level of an given image
the intensity level transformation tends to be governed by several common functions, like exponential functions, and piecewise linear functions. however since imadjust saturate the intensity value at two input scale ends, it's probably in helping inspect the image instead of operating on the image:

stretchlim: obtain the upper and lower bound of intensity value

example:
img_adj = imadjust(img_f, stretchlim(img_f), [0, 1], 0.25);
imshow(img_adj);
an explanation of the example. it will map the intensity value between the minimum and maximum intensity of img_f into the full range [0, 1]. here 0.25 means the exponential value of the transform function s=r^alpha, r is the old intensity value and s is the new intensity value.

the result is as follows:




sometimes, it's necessary obtain the negative image of the original one, it can be completed by the following way:
img_neg = imadjust(img_f, [0, 1], [1, 0]);

there's also a function fulfil the same purpose:
imcomplement: obtain the complement image of the original one
example:
img_neg = imcomplement(img_f);

the result is as follows:



Reference:
http://www.cs.otago.ac.nz/cosc451/Resources/matlab_ipt_tutorial.pdf
Digital Image Processing, 3e, Gonzalez & Woods






No comments:

Post a Comment