Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Experiment No.

(1)
Image Types
The four image kinds are demonstrated and a conversion from one image
type to others is applied using a suitable conversion formula(s).

Theory:
Image could be classified into four categories,

1. True colour or Red Green Blue (RGB) image. This kind of image
consists of three colored planes, each one represent a 2D matrix.
The data class for this kind of image might be unsigned integer (0-
255), double, or scaled double (0 – 1), e.g; the jpg or png image
2. Indexed image. It consists of one main matrix with a color map
associated for each pixel value. The data class might be a scaled
double value, e.g; tif image
3. Gray-scale or intensity image which consist of one matrix. The
data class for this image type might be uint(0-255) or scaled double
(0-1). These values represents the intensity of gray level values
4. Binary image, consists of one matrix with 0/1 data-class value

• The RGB to Gray‐scale Conversion


There are four algorithms for converting color to gray-scale. If each color
pixel is described by a triple (r,g,b) of intensities for red, green, and blue.
These formulas could be applied separately to map the colored pixel to its
equivalent gray level value::

1. The lightness method which averages the most prominent and least
prominent colors: (max(R, G, B) + min(R, G, B)) / 2.
2. The average method, simply averages the values: (R + G + B) / 3.
3. The luminosity method is a more sophisticated version of the average
method. It also averages the values, but it forms a weighted average to
account for human perception. We’re more sensitive to green than
other colors, so green is weighted most heavily. The formula for
luminosity is: 0.21 R + 0.71 G + 0.07 B.
4. The weighted average method is given by the formula.
Gray = 0.299 R + 0.587 G + 0.114 B
Example: A shade of dark purple has an (r,g,b) value of (100, 0, 150). The
weighted average is: gray = 0.299(100) + 0.587(0) + 0.114(150),

Converting Image Types


Matlab also contains many built-in functions for converting different
image types. See table below;
Function Use Format
Ind2gray Indexed to grayscale y=ind2gray(x,map);
Gray2ind Grayscale to indexed [y,map]=gray2ind(x);
Rgb2gray RGB to grayscale y=rgb2gray(x);
Rgb2ind RGB to indexed [y,map]=rgb2ind;
Ind2rgb Indexed to RGB y=ind2rgb(x,map);
Mat2gray Matrix to grayscale Y=mat2gray(x);

Example : The green and red color plane of image rgbimage.jpg


are swapped

f = imread(’rgbimage.jpg’);
red = f(:,:,1);
g(:,:,1) = f(:,:,2);
g(:,:,2) = red;
g(:,:,3) = f(:,:,3);
imshow(g);

Requirements:
1. Read and display your stored images “ 1rgb.jpg ” and “ 1ind.tif “
2. Find the equivalent gray (intensity) image for “ 1rgb.jpg” and “1ind.tif”
using the built-in MATLAB functions
3. Repeat step 2 using for-Loop statement and four conversion formulas.
Which formula is better (use subplot (m,n,p) function for displaying)
4. Can you re-convert a gray value back to its equivalent RGB color code?

4
5. Fill the following table:
image Size Plane Size Gray-level size Binary size
(row × col.× dim) Red Green Blue (row × col.× dim) (row × col.× dim)
1rgb.jpj
1ind.tif

6. Write a program to display the individual red, green, and blue channels
of “1rgb.jpg” colour image. Use subplot( ) function for displaying

5
Image Data Class
Aims:
This experiment demonstrates the different image data class likes: Logic,
Arbitrary Double, Scaled Double (0 – 1), Uint8, Uint16, or Grey-scale

Theory:
Suppose you have images of different formats have been saved in your
computer. There are many MATLAB commands that can deal with these
different formatted images. The most common are listed in table 1.1

Thresholding
Thresholding produces a binary image from a grey-scale or colour image
by setting pixel values to 1 or 0 depending on whether they are above or
below the threshold value. This is commonly used to separate or segment
a region or object within the image based upon its pixel values. In its
basic operation, thresholding operates on an image I as follows:

for each pixel I(i,j) within the image I


if I(i,j) > threshold
I(i,j) = 1
else
I(i,j) = 0
end
end

In Matlab, this can be carried out using the function im2bw(I, 0.7) and a
threshold in the range 0 to 1

6
Example (1)
a=75;
b=uint(a);
Whos a b

Name Size Bytes Class


a 1×1 8 double array
b 1×1 1 uint8 array

Requirements:
(1) Suppose you have the following image matrices A=[-1 0 10; 100 255
256] ; B=[ -2 -0.1 0 ; 1.5 100.4 256] and C= [-1 0 10.4 ;100.5 255 256]; write
MATLAB instruction to find :
a) unsigned integer of A
b) scaled gray of A
c) binary image of A
d) unsigned integer of B
e) scaled gray of B
f) binary image of B
g) unsigned integer of C h )double of step(g) i) scaled gray of step(h)

answer:

a) Aint = 0 0 10
100 255 255

b) Agray = 0 0.0039 0.0428


0.3930 0.9961 1.0000

c) Abin = 0 0 1
1 1 1 how?

d) Bint = 0 0 0
2 100 255

e) Bscaled = 0 0.0074 0.0078


0.0136 0.3969 1.0000

f) Bbin = 0 0 0
1 1 1

g) Cint = 0 0 10
101 255 255

h) Cdouble = 0 0 0.0392
0.3961 1.0000 1.0000

i) Cscaled = 0 0 0.0392
0.3961 1.0000 1.0000
7
(2) Give an explanation about the difference between;
A = im2double (B) and A= double (B), if B is uint8 ( [0 5 10 ; 5
10 25 ; 50 100 255] )

(3) Write a program to compute number of 0’s and 1’s in the binary
image of “Red” plane of “1rgb.jpg” image, use for-loop statement
for image type conversion and logical data counting.

You might also like