DIP - 2025 - Matlab-123
DIP - 2025 - Matlab-123
DIP - 2025 - Matlab-123
Matlab
1
29/01/1446
Display an Image
To display image, use the imshow function.
Syntax
imshow(A)
Description
imshow(A) displays the image stored in array A.
Writing Image Data
Imwrite write image to graphics file
Syntax
imwrite(A,filename,fmt)
2
29/01/1446
3
29/01/1446
imfinfo('cameraman.tif')
Exampe 2
h=imshow('bag.png');
imageinfo(h)
4
29/01/1446
10
5
29/01/1446
11
D=imread('onion.png');
imshow(B); %View resulting changes in image
D(25,50,:) %Print RGB pixel value at location (25,50)
D(25,50, 1) %Print only the red value at (25,50)
12
6
29/01/1446
Homework
Using the examples presented for displaying an image in Matlab
together with those for accessing pixel locations,
investigate adding and subtracting a scalar value from an
individual location, i.e. I(i; j) = I(i; j)+ 25 or I(i; j) = I(i; j)-25.
Start by using the grey-scale example image and pixel
location(100; 20).
What is the effect to n the greyscale colour of adding and
subtracting?
14
7
29/01/1446
15
16
8
29/01/1446
17
18
9
29/01/1446
19
21
10
29/01/1446
c=imread('onion.png');
cd=double(c);
imshow(c),
figure,imshow(cd/255)
22
23
11
29/01/1446
Image Rotation
Rotating an Image:
Imrotate function used to rotate a grey scale or RGB Image.
Syntax:
B = imrotate(A,angle)
The value of angle is given in degrees and the image rotates in anti-clockwise
direction according to the angle.
% Rotation
I=imread('onion.png');
K=imrotate(I,60);
subplot(2,1,1); imshow(K); title('Rotated Image 60deg');
R=imrotate(I,45);
subplot(2,1,2); imshow(R); title('Rotated Image 45deg');
24
12
29/01/1446
Scaling
Example of image scaling
I = imread(‘circuit.tif’);
J = imresize(I,1.25);
figure,
imshow(I);
figure,
imshow(J)
26
13
29/01/1446
31
14
29/01/1446
15