Matlab Lecture 2
description
Transcript of Matlab Lecture 2
![Page 1: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/1.jpg)
MATLAB LECTURE 2Image Enhancement in the Spatial Domain (MATLAB)
![Page 2: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/2.jpg)
IMAGE ENHANCEMENT IN THE SPATIAL DOMAIN
![Page 3: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/3.jpg)
SPATIAL DOMAIN: BACKGROUND g(x, y) = T [f(x, y)]
f(x, y) : input image g(x, y) : output image T : an operator on f (Transformation
Function)
![Page 4: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/4.jpg)
IN MATLAB: FUNCTION IMADJUST Adjust image intensity values or colormap Syntax : (in gray images)
J = imadjust(I)maps the values in intensity image I to new values in J. Thisincreases the contrast of the output image J.
J = imadjust(I,[low_in high_in],[low_out high_out])maps the values in intensity image I to new values in J suchthat values between low_in and high_in map to values between low_out and high_out.
![Page 5: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/5.jpg)
FUNCTION IMADJUST J = imadjust(...,gamma) maps the values in intensity image I to new
values in J, where gamma specifies the shape of the curve describing the relationship between the values in I and J.
![Page 6: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/6.jpg)
FUNCTION IMADJUST (CONT.) If gamma is less than 1, the mapping is
weighted toward higher (brighter) output values. If gamma is greater than1, the mapping is weighted toward lower (darker) output values. If you omit the argument, gamma defaults to 1(linear mapping).
![Page 7: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/7.jpg)
IMAGE ADJUST EXAMPLES (MATLAB CODE) Adjust a low-contrast grayscale image.
I = imread('pout.tif');J = imadjust(I);figure, imshow(I), figure, imshow(J)
![Page 8: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/8.jpg)
IMAGE ADJUST EXAMPLES Adjust the grayscale image,
specifying the contrast limits.
K1 = imadjust(I,[0.3 0.7],[.2 .6]);figure, imshow(K1)
K2 = imadjust(I,[0.3 0.7],[]);figure, imshow(K2)
![Page 9: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/9.jpg)
IMAGE ADJUST EXAMPLESAdjust the gammaL1 = imadjust(I,[0.3 0.7], [ ],2);figure, imshow(L1)
L2 = imadjust(I,[0.3 0.7], [ ],.3);figure, imshow(L2)
![Page 10: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/10.jpg)
NEGATIVE IMAGEObtaining a negative image
I = imread('pout.tif');K1 =imadjust(I, [0 1] , [1 0]);K2 = imcomplement(I);imshow(I), figure, imshow(K1), figure, imshow(K2)
![Page 11: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/11.jpg)
STRETCHLIM EXAMPLEContrast Stretching:
I = imread('pout.tif');J = imadjust(I,stretchlim(I),[]);imshow(I), figure, imshow(J)
![Page 12: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/12.jpg)
LOGARITHMIC AND CONTRASTSTRETCHING Logarithmic:
g=c*log(1+double(f)) Contrast stretching :
compress the input levels lower than m into a narrow range of dark levels in the output image; similarly, it compresses the values above m into a narrow band of light levels in the output.
![Page 13: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/13.jpg)
LOGARITHMIC AND CONTRASTSTRETCHING EXAMPLE
I = imread('pout.tif');g=c*log(1+double(I))gs=im2uint8(mat2gray(g));
![Page 14: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/14.jpg)
THRESHOLDING EXAMPLEI = imread('pout.tif');threshold = graythresh(I);BW = im2bw(I,threshold);imshow(BW);
![Page 15: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/15.jpg)
IN MATLAB: IM2BW Convert an image to a binary image, based
on threshold Syntax:
BW = im2bw(I,level)BW = im2bw(X,map,level)BW = im2bw(RGB,level)
![Page 16: Matlab Lecture 2](https://reader030.fdocuments.net/reader030/viewer/2022012911/56816256550346895dd2a5d1/html5/thumbnails/16.jpg)
IM2BW: EXAMPLE
Im2bw: Example load treesBW = im2bw(X,map,0.4);Imview(X,map), imview(BW)