Professional Documents
Culture Documents
Lab # 14
Summary
Items Description
Duration 3 Hours
1. imread()
2. imshow()
imread() :
The imread() command will read an image into a matrix:
Example:
img = imread('ImageProcessing_1/BerkeleyTower.png');
>> size(img)
ans =
499 748 3
imshow():
To show our image, we use the imshow() command. The imshow() command shows an image in
standard 8-bit format, like it would appear in a web browser.
rgb2gray():
To convert color image into a gray-scale image we use rgb2gray command.
Example:
img = imread('ImageProcessing_1/BerkeleyTower.png');
gray = rgb2gray(img);
imshow(gray);
imhist():
Display a histogram of image data. imhist(img,n) displays a histogram with n bins for the
intensity image above a grayscale color bar of length n.
img = imread('ImageProcessing_1/BerkeleyTower.png');
gray = rgb2gray(img);
imhist(gray);
imadjust():
imadjust() adjust image intensity values. It maps the values in intensity image of an input to new
values in output image. This increases the contrast of the output image.
Example:
subplot(121);
imshow(gray);
title('input');
subplot(122);
imshow(adj_img);
title('adjusted');
im2bw() :
im2bw() converts the grayscale image to a binary image. We'll use the adjusted image.
Example:
subplot(121);
imshow(adj_img);
title('input image');
subplot(122);
imshow(bw_img);
title('binary image');
Sharpen an Image:
Example:
a = imread('hestain.png');
imshow(a), title('Original Image');
b = imsharpen(a);
TASK 1
Write a MATLAB code that reads a gray scale image given as an input and generates the
following resultant image given below
3. Again display the image such that the pixels having intensity values below than 50 will
display as black and pixels having intensity values above than 150 will display as white. And the
pixels between these will display as it is.
TASK3
Switch can handle multiple conditions in a single case statement by enclosing the
case expression in a cell array. switchvar
case 1
disp('1')
case {2,3,4}
disp('2 or 3 or4')
case 5
disp('5')
otherwise
disp('something else')
end