Wednesday, January 30, 2019

BASICS OPERATION OF IMAGE PROCESSING WITH MATLAB


DIGITAL SIGNAL PROCESSING
 BASICS OPERATION OF IMAGE PROCESSING WITH MATLAB
INTRODUCTION:
Digital image processing is transforming digital information representing images.
Image Processing Toolbox: The Image Processing Toolbox is a collection of functions that extend the capabilities of the MATLAB’s numeric computing environment. The toolbox supports a wide range of image processing operations.
MATLAB can import/export several image formats such as BMP (Microsoft Windows Bitmap), GIF (Graphics Interchange Files) and JPEG (Joint Photographic Experts Group) etc.
IMAGES IN MATLAB:
• Binary images: {0, 1}
• Intensity images: [0, 1] or uint8, double etc.
• RGB images: m × n × 3


Images and Matrices How to build a matrix (or image)
Example 1: Intensity Image:
row = 256;
col = 256;
img = zeros(row, col);
img(100:105, :) = 0.5;
img(:, 100:105) = 1;
figure;
imshow(img);


Example 2: Binary Image:
row = 256;
col = 256;
img = rand(row, col);
img = round(img);
figure;
imshow (img);
Basic commands of image processing

Imread
A = imread (filename, fmt) reads a gray scale or true color image named filename into A. If the file contains a gray scale intensity image, A is a two dimensional array. If the file contains a true color (RGB) image, A is a three dimensional (m by n by 3) array.
Note: when you read image you have to give the path of drive where image is placed along with image name and format.
A=imread('drive:/ folder_name/image_name')
Rotation:
B = imrotate (a,angle)
a is your image.
ANGLE is the angle (in degrees) you want to rotate your image in the counter clockwise direction.
Edge Tracing
b=rgb2gray (a); % convert to gray.
WE can only do edge tracing for gray images.
edge(b,'prewitt');
edge(b,'sobel');
edge(b,'sobel','vertical');
edge(b,'sobel','horizontal');

Scaling:
imresize Resizes the image.
B = imresize (A, M) returns an image that is M times the size of A. If M is between 0 and 1.0, B is smaller than A. If M is greater than 1.0, B is larger than A.
B = imresize (A, [MROWS MCOLS]) returns an image of size MROWS by MCOLS.
If the specified size does not produce the same aspect ratio as the input image has, the output image is distorted.
Note: you can check the size of image using command “size”.

Export image:
To display image we use the following command
imshow (a)
and to write an image we use command
 imwrite (a,'filename.format')
EXERCISE:
1. Generate the image that is reverse of example 1 (convert black area of image to white and white area to black).

row = 256;
col = 256;
img = ones(row, col);
img(100:105, :) = 0;
img(:, 100:105) = 0.5;
figure
imshow(img)



2. Read any image using “imread” and apply basic image processing commands studied and show the output image for each command.
READING IMAGE:
A=imread('logo.jpg')
figure
imshow(A)

ROTATE:
B=imrotate(A,60)
figure
imshow(B)


EDGE TRACING (Sobel):
C=rgb2gray(A)
D=edge(C,'sobel')
figure
imshow(D)

EDGE TRACING (Prewitt):
C=rgb2gray(A)
D=edge(C,'prewitt')
figure
imshow(D)


SCALING:
B=imresize(A,1/2)
figure
imshow(B)


3. Run the following code.
ima = zeros(100,100);
for  i = 1:100
for  j = 1:100
ima(i,j) = i+j;
end
end
imagesc(ima)



No comments:

Post a Comment