2 5427330694831422442
2 5427330694831422442
(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
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),
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:
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
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
c) Abin = 0 0 1
1 1 1 how?
d) Bint = 0 0 0
2 100 255
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.