3. Reading Image
• >>F = imread(Penguins_grey.jpg);
>>G = imread(Penguins_RGB.jpg);
RGB image of penguinsGrayscale image of penguins
4. • To get the size of a 2D image,
[M,N] = size(f)
This syntax returns the number of rows (M) and
columns (N) in the image.
Find additional information about the array using
‘whos’ command.
• Syntax
whos filename
‘whos f’ gives name, size, bytes, class and attributes of
the array ‘f.’
5. Syntax:
whos filename
As an example, ‘whos F’gives:
Name F
Size 768×1024×3
Bytes 2359296
Class Attributes uint8
‘whos G’ gives:
Name G
Size 768×1024
Bytes 786432
6.
7. • To start the image tool, use the imtool function.
• >>B = imread(Penguins_grey.jpg);
>>imtool(B)
• The above window that appears when using the image tool. The
status text at the bottom of the main window shows the column/row
location and the value of the pixel lying under the mouse cursor.
8. Measure Distance tool
The Measure Distance tool under Tools tab is used to show the
distance between the two selected points
9. Pixel Region tool
The Pixel Region tool shows individual pixels from the small
square region on the upper right tip, zoomed large enough to see
the actual pixel values.
10. • Quality
The quality parameter is used as a trade-off between the
resulting image’s subjective quality and file size.
• Syntax:
imwrite(f, ‘filename.jpg’, ‘quality’, q)
where ‘q’ is an integer between 0 and 100.
It can be used to reduce the image size.
• image Penguins_grey.jpg is read
• JPG format with three different quality parameters: 75 (default), 10
(poor quality and small size) and 90 (high quality and large size)
are applied
11. • F = imread(‘Penguins_grey.jpg’);
imwrite(F,’Penguins_grey_75.
jpg’,’quality’,75);
imwrite(F,’Penguins_grey_10.
jpg’,’quality’,10);
imwrite(F,’Penguins_grey_90.
jpg’,’quality’,90);
• From the following images, quality factors of 75, 10 and 90
seen. Note that that a low-quality image has a smaller size than
a higher-quality image.
12. Image for quality factor of 90Image for quality factor of 10Image for quality factor of 75
13. • Image information
File details including file name, data, size,
format, height and width can be obtained.
• Syntax:
imfinfo’filename’
imfinfo(‘Penguins_grey.jpg’)
15. • The following example stores all the information into variable
‘K’:
• K = imfinfo(‘Penguins_grey.jpg’)
• The information generated by ‘imfinfo’ is appended to the
structure variable by means of fields, separated from ‘K’ by a
dot. As an example, the image height and width are stored in
structure fields K.height and K.weight.
16. • imread()
The imread() command will read an image into a matrix:
img = imread('ImageProcessing_1/BerkeleyTower.png');
>> size(img)
ans =
499 748 3
• It's a 499x748 matrix with 3 RGB channels. The matrix looks like this:
24 40 73 108 129 108 96 100 109 114 108 109 62
29 56 97 107 110 104 103 105 106 110 110 111 105
...
3 2 2 1 0 0 1 1 0 1 2 4 2
1 0 1 3 2 0 0 0 1 1 2 1 0
...
17. • imshow()
To show our image use ,
The imshow() command shows an image in
standard 8-bit format, like it would appear in a
web browser.
The imagesc()command displays the image on
scaled axes with the min value as black and the
max value as white.
20. • We can check the RGB values with (x,y) coordinates of a pixel:
• Select "Data Cursor" icon from the top menu
• Click the mouse on the image
• Notice each pixel is a 3-dimensional vector with values in the range [0,255].
The 3 numbers displayed is the amount of RGB.
21. • Actually, a color image is a combined image of 3 grayscale images. So, we can
display the individual RGB components of the image using the following
script:
subplot(131);
imagesc(img(:,:,1));
title('Red');
subplot(132);
imagesc(img(:,:,2));
title('Green');
subplot(133);
imagesc(img(:,:,3));
title('Blue');
22.
23. • Using a command colormap gray, the picture turns into a
grayscale:
• >> colormap gray
24. • imwrite()
To save new blue image, use the imwrite() command:
imwrite(blue_img, 'Blue4_BerkeleyTower.png', 'png');
• rgb2gray()
img = imread('ImageProcessing_1/BerkeleyTower.png');
gray = rgb2gray(img);
imshow(gray);
25. • >> size(gray)
ans =
499 748
• imhist()
Display a histogram of image data.
img = imread('ImageProcessing_1/BerkeleyTower.png');
gray = rgb2gray(img);
imhist(gray);
26. • 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.
img = imread('ImageProcessing_1/Rachmaninoff.jpg');
gray = rgb2gray(img);
adj_img = imadjust(gray, [0.3,0.7],[]);
subplot(121);
imshow(gray);
title('input');
subplot(122);
imshow(adj_img);
title('adjusted');